Skip to content
Snippets Groups Projects

Prevent import of multiple training

2 files
+ 24
3
Compare changes
  • Side-by-side
  • Inline

Files

@@ -26,6 +26,7 @@ import nl.tudelft.tam.dto.id.ProfileIdDTO;
import nl.tudelft.tam.model.TrainingApproval;
import nl.tudelft.tam.model.TrainingType;
import nl.tudelft.tam.service.PersonService;
import nl.tudelft.tam.service.TrainingApprovalService;
import nl.tudelft.tam.service.TrainingTypeService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,12 +38,15 @@ public class TrainingImportHandler extends ImportHandler<TrainingApproval> {
private final PersonService personService;
private final TrainingApprovalService trainingApprovalService;
private final TrainingTypeService trainingTypeService;
private Long programId = null;
@Autowired
public TrainingImportHandler(PersonService personService, TrainingTypeService trainingTypeService) {
public TrainingImportHandler(PersonService personService, TrainingApprovalService trainingApprovalService,
TrainingTypeService trainingTypeService) {
this.personService = personService;
this.trainingApprovalService = trainingApprovalService;
this.trainingTypeService = trainingTypeService;
}
@@ -95,6 +99,13 @@ public class TrainingImportHandler extends ImportHandler<TrainingApproval> {
"Multiple training types with name " + line[1] + " found, using the first one"));
}
if (trainingApprovalService
.findByPersonIdAndType(personSearchResult.get(0).getId(), validTrainingTypes.get(0))
.isPresent()) {
return new ImportResult.Error<>(
new SimpleImportError("User " + line[0] + " already completed training " + line[1]));
}
training.setPerson(new ProfileIdDTO(personSearchResult.get(0).getId()));
training.setType(validTrainingTypes.get(0));
training.setDatePassed(parseDate(line[2])
Loading