Allows admins to manage grading report templates #14
@ -36,12 +36,19 @@ public record GradingReportTemplateUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
public record Criteria(LocalizedString title, @Nullable Flag flag, List<Requirement> requirements)
|
||||
public record Criteria(
|
||||
LocalizedString title,
|
||||
Type type,
|
||||
int minimumPointsRequiredToPass,
|
||||
@Nullable Flag flag,
|
||||
List<Requirement> requirements)
|
||||
{
|
||||
public enum Type {THESIS, INDIVIDUAL}
|
||||
public enum Flag {OPPOSITION, REFLECTION}
|
||||
|
||||
public Criteria {
|
||||
Objects.requireNonNull(title, "Title must not be null");
|
||||
Objects.requireNonNull(type, "Type must not be null");
|
||||
Objects.requireNonNull(requirements, "Requirements must not be null");
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class GradingReportTemplate extends DomainObject {
|
||||
@OneToOne(optional = false)
|
||||
private ProjectType projectType;
|
||||
|
||||
@OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL})
|
||||
@OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
||||
private Collection<GradingCriterionTemplate> criteria = new HashSet<>();
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
|
@ -65,6 +65,40 @@ public class GradingReportTemplateRepoImpl extends GenericRepo<GradingReportTemp
|
||||
@Transactional
|
||||
public GradingReportTemplate updateTemplate(long templateId, GradingReportTemplateUpdate update) {
|
||||
GradingReportTemplate gradingReportTemplate = findOne(templateId);
|
||||
return gradingReportTemplate;
|
||||
gradingReportTemplate.setValidFrom(update.validFrom());
|
||||
|
||||
gradingReportTemplate.getCriteria().clear();
|
||||
for (var criteria : update.criteria()) {
|
||||
final List<GradingCriterionPointTemplate> pointTemplates = criteria.requirements()
|
||||
.stream()
|
||||
.map(this::toPointTemplate)
|
||||
.toList();
|
||||
switch (criteria.type()) {
|
||||
case THESIS -> {
|
||||
gradingReportTemplate.addProjectCriterion(
|
||||
criteria.title().swedish(),
|
||||
criteria.title().english(),
|
||||
criteria.minimumPointsRequiredToPass(),
|
||||
pointTemplates);
|
||||
}
|
||||
case INDIVIDUAL -> {
|
||||
gradingReportTemplate.addIndividualCriterion(
|
||||
criteria.title().swedish(),
|
||||
criteria.title().english(),
|
||||
criteria.minimumPointsRequiredToPass(),
|
||||
pointTemplates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return save(gradingReportTemplate);
|
||||
}
|
||||
|
||||
private GradingCriterionPointTemplate toPointTemplate(GradingReportTemplateUpdate.Criteria.Requirement requirement) {
|
||||
return new GradingCriterionPointTemplate.Builder()
|
||||
.point(requirement.points())
|
||||
.description(requirement.description().swedish())
|
||||
.descriptionEn(requirement.description().english())
|
||||
.build();
|
||||
}
|
||||
}
|
@ -97,6 +97,11 @@ public class AdminGradingTemplateEditPage extends AbstractAdminProjectPage imple
|
||||
}
|
||||
return new GradingReportTemplateUpdate.Criteria(
|
||||
new LocalizedString(criteria.getTitleEn(), criteria.getTitleSv()),
|
||||
switch (criteria.getType()) {
|
||||
case PROJECT -> GradingReportTemplateUpdate.Criteria.Type.THESIS;
|
||||
case INDIVIDUAL -> GradingReportTemplateUpdate.Criteria.Type.INDIVIDUAL;
|
||||
},
|
||||
criteria.getPointsRequiredToPass(),
|
||||
getFlag(criteria),
|
||||
requirements);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user