Search in sources :

Example 1 with SormasToSormasValidationException

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

the class AbstractSormasToSormasInterface method processShareRequest.

private ShareRequestData processShareRequest(SormasToSormasEncryptedDataDto encryptedData) throws SormasToSormasException, SormasToSormasValidationException {
    ShareRequestData shareData = sormasToSormasEncryptionEjb.decryptAndVerify(encryptedData, ShareRequestData.class);
    List<ValidationErrors> validationErrors = receivedEntitiesProcessor.processReceivedRequest(shareData);
    if (!validationErrors.isEmpty()) {
        throw new SormasToSormasValidationException(validationErrors);
    }
    return shareData;
}
Also used : ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) ShareRequestData(de.symeda.sormas.backend.sormastosormas.share.ShareRequestData)

Example 2 with SormasToSormasValidationException

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

the class AbstractSormasToSormasInterface method perisist.

private void perisist(@Valid SormasToSormasDto receivedData, Persister persister) throws SormasToSormasValidationException {
    ShareDataExistingEntities existingEntities = loadExistingEntities(receivedData);
    List<ValidationErrors> validationErrors = receivedEntitiesProcessor.processReceivedData(receivedData, existingEntities);
    if (!validationErrors.isEmpty()) {
        throw new SormasToSormasValidationException(validationErrors);
    }
    persister.call(receivedData, existingEntities);
}
Also used : ShareDataExistingEntities(de.symeda.sormas.backend.sormastosormas.entities.ShareDataExistingEntities) ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException)

Example 3 with SormasToSormasValidationException

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

the class SormasToSormasContactFacadeEjbTest method testSaveReturnedContact.

@Test
public void testSaveReturnedContact() throws SormasToSormasException, SormasToSormasValidationException {
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    PersonDto contactPerson = creator.createPerson();
    ContactDto contact = creator.createContact(rdcf, officer, contactPerson.toReference());
    SampleDto sharedSample = creator.createSample(contact.toReference(), officer, rdcf.facility, null);
    SampleDto newSample = createRemoteSample(contact.toReference(), officer, rdcf.facility);
    User officerUser = getUserService().getByReferenceDto(officer);
    getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setContact(getContactService().getByReferenceDto(contact.toReference()))));
    getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setSample(getSampleService().getByReferenceDto(sharedSample.toReference()))));
    contact.setQuarantine(QuarantineType.HOTEL);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(contact.getChangeDate());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    contact.setChangeDate(calendar.getTime());
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true));
    shareData.setContacts(Collections.singletonList(new SormasToSormasContactDto(contactPerson, contact)));
    shareData.setSamples(Arrays.asList(new SormasToSormasSampleDto(sharedSample, Collections.emptyList(), Collections.emptyList()), new SormasToSormasSampleDto(newSample, Collections.emptyList(), Collections.emptyList())));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasContactFacade().saveSharedEntities(encryptedData);
    ContactDto returnedContact = getContactFacade().getByUuid(contact.getUuid());
    assertThat(returnedContact.getQuarantine(), is(QuarantineType.HOTEL));
    assertThat(returnedContact.getReportingUser(), is(officer));
    List<SormasToSormasShareInfoDto> contactShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().contact(contact.toReference()), 0, 100);
    assertThat(contactShares.get(0).isOwnershipHandedOver(), is(false));
    List<SormasToSormasShareInfoDto> sampleShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().sample(sharedSample.toReference()), 0, 100);
    assertThat(sampleShares.get(0).isOwnershipHandedOver(), is(false));
    SampleDto returnedNewSample = getSampleFacade().getSampleByUuid(newSample.getUuid());
    assertThat(returnedNewSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) ExposureType(de.symeda.sormas.api.exposure.ExposureType) PersonDto(de.symeda.sormas.api.person.PersonDto) Matchers.nullValue(org.hamcrest.Matchers.nullValue) UserRole(de.symeda.sormas.api.user.UserRole) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Matchers.is(org.hamcrest.Matchers.is) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) MockProducer(de.symeda.sormas.backend.MockProducer) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) QuarantineType(de.symeda.sormas.api.contact.QuarantineType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AnimalCondition(de.symeda.sormas.api.epidata.AnimalCondition) DataHelper(de.symeda.sormas.api.utils.DataHelper) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) Test(org.junit.Test) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SormasToSormasConfig(de.symeda.sormas.api.sormastosormas.SormasToSormasConfig) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Collections(java.util.Collections) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) PersonDto(de.symeda.sormas.api.person.PersonDto) Calendar(java.util.Calendar) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 4 with SormasToSormasValidationException

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

the class SormasToSormasEventFacadeEjbTest method testSaveReturnedEvent.

@Test
public void testSaveReturnedEvent() throws SormasToSormasException, SormasToSormasValidationException {
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    EventDto event = creator.createEvent(officer);
    EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson(), officer);
    EventParticipantDto newEventParticipant = createEventParticipantDto(event.toReference(), UserDto.build().toReference(), rdcf);
    FacilityDto lab = creator.createFacility("Test Lab", rdcf.region, rdcf.district, null, FacilityType.LABORATORY);
    SampleDto newSample = createSample(newEventParticipant.toReference(), officer, lab.toReference());
    User officerUser = getUserService().getByReferenceDto(officer);
    ShareRequestInfo shareRequestInfo = createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setEvent(getEventService().getByReferenceDto(event.toReference())));
    shareRequestInfo.setWithEventParticipants(true);
    shareRequestInfo.getShares().add(createShareInfo(DEFAULT_SERVER_ID, true, i -> i.setEventParticipant(getEventParticipantService().getByReferenceDto(eventParticipant.toReference()))));
    getShareRequestInfoService().persist(shareRequestInfo);
    event.setEventDesc("Test updated description");
    eventParticipant.getPerson().setBirthName("Test birth name");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(event.getChangeDate());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    event.setChangeDate(calendar.getTime());
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true));
    shareData.setEvents(Collections.singletonList(new SormasToSormasEventDto(event)));
    shareData.setEventParticipants(Arrays.asList(new SormasToSormasEventParticipantDto(eventParticipant), new SormasToSormasEventParticipantDto(newEventParticipant)));
    shareData.setSamples(Collections.singletonList(new SormasToSormasSampleDto(newSample, Collections.emptyList(), Collections.emptyList())));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasEventFacade().saveSharedEntities(encryptedData);
    EventDto returnedEvent = getEventFacade().getEventByUuid(event.getUuid(), false);
    assertThat(returnedEvent.getEventDesc(), is("Test updated description"));
    assertThat(returnedEvent.getReportingUser(), is(officer));
    List<SormasToSormasShareInfoDto> eventShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().event(event.toReference()), 0, 100);
    assertThat(eventShares.get(0).isOwnershipHandedOver(), is(false));
    assertThat(getEventParticipantFacade().getEventParticipantByUuid(eventParticipant.getUuid()).getPerson().getBirthName(), is("Test birth name"));
    List<SormasToSormasShareInfoDto> eventParticipantShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().eventParticipant(eventParticipant.toReference()), 0, 100);
    assertThat(eventParticipantShares.get(0).isOwnershipHandedOver(), is(false));
    EventParticipantDto returnedNewEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(newEventParticipant.getUuid());
    assertThat(returnedNewEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
    SampleDto returnedNewSample = getSampleFacade().getSampleByUuid(newSample.getUuid());
    assertThat(returnedNewSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) Matchers.nullValue(org.hamcrest.Matchers.nullValue) EventInvestigationStatus(de.symeda.sormas.api.event.EventInvestigationStatus) UserRole(de.symeda.sormas.api.user.UserRole) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) EventDto(de.symeda.sormas.api.event.EventDto) RiskLevel(de.symeda.sormas.api.event.RiskLevel) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) Matchers.is(org.hamcrest.Matchers.is) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) MockProducer(de.symeda.sormas.backend.MockProducer) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) EventStatus(de.symeda.sormas.api.event.EventStatus) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) DataHelper(de.symeda.sormas.api.utils.DataHelper) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) UserDto(de.symeda.sormas.api.user.UserDto) Test(org.junit.Test) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventSourceType(de.symeda.sormas.api.event.EventSourceType) Collections(java.util.Collections) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) Calendar(java.util.Calendar) EventDto(de.symeda.sormas.api.event.EventDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 5 with SormasToSormasValidationException

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

the class ShareDataBuilder method buildShareData.

public SHARED buildShareData(ADO data, ShareRequestInfo requestInfo) throws SormasToSormasValidationException {
    SHARED shared = doBuildShareData(data, requestInfo);
    ValidationErrors errors = validator.validateOutgoing(shared);
    if (errors.hasError()) {
        List<ValidationErrors> validationErrors = new ArrayList<>();
        validationErrors.add(errors);
        throw new SormasToSormasValidationException(validationErrors);
    }
    return shared;
}
Also used : ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) ArrayList(java.util.ArrayList) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException)

Aggregations

SormasToSormasValidationException (de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException)11 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)6 SormasToSormasSampleDto (de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto)6 ValidationErrors (de.symeda.sormas.api.sormastosormas.validation.ValidationErrors)6 Disease (de.symeda.sormas.api.Disease)5 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)5 PersonDto (de.symeda.sormas.api.person.PersonDto)5 SampleDto (de.symeda.sormas.api.sample.SampleDto)5 SampleMaterial (de.symeda.sormas.api.sample.SampleMaterial)5 SamplePurpose (de.symeda.sormas.api.sample.SamplePurpose)5 ShareTreeCriteria (de.symeda.sormas.api.sormastosormas.ShareTreeCriteria)5 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)5 SormasToSormasEncryptedDataDto (de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto)5 SormasToSormasException (de.symeda.sormas.api.sormastosormas.SormasToSormasException)5 SormasToSormasOptionsDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto)5 SormasToSormasOriginInfoDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)5 SormasToSormasShareInfoCriteria (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria)5 SormasToSormasShareInfoDto (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto)5 ShareRequestStatus (de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus)5 SormasToSormasShareRequestDto (de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto)5