Search in sources :

Example 1 with ValidationRuntimeException

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());
    }
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date)

Example 2 with ValidationRuntimeException

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();
}
Also used : CaseImportEntities(de.symeda.sormas.api.caze.caseimport.CaseImportEntities) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Example 3 with ValidationRuntimeException

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);
}
Also used : User(de.symeda.sormas.backend.user.User) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException)

Example 4 with ValidationRuntimeException

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()));
    }
}
Also used : ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException)

Example 5 with ValidationRuntimeException

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));
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException)

Aggregations

ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)29 IOException (java.io.IOException)8 PersonDto (de.symeda.sormas.api.person.PersonDto)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)6 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)6 Date (java.util.Date)6 Transient (javax.persistence.Transient)6 ArrayList (java.util.ArrayList)5 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 ContactDto (de.symeda.sormas.api.contact.ContactDto)3 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)3 CampaignDashboardElement (de.symeda.sormas.api.campaign.diagram.CampaignDashboardElement)2 CampaignFormElement (de.symeda.sormas.api.campaign.form.CampaignFormElement)2 CampaignFormMetaDto (de.symeda.sormas.api.campaign.form.CampaignFormMetaDto)2 CampaignFormTranslations (de.symeda.sormas.api.campaign.form.CampaignFormTranslations)2 EventDto (de.symeda.sormas.api.event.EventDto)2 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)2 ImportRelatedObjectsMapper (de.symeda.sormas.api.importexport.ImportRelatedObjectsMapper)2 PathogenTestDto (de.symeda.sormas.api.sample.PathogenTestDto)2