use of de.symeda.sormas.api.utils.ValidationRuntimeException in project SORMAS-Project by hzi-braunschweig.
the class CaseImportFacadeEjb method saveImportedEntities.
@Override
public ImportLineResultDto<CaseImportEntities> saveImportedEntities(@Valid CaseImportEntities entities, boolean skipPersonValidation) {
CaseDataDto caze = entities.getCaze();
PersonDto person = entities.getPerson();
List<SampleDto> samples = entities.getSamples();
List<PathogenTestDto> pathogenTests = entities.getPathogenTests();
List<VaccinationDto> vaccinations = entities.getVaccinations();
try {
// Necessary to make sure that the follow-up information is retained
if (featureConfigurationFacade.isFeatureEnabled(FeatureType.CASE_FOLLOWUP) && caze.getFollowUpStatus() == null) {
caze.setFollowUpStatus(FollowUpStatus.FOLLOW_UP);
}
if (caze.getEpidNumber() != null && caseFacade.doesEpidNumberExist(caze.getEpidNumber(), caze.getUuid(), caze.getDisease())) {
return ImportLineResultDto.errorResult(I18nProperties.getString(Strings.messageEpidNumberWarning));
}
// PersonDto savedPerson = personFacade.savePerson(person);
final PersonDto savedPerson = personFacade.savePerson(person, skipPersonValidation);
caze.setPerson(savedPerson.toReference());
// Workaround: Reset the change date to avoid OutdatedEntityExceptions
// Should be changed when doing #2265
caze.setChangeDate(new Date());
caseFacade.save(caze);
for (SampleDto sample : samples) {
sampleFacade.saveSample(sample);
}
for (PathogenTestDto pathogenTest : pathogenTests) {
pathogenTestFacade.savePathogenTest(pathogenTest);
}
for (VaccinationDto vaccination : vaccinations) {
vaccinationFacade.createWithImmunization(vaccination, caze.getResponsibleRegion(), caze.getResponsibleDistrict(), caze.getPerson(), caze.getDisease());
}
return ImportLineResultDto.successResult();
} catch (ValidationRuntimeException e) {
return ImportLineResultDto.errorResult(e.getMessage());
}
}
use of de.symeda.sormas.api.utils.ValidationRuntimeException in project SORMAS-Project by hzi-braunschweig.
the class CaseImportFacadeEjb method validateEntities.
private ImportLineResultDto<CaseImportEntities> validateEntities(CaseImportEntities entities) {
ImportLineResultDto<CaseImportEntities> validationResult = importFacade.validateConstraints(entities);
if (validationResult.isError()) {
return validationResult;
}
try {
personFacade.validate(entities.getPerson());
caseFacade.validate(entities.getCaze());
for (SampleDto sample : entities.getSamples()) {
sampleFacade.validate(sample);
}
for (PathogenTestDto pathogenTest : entities.getPathogenTests()) {
pathogenTestFacade.validate(pathogenTest);
}
} catch (ValidationRuntimeException e) {
return ImportLineResultDto.errorResult(e.getMessage());
}
return ImportLineResultDto.successResult();
}
use of de.symeda.sormas.api.utils.ValidationRuntimeException in project SORMAS-Project by hzi-braunschweig.
the class AbstractInfrastructureFacadeEjb method doSave.
protected DTO doSave(DTO dtoToSave, boolean allowMerge, boolean includeArchived, boolean checkChangeDate, String duplicateErrorMessageProperty) {
if (dtoToSave == null) {
return null;
}
ADO existingEntity = service.getByUuid(dtoToSave.getUuid());
final User currentUser = userService.getCurrentUser();
if (currentUser != null) {
if (existingEntity == null && !userService.hasRight(UserRight.INFRASTRUCTURE_CREATE)) {
throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to create infrastructure data.");
}
if (existingEntity != null && !userService.hasRight(UserRight.INFRASTRUCTURE_EDIT)) {
throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to edit infrastructure data.");
}
}
if (existingEntity == null) {
List<ADO> duplicates = findDuplicates(dtoToSave, includeArchived);
if (!duplicates.isEmpty()) {
if (allowMerge) {
return mergeAndPersist(dtoToSave, duplicates, checkChangeDate);
} else {
throw new ValidationRuntimeException(I18nProperties.getValidationError(duplicateErrorMessageProperty));
}
}
}
return persistEntity(dtoToSave, existingEntity, checkChangeDate);
}
use of de.symeda.sormas.api.utils.ValidationRuntimeException in project SORMAS-Project by hzi-braunschweig.
the class PatchHelper method updateObjectList.
/**
* This method updates the fields of type collections (lists or array).
*
* @param existingObject
* @param jsonObjectFieldNode
* @param existingObjectField
* @param <T>
* @throws JsonProcessingException
* @throws IllegalAccessException
*/
private static <T extends HasUuid> void updateObjectList(T existingObject, JsonNode jsonObjectFieldNode, Field existingObjectField) {
Class listElementClass = getParameterizedType(existingObjectField);
List tempNewElementList = new ArrayList();
for (JsonNode listElement : jsonObjectFieldNode) {
T updatedListObject = createOrUpdateListElement(existingObject, existingObjectField, listElementClass, listElement);
if (updatedListObject != null) {
tempNewElementList.add(updatedListObject);
}
}
if (existingObjectField.getType().isAssignableFrom(List.class)) {
Object existingObjectFieldInstance = null;
try {
existingObjectFieldInstance = existingObjectField.get(existingObject);
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot access field " + existingObjectField.getName() + " on the object of type: " + existingObject.getClass().getSimpleName(), e.getCause());
}
if (existingObjectFieldInstance != null) {
Collection existingElementList = (Collection) existingObjectFieldInstance;
existingElementList.clear();
existingElementList.addAll(tempNewElementList);
} else {
try {
existingObjectField.set(existingObject, tempNewElementList);
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot access field " + existingObjectField.getName() + " on the object of type: " + existingObject.getClass().getSimpleName(), e.getCause());
}
}
} else if (existingObjectField.getType().isArray()) {
try {
existingObjectField.set(existingObject, tempNewElementList.toArray());
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot access field " + existingObjectField.getName() + " on the object of type: " + existingObject.getClass().getSimpleName(), e.getCause());
}
} else {
throw new ValidationRuntimeException(I18nProperties.getValidationError(Validations.patchUnsupportedCollectionFieldType, existingObjectField.getName(), existingObjectField.getType().getSimpleName()));
}
}
use of de.symeda.sormas.api.utils.ValidationRuntimeException in project SORMAS-Project by hzi-braunschweig.
the class VaccinationFacadeEjb method createWithImmunization.
@Override
public VaccinationDto createWithImmunization(VaccinationDto dto, RegionReferenceDto region, DistrictReferenceDto district, PersonReferenceDto person, Disease disease) {
if (dto.getImmunization() != null) {
throw new IllegalArgumentException("VaccinationDto already has an immunization assigned");
}
if (dto.getUuid() != null && vaccinationService.getByUuid(dto.getUuid()) != null) {
throw new IllegalArgumentException("VaccinationDto already has a UUID");
}
validate(dto, true);
Vaccination vaccination = null;
vaccination = fillOrBuildEntity(dto, vaccination, true);
boolean immunizationFound = addImmunizationToVaccination(vaccination, person.getUuid(), disease);
if (!immunizationFound) {
ImmunizationDto immunizationDto = ImmunizationDto.build(person);
immunizationDto.setDisease(disease);
immunizationDto.setResponsibleRegion(region);
immunizationDto.setResponsibleDistrict(district);
immunizationDto.setReportingUser(userService.getCurrentUser().toReference());
immunizationDto.setMeansOfImmunization(MeansOfImmunization.VACCINATION);
immunizationDto.setImmunizationStatus(ImmunizationStatus.ACQUIRED);
immunizationDto.setImmunizationManagementStatus(ImmunizationManagementStatus.COMPLETED);
immunizationFacade.save(immunizationDto);
Immunization immunization = immunizationService.getByUuid(immunizationDto.getUuid());
vaccination.setImmunization(immunization);
}
if (vaccination.getImmunization() == null) {
throw new ValidationRuntimeException(I18nProperties.getValidationError(Validations.validImmunization));
}
vaccinationService.ensurePersisted(vaccination);
updateVaccinationStatuses(vaccination.getVaccinationDate(), null, vaccination.getImmunization().getPerson().getId(), disease);
return convertToDto(vaccination, Pseudonymizer.getDefault(userService::hasRight));
}
Aggregations