Allow changes to the reflection to be made after it's been submitted #13

Merged
ansv7779 merged 20 commits from 3412-supervisor-edit-reflection into develop 2024-11-21 19:20:48 +01:00
6 changed files with 87 additions and 9 deletions
Showing only changes of commit 93124dfade - Show all commits

View File

@ -39,6 +39,11 @@ public class Author {
@Basic(optional = true)
private String reflection;
@Basic
@Enumerated(EnumType.STRING)
@Column(name = "reflection_status")
private ReflectionStatus reflectionStatus = ReflectionStatus.NOT_SUBMITTED;
public Project getProject() {
return project;
}
@ -63,6 +68,14 @@ public class Author {
this.reflection = reflection;
}
public ReflectionStatus getReflectionStatus() {
return reflectionStatus;
}
public void setReflectionStatus(ReflectionStatus reflectionStatus) {
this.reflectionStatus = reflectionStatus;
}
@Embeddable
public static class AuthorPK implements Serializable {
private Long projectId;

View File

@ -0,0 +1,7 @@
package se.su.dsv.scipro.project;
public enum ReflectionStatus {
NOT_SUBMITTED,
SUBMITTED,
COMPLETION_REQUESTED
}

View File

@ -0,0 +1,22 @@
package se.su.dsv.scipro.reflection;
public sealed interface Reflection {
boolean isSubmittable();
record NotSubmitted() implements Reflection {
@Override
public boolean isSubmittable() { return true; }
}
record Submitted(String reflection) implements Reflection {
@Override
public boolean isSubmittable() {
return false;
}
}
record ImprovementsNeeded(String oldReflection, String commentBySupervisor) implements Reflection {
@Override
public boolean isSubmittable() { return true; }
}
}

View File

@ -5,10 +5,13 @@ import se.su.dsv.scipro.finalseminar.AuthorRepository;
import se.su.dsv.scipro.finalseminar.FinalSeminarService;
import se.su.dsv.scipro.project.Author;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.project.ReflectionStatus;
import se.su.dsv.scipro.system.User;
import jakarta.inject.Inject;
import java.util.Optional;
class ReflectionServiceImpl implements ReflectionService {
private final AuthorRepository authorRepository;
private final FinalSeminarService finalSeminarService;
@ -25,10 +28,13 @@ class ReflectionServiceImpl implements ReflectionService {
}
@Override
public boolean hasToFillInReflection(Project project, User author) {
boolean noReflectionSubmitted = authorRepository.findByProjectAndUser(project, author)
.map(Author::getReflection)
.isEmpty();
public boolean hasToFillInReflection(Project project, User user) {
Optional<Author> optionalAuthor = authorRepository.findByProjectAndUser(project, user);
if (optionalAuthor.isEmpty()) {
return false;
}
Author author = optionalAuthor.get();
boolean noReflectionSubmitted = author.getReflectionStatus() != ReflectionStatus.SUBMITTED;
return hasReachedReflectionProcess(project) && noReflectionSubmitted;
}
@ -36,7 +42,10 @@ class ReflectionServiceImpl implements ReflectionService {
@Transactional
public void submitReflection(Project project, User user, String reflection) {
authorRepository.findByProjectAndUser(project, user)
.ifPresent(author -> author.setReflection(reflection));
.ifPresent(author -> {
author.setReflection(reflection);
author.setReflectionStatus(ReflectionStatus.SUBMITTED);
});
}
@Override
@ -47,7 +56,11 @@ class ReflectionServiceImpl implements ReflectionService {
}
@Override
public void requestNewReflection(Project project, User author) {
@Transactional
public void requestNewReflection(Project project, User user) {
authorRepository.findByProjectAndUser(project, user)
.ifPresent(author -> {
author.setReflectionStatus(ReflectionStatus.COMPLETION_REQUESTED);
});
}
}

View File

@ -38,6 +38,7 @@
<div wicket:id="current_thesis_file"></div>
</div>
</wicket:enclosure>
<p wicket:id="old_reflection"></p>
<div class="mb-3">
<label class="form-label" wicket:for="reflection">
<wicket:message key="reflection">[Reflection]</wicket:message>

View File

@ -2,6 +2,7 @@ package se.su.dsv.scipro.project.panels;
import org.apache.wicket.feedback.FencedFeedbackPanel;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
@ -24,6 +25,7 @@ import se.su.dsv.scipro.grading.PublicationMetadata;
import se.su.dsv.scipro.grading.PublicationMetadataFormComponentPanel;
import se.su.dsv.scipro.grading.PublicationMetadataService;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.reflection.Reflection;
import se.su.dsv.scipro.reflection.ReflectionService;
import se.su.dsv.scipro.session.SciProSession;
@ -73,9 +75,23 @@ public class FinalStepsPanel extends GenericPanel<Project> {
public FinalStepsForm(String id, IModel<Project> projectModel) {
super(id, projectModel);
IModel<Reflection> reflectionLoadableDetachableModel = LoadableDetachableModel.of(() -> null);
IModel<Reflection.ImprovementsNeeded> i = reflectionLoadableDetachableModel.as(Reflection.ImprovementsNeeded.class);
IModel<String> labelModel = i.map(Reflection.ImprovementsNeeded::oldReflection);
add(new Label("old_reflection", labelModel));
add(new Label("supervisor_comment", i.map(Reflection.ImprovementsNeeded::commentBySupervisor)));
reflectionModel = new Model<>();
TextArea<String> reflectionTextArea = new TextArea<>("reflection", reflectionModel);
TextArea<String> reflectionTextArea = new TextArea<>("reflection", reflectionModel) {
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(reflectionLoadableDetachableModel.getObject().isSubmittable());
}
};
reflectionTextArea.setRequired(true);
add(reflectionTextArea);
@ -111,7 +127,13 @@ public class FinalStepsPanel extends GenericPanel<Project> {
currentThesisFile.add(new OppositeVisibility(thesisFileUpload));
add(currentThesisFile);
publicationMetadataModel = LoadableDetachableModel.of(() -> publicationMetadataService.getByProject(getModelObject()));
WebMarkupContainer publicationMetadata = new WebMarkupContainer("publication_metadata");
WebMarkupContainer publicationMetadata = new WebMarkupContainer("publication_metadata") {
@Override
protected void onConfigure() {
super.onConfigure();
setEnabled(finalThesisService.isUploadAllowed(FinalStepsPanel.FinalStepsForm.this.getModelObject()));
}
};
add(publicationMetadata);
publicationMetadata.add(new PublicationMetadataFormComponentPanel("publication_metadata_components", publicationMetadataModel));
}