Search in sources :

Example 1 with ValidationErrorGroup

use of de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasLabMessageFacadeEjb method validateSharedLabMessage.

private ValidationErrors validateSharedLabMessage(SormasToSormasLabMessageDto dto) throws ValidationRuntimeException {
    ValidationErrors errors = new ValidationErrors();
    if (labMessageFacade.exists(dto.getEntity().getUuid())) {
        errors.add(new ValidationErrorGroup(Captions.LabMessage), new ValidationErrorMessage(Validations.sormasToSormasLabMessageExists));
    }
    errors.addAll(dtoValidator.validateIncoming(dto));
    return errors;
}
Also used : ValidationErrorGroup(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup) ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) ValidationErrorMessage(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorMessage)

Example 2 with ValidationErrorGroup

use of de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup in project SORMAS-Project by hzi-braunschweig.

the class ReceivedEntitiesProcessor method processReceivedRequest.

public List<ValidationErrors> processReceivedRequest(ShareRequestData shareData) {
    List<ValidationErrors> validationErrors = new ArrayList<>();
    SormasToSormasOriginInfoDto originInfo = shareData.getOriginInfo();
    originInfo.setUuid(DataHelper.createUuid());
    originInfo.setChangeDate(new Date());
    ValidationErrors originInfoErrors = validateOriginInfo(originInfo, Captions.sormasToSormasOriginInfo);
    if (originInfoErrors.hasError()) {
        validationErrors.add(new ValidationErrors(new ValidationErrorGroup(Captions.sormasToSormasOriginInfo), originInfoErrors));
    }
    shareData.getPreviews().getCases().forEach(c -> {
        ValidationErrors caseErrors = caseProcessor.processReceivedPreview(c);
        if (caseErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildCaseValidationGroupName(c), caseErrors));
        }
    });
    shareData.getPreviews().getContacts().forEach(c -> {
        ValidationErrors contactErrors = contactProcessor.processReceivedPreview(c);
        if (contactErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildContactValidationGroupName(c), contactErrors));
        }
    });
    shareData.getPreviews().getEvents().forEach(e -> {
        ValidationErrors eventErrors = eventProcessor.processReceivedPreview(e);
        if (eventErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildEventValidationGroupName(e), eventErrors));
        }
    });
    shareData.getPreviews().getEventParticipants().forEach(ep -> {
        ValidationErrors eventParticipantErrors = eventParticipantProcessor.processReceivedPreview(ep);
        if (eventParticipantErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildEventParticipantValidationGroupName(ep), eventParticipantErrors));
        }
    });
    return validationErrors;
}
Also used : ValidationErrorGroup(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup) ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) ArrayList(java.util.ArrayList) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) Date(java.util.Date)

Example 3 with ValidationErrorGroup

use of de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup in project SORMAS-Project by hzi-braunschweig.

the class ProcessedContactDataPersister method persistProcessedData.

private void persistProcessedData(SormasToSormasContactDto processedData, boolean isCreate) throws SormasToSormasValidationException {
    ValidationErrorGroup contactValidationGroupName = buildContactValidationGroupName(processedData.getEntity());
    if (isCreate) {
        // save person first during creation
        handleValidationError(() -> personFacade.savePerson(processedData.getPerson(), false, false, false), Captions.Person, contactValidationGroupName);
        handleValidationError(() -> contactFacade.save(processedData.getEntity(), true, true, false, false), Captions.Contact, contactValidationGroupName);
    } else {
        // save contact first during update
        handleValidationError(() -> contactFacade.save(processedData.getEntity(), true, true, false, false), Captions.Contact, contactValidationGroupName);
        handleValidationError(() -> personFacade.savePerson(processedData.getPerson(), false, false, false), Captions.Person, contactValidationGroupName);
    }
}
Also used : ValidationErrorGroup(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup)

Example 4 with ValidationErrorGroup

use of de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup in project SORMAS-Project by hzi-braunschweig.

the class InfrastructureValidator method validateInfra.

private <DTO extends InfrastructureDto, INDEX_DTO extends Serializable, REF_DTO extends InfrastructureDataReferenceDto, CRITERIA extends BaseCriteria> void validateInfra(InfrastructureDataReferenceDto dto, String groupNameTag, ValidationErrors validationErrors, InfrastructureFacade<DTO, INDEX_DTO, REF_DTO, CRITERIA> facade, String i18property, Consumer<REF_DTO> onNoErrors, ValidationDirection validationDirection) {
    if (dto == null) {
        return;
    }
    if (validationDirection == ValidationDirection.INCOMING) {
        // try to look up the received infrastructure entity locally
        DTO match = facade.getByUuid(dto.getUuid());
        if (match != null && match.isCentrallyManaged()) {
            // todo AbstractBaseEjb::toRefDto is not part of the facade, so we load twice here, this will be fixed in the future
            REF_DTO matchRef = facade.getReferenceByUuid(dto.getUuid());
            onNoErrors.accept(matchRef);
        } else {
            validationErrors.add(new ValidationErrorGroup(groupNameTag), new ValidationErrorMessage(i18property, dto.getCaption()));
        }
    } else if (validationDirection == ValidationDirection.OUTGOING) {
        // check if the infra we are going to send via S2S is centrally managed
        DTO match = facade.getByUuid(dto.getUuid());
        if (!match.isCentrallyManaged()) {
            validationErrors.add(new ValidationErrorGroup(groupNameTag), new ValidationErrorMessage(i18property, dto.getCaption()));
        }
    } else {
        throw new IllegalStateException("Unexpected value: " + validationDirection);
    }
}
Also used : ValidationErrorGroup(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup) ValidationErrorMessage(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorMessage)

Aggregations

ValidationErrorGroup (de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup)4 ValidationErrorMessage (de.symeda.sormas.api.sormastosormas.validation.ValidationErrorMessage)2 ValidationErrors (de.symeda.sormas.api.sormastosormas.validation.ValidationErrors)2 SormasToSormasOriginInfoDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1