fixes
This commit is contained in:
parent
24ec12553a
commit
b99f287f8c
@ -54,6 +54,13 @@ public class Assessment extends BaseEntity {
|
|||||||
.isPresent();
|
.isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStarted() {
|
||||||
|
return assessmentEvents.stream().filter(e -> e.getStatus() == AssessmentStatus.STARTED)
|
||||||
|
.map(AssessmentEvent::getTimestamp)
|
||||||
|
.findFirst()
|
||||||
|
.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFirst(Submission currSubmission) {
|
public boolean isFirst(Submission currSubmission) {
|
||||||
return getQuestions().indexOf(currSubmission.getQuestion()) == 0;
|
return getQuestions().indexOf(currSubmission.getQuestion()) == 0;
|
||||||
}
|
}
|
||||||
|
@ -35,34 +35,45 @@ public class AssessmentService {
|
|||||||
|
|
||||||
public Assessment startAssessment(final UUID id) {
|
public Assessment startAssessment(final UUID id) {
|
||||||
final Assessment assessment = assessmentRepository.findById(id).get();
|
final Assessment assessment = assessmentRepository.findById(id).get();
|
||||||
final Optional<AssessmentEvent> started = assessment.getAssessmentEvents().stream()
|
if (assessment.isStarted()) {
|
||||||
.filter(e -> e.getStatus() == AssessmentStatus.STARTED)
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
if (started.isPresent()) {
|
|
||||||
return assessment;
|
return assessment;
|
||||||
}
|
}
|
||||||
|
|
||||||
assessment.getAssessmentEvents().add(new AssessmentEvent(Instant.now(), AssessmentStatus.STARTED, assessment));
|
assessment.getAssessmentEvents().add(new AssessmentEvent(Instant.now(), AssessmentStatus.STARTED, assessment));
|
||||||
assessmentRepository.save(assessment);
|
|
||||||
|
|
||||||
return assessment;
|
return assessmentRepository.save(assessment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Submission getNextSubmission(final Assessment assessment, final Submission currSubmission) {
|
public Submission getNextSubmission(final UUID assessmentId, final UUID currSubmissionId) {
|
||||||
if (currSubmission == null) {
|
final Assessment assessment = assessmentRepository.findById(assessmentId).get();
|
||||||
|
|
||||||
|
Assessment saved;
|
||||||
|
if (currSubmissionId == null) {
|
||||||
if (assessment.isCompleted()) {
|
if (assessment.isCompleted()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Question firstQuestion = assessment.getQuestions().stream().findFirst().get();
|
final Question firstQuestion = assessment.getQuestions().stream().findFirst().get();
|
||||||
final Submission submissionToReturn = new Submission(firstQuestion, firstQuestion.getContent(), Map.of(), SubmissionStatus.FAIL, assessment);
|
final Optional<Submission> submissionToReturn = assessment.getSubmissions().stream()
|
||||||
assessment.getSubmissions().add(submissionToReturn);
|
.filter(s -> s.getQuestion().equals(firstQuestion))
|
||||||
assessmentRepository.save(assessment);
|
.findFirst();
|
||||||
|
|
||||||
return submissionToReturn;
|
if (submissionToReturn.isEmpty()) {
|
||||||
|
final Submission result = new Submission(firstQuestion, firstQuestion.getContent(), Map.of(), SubmissionStatus.FAIL, assessment);
|
||||||
|
assessment.getSubmissions().add(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved = assessmentRepository.save(assessment);
|
||||||
|
final Optional<Submission> submissionToReturn2 = saved.getSubmissions().stream()
|
||||||
|
.filter(s -> s.getQuestion().equals(firstQuestion))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
return submissionToReturn2.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Submission currSubmission = assessment.getSubmissions().stream()
|
||||||
|
.filter(s -> s.getId().equals(currSubmissionId))
|
||||||
|
.findFirst().get();
|
||||||
final Question currQuestion = currSubmission.getQuestion();
|
final Question currQuestion = currSubmission.getQuestion();
|
||||||
int idx = assessment.getQuestions().indexOf(currQuestion);
|
int idx = assessment.getQuestions().indexOf(currQuestion);
|
||||||
|
|
||||||
@ -76,25 +87,26 @@ public class AssessmentService {
|
|||||||
.filter(s -> s.getQuestion().equals(nextQuestion))
|
.filter(s -> s.getQuestion().equals(nextQuestion))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
final Submission result;
|
|
||||||
if (submissionToReturn.isEmpty()) {
|
if (submissionToReturn.isEmpty()) {
|
||||||
result = new Submission(nextQuestion, nextQuestion.getContent(), Map.of(), SubmissionStatus.FAIL, assessment);
|
final Submission result = new Submission(nextQuestion, nextQuestion.getContent(), Map.of(), SubmissionStatus.FAIL, assessment);
|
||||||
assessment.getSubmissions().add(result);
|
assessment.getSubmissions().add(result);
|
||||||
} else {
|
|
||||||
result = submissionToReturn.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assessmentRepository.save(assessment);
|
saved = assessmentRepository.save(assessment);
|
||||||
|
final Optional<Submission> submissionToReturn2 = saved.getSubmissions().stream()
|
||||||
|
.filter(s -> s.getQuestion().equals(nextQuestion))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
return result;
|
return submissionToReturn2.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Submission getPrevSubmission(final Assessment assessment, final Submission currSubmission) {
|
public Submission getPrevSubmission(final UUID assessmentId, final Submission currSubmission) {
|
||||||
if (currSubmission == null) {
|
if (currSubmission == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Question currQuestion = currSubmission.getQuestion();
|
final Question currQuestion = currSubmission.getQuestion();
|
||||||
|
Assessment assessment = assessmentRepository.findById(assessmentId).get();
|
||||||
int idx = assessment.getQuestions().indexOf(currQuestion);
|
int idx = assessment.getQuestions().indexOf(currQuestion);
|
||||||
|
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
@ -103,15 +115,12 @@ public class AssessmentService {
|
|||||||
|
|
||||||
final Question prevQuestion = assessment.getQuestions().get(idx - 1);
|
final Question prevQuestion = assessment.getQuestions().get(idx - 1);
|
||||||
|
|
||||||
assessmentRepository.save(assessment);
|
|
||||||
|
|
||||||
|
|
||||||
return assessment.getSubmissions().stream()
|
return assessment.getSubmissions().stream()
|
||||||
.filter(s -> s.getQuestion().equals(prevQuestion))
|
.filter(s -> s.getQuestion().equals(prevQuestion))
|
||||||
.findFirst().orElseThrow(() -> new IllegalStateException("submission invalid"));
|
.findFirst().orElseThrow(() -> new IllegalStateException("submission invalid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Assessment completeAssessment(final UUID id, final Submission submission) {
|
public Assessment completeAssessment(final UUID id) {
|
||||||
Assessment assessment = assessmentRepository.findById(id).get();
|
Assessment assessment = assessmentRepository.findById(id).get();
|
||||||
Optional<AssessmentEvent> completed = assessment.getAssessmentEvents().stream()
|
Optional<AssessmentEvent> completed = assessment.getAssessmentEvents().stream()
|
||||||
.filter(e -> e.getStatus() == AssessmentStatus.COMPLETED)
|
.filter(e -> e.getStatus() == AssessmentStatus.COMPLETED)
|
||||||
@ -122,8 +131,18 @@ public class AssessmentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assessment.getAssessmentEvents().add(new AssessmentEvent(Instant.now(), AssessmentStatus.COMPLETED, assessment));
|
assessment.getAssessmentEvents().add(new AssessmentEvent(Instant.now(), AssessmentStatus.COMPLETED, assessment));
|
||||||
assessmentRepository.save(assessment);
|
Assessment saved = assessmentRepository.save(assessment);
|
||||||
|
|
||||||
return assessment;
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSubmission(UUID id, Submission currSubmission) {
|
||||||
|
Assessment assessment = assessmentRepository.findById(id).get();
|
||||||
|
final Submission submission = assessment.getSubmissions().stream()
|
||||||
|
.filter(s -> s.getId().equals(currSubmission.getId()))
|
||||||
|
.findFirst().get();
|
||||||
|
|
||||||
|
submission.setResponse(currSubmission.getResponse());
|
||||||
|
Assessment saved = assessmentRepository.save(assessment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
Button start = null;
|
Button start = null;
|
||||||
MenuItem prev = null;
|
MenuItem prev = null;
|
||||||
MenuItem next = null;
|
MenuItem next = null;
|
||||||
|
MenuItem reset = null;
|
||||||
Section sidebar = null;
|
Section sidebar = null;
|
||||||
SimpleTimer timer = null;
|
SimpleTimer timer = null;
|
||||||
|
|
||||||
@ -126,8 +127,9 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
|
|
||||||
final Button saveButton = new Button("Guardar y Siguiente", e -> {
|
final Button saveButton = new Button("Guardar y Siguiente", e -> {
|
||||||
this.currSubmission.setResponse(this.questionEditor.getValue());
|
this.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
goToNext();
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
dialog.close();
|
dialog.close();
|
||||||
|
goToNext();
|
||||||
});
|
});
|
||||||
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
final Button closeButton = new Button("Cerrar", e -> dialog.close());
|
final Button closeButton = new Button("Cerrar", e -> dialog.close());
|
||||||
@ -151,7 +153,9 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
|
|
||||||
final Button completeButton = new Button("Terminar", e -> {
|
final Button completeButton = new Button("Terminar", e -> {
|
||||||
completeDialog.close();
|
completeDialog.close();
|
||||||
this.assessment = assessmentService.completeAssessment(assessment.getId(), currSubmission);
|
this.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
|
this.assessment = assessmentService.completeAssessment(assessment.getId());
|
||||||
goToCompleted();
|
goToCompleted();
|
||||||
updateUI();
|
updateUI();
|
||||||
});
|
});
|
||||||
@ -182,13 +186,19 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
prev = navMenuBar.addItem("Anterior pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
prev = navMenuBar.addItem("Anterior pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
||||||
System.out.println(">>> prev");
|
System.out.println(">>> prev");
|
||||||
this.currSubmission.setResponse(this.questionEditor.getValue());
|
this.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
this.currSubmission = this.assessmentService.getPrevSubmission(assessment, this.currSubmission);
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
|
this.currSubmission = this.assessmentService.getPrevSubmission(assessment.getId(), this.currSubmission);
|
||||||
updateUI();
|
updateUI();
|
||||||
});
|
});
|
||||||
next = navMenuBar.addItem("Siguiente pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
next = navMenuBar.addItem("Siguiente pregunta", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
||||||
this.currSubmission.setResponse(this.questionEditor.getValue());
|
this.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
goToNext();
|
goToNext();
|
||||||
});
|
});
|
||||||
|
reset = navMenuBar.addItem("Reiniciar pregunta (deshacer cambios)", (ComponentEventListener<ClickEvent<MenuItem>>) menuItemClickEvent -> {
|
||||||
|
this.currSubmission.setResponse(this.currSubmission.getQuestion().getContent());
|
||||||
|
this.questionEditor.setValue(this.currSubmission.getQuestion().getContent());
|
||||||
|
});
|
||||||
|
|
||||||
final Div menuBar = new Div();
|
final Div menuBar = new Div();
|
||||||
menuBar.add(runMenuBar, navMenuBar);
|
menuBar.add(runMenuBar, navMenuBar);
|
||||||
@ -228,8 +238,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
this.assessment = this.assessmentService.startAssessment(this.assessment.getId());
|
this.assessment = this.assessmentService.startAssessment(this.assessment.getId());
|
||||||
|
|
||||||
if (tf.getValue().trim().equalsIgnoreCase(this.assessment.getAppUser().getEmail())) {
|
if (tf.getValue().trim().equalsIgnoreCase(this.assessment.getAppUser().getEmail())) {
|
||||||
this.currSubmission = this.assessmentService.getNextSubmission(assessment, this.currSubmission);
|
this.getUI().get().getPage().reload();
|
||||||
updateUI();
|
|
||||||
} else {
|
} else {
|
||||||
Notification notification = new Notification();
|
Notification notification = new Notification();
|
||||||
notification.addThemeVariants(NotificationVariant.LUMO_ERROR);
|
notification.addThemeVariants(NotificationVariant.LUMO_ERROR);
|
||||||
@ -291,8 +300,14 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
|
|
||||||
private void goToNext() {
|
private void goToNext() {
|
||||||
System.out.println(">>> next");
|
System.out.println(">>> next");
|
||||||
this.currSubmission = this.assessmentService.getNextSubmission(assessment, this.currSubmission);
|
Submission found = this.assessmentService.getNextSubmission(assessment.getId(), this.currSubmission.getId());
|
||||||
updateUI();
|
|
||||||
|
if (found == null) {
|
||||||
|
this.completeDialog.open();
|
||||||
|
} else {
|
||||||
|
this.currSubmission = found;
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSidebar() {
|
private void initSidebar() {
|
||||||
@ -311,7 +326,9 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
timer.setMinutes(true);
|
timer.setMinutes(true);
|
||||||
timer.addTimerEndEvent((ComponentEventListener<SimpleTimer.TimerEndedEvent>) timerEndedEvent -> {
|
timer.addTimerEndEvent((ComponentEventListener<SimpleTimer.TimerEndedEvent>) timerEndedEvent -> {
|
||||||
Notification.show("Tiempo completado.", 5, Notification.Position.TOP_CENTER);
|
Notification.show("Tiempo completado.", 5, Notification.Position.TOP_CENTER);
|
||||||
this.assessment = assessmentService.completeAssessment(assessment.getId(), currSubmission);
|
this.currSubmission.setResponse(this.questionEditor.getValue());
|
||||||
|
this.assessmentService.saveSubmission(assessment.getId(), this.currSubmission);
|
||||||
|
this.assessment = assessmentService.completeAssessment(assessment.getId());
|
||||||
goToCompleted();
|
goToCompleted();
|
||||||
updateUI();
|
updateUI();
|
||||||
});
|
});
|
||||||
@ -328,18 +345,19 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
if (currSubmission == null) {
|
if (assessment == null || !assessment.isStarted()) {
|
||||||
editorSection.setVisible(false);
|
editorSection.setVisible(false);
|
||||||
startSection.setVisible(true);
|
startSection.setVisible(true);
|
||||||
sidebar.setVisible(false);
|
sidebar.setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
questionEditor.setValue(this.currSubmission.getResponse());
|
if (currSubmission != null) {
|
||||||
|
questionEditor.setValue(this.currSubmission.getResponse());
|
||||||
|
}
|
||||||
|
|
||||||
editorSection.setVisible(true);
|
editorSection.setVisible(true);
|
||||||
startSection.setVisible(false);
|
startSection.setVisible(false);
|
||||||
sidebar.setVisible(true);
|
sidebar.setVisible(true);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.assessment != null) {
|
|
||||||
prev.setEnabled(currSubmission != null && !assessment.isFirst(currSubmission));
|
prev.setEnabled(currSubmission != null && !assessment.isFirst(currSubmission));
|
||||||
next.setEnabled(currSubmission == null || !assessment.isLast(currSubmission));
|
next.setEnabled(currSubmission == null || !assessment.isLast(currSubmission));
|
||||||
|
|
||||||
@ -354,7 +372,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
if (dl.getChildren().collect(Collectors.toList()).isEmpty()) {
|
if (dl.getChildren().collect(Collectors.toList()).isEmpty()) {
|
||||||
dl.add(
|
dl.add(
|
||||||
createItem("Candidato:", assessment.getAppUser().getEmail()),
|
createItem("Candidato:", assessment.getAppUser().getEmail()),
|
||||||
createItem("Hora comienzo:", Optional.ofNullable(assessment.getStartingTime())
|
createItem("Hora de inicio:", Optional.ofNullable(assessment.getStartingTime())
|
||||||
.map(t -> ZonedDateTime.ofInstant(t, ZoneId.of("GMT-4")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
.map(t -> ZonedDateTime.ofInstant(t, ZoneId.of("GMT-4")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
||||||
.orElse("N/A"))
|
.orElse("N/A"))
|
||||||
);
|
);
|
||||||
@ -401,9 +419,9 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
goToCompleted();
|
goToCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currSubmission = this.assessment.getSubmissions().isEmpty()
|
this.currSubmission = this.assessment.isStarted()
|
||||||
? null
|
? this.assessmentService.getNextSubmission(assessment.getId(), null)
|
||||||
: this.assessmentService.getNextSubmission(assessment, null);
|
: null;
|
||||||
|
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,15 @@ vaadin.launch-browser=true
|
|||||||
vaadin.allowed-packages = com.vaadin,org.vaadin,com.primefactorsolutions,com.hilerio.ace,com.flowingcode.vaadin
|
vaadin.allowed-packages = com.vaadin,org.vaadin,com.primefactorsolutions,com.hilerio.ace,com.flowingcode.vaadin
|
||||||
|
|
||||||
|
|
||||||
# spring.datasource.url=jdbc:h2:mem:testdb
|
spring.datasource.url=jdbc:h2:mem:testdb
|
||||||
|
#spring.datasource.url=jdbc:h2:file:./db
|
||||||
|
#spring.datasource.url=jdbc:h2:file:/var/opt/pfs/db
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
spring.sql.init.mode=always
|
spring.sql.init.mode=always
|
||||||
#spring.datasource.url=jdbc:h2:file:./db
|
|
||||||
spring.datasource.url=jdbc:h2:file:/var/opt/pfs/db
|
|
||||||
spring.datasource.driverClassName=org.h2.Driver
|
spring.datasource.driverClassName=org.h2.Driver
|
||||||
spring.datasource.username=sa
|
spring.datasource.username=sa
|
||||||
spring.datasource.password=sa
|
spring.datasource.password=sa
|
||||||
|
spring.h2.console.settings.web-allow-others=true
|
||||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||||
spring.jpa.defer-datasource-initialization = true
|
spring.jpa.defer-datasource-initialization = true
|
||||||
spring.h2.console.enabled=true
|
spring.h2.console.enabled=true
|
||||||
|
Loading…
Reference in New Issue
Block a user