Search in sources :

Example 1 with SormasToSormasContactDto

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

the class SormasToSormasContactDtoValidator method validate.

@Override
public ValidationErrors validate(SormasToSormasContactDto sharedData, ValidationDirection direction) {
    ContactDto contact = sharedData.getEntity();
    ValidationErrors validationErrors = new ValidationErrors(buildContactValidationGroupName(contact));
    ValidationErrors personValidationErrors = validatePerson(sharedData.getPerson(), direction);
    validationErrors.addAll(personValidationErrors);
    String groupNameTag = Captions.Contact;
    infraValidator.validateRegion(contact.getRegion(), groupNameTag, validationErrors, contact::setRegion, direction);
    infraValidator.validateDistrict(contact.getDistrict(), groupNameTag, validationErrors, contact::setDistrict, direction);
    infraValidator.validateCommunity(contact.getCommunity(), groupNameTag, validationErrors, contact::setCommunity, direction);
    infraValidator.validateDistrict(contact.getReportingDistrict(), groupNameTag, validationErrors, contact::setReportingDistrict, direction);
    validateEpiData(contact.getEpiData(), validationErrors, direction);
    return validationErrors;
}
Also used : ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto)

Example 2 with SormasToSormasContactDto

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

the class ReceivedContactProcessor method handleReceivedData.

@Override
public void handleReceivedData(SormasToSormasContactDto sharedData, Contact existingData) {
    handleIgnoredProperties(sharedData.getEntity(), contactFacade.toDto(existingData));
    handleIgnoredProperties(sharedData.getPerson(), Optional.ofNullable(existingData).map(c -> PersonFacadeEjb.toDto(c.getPerson())).orElse(null));
    ContactDto contact = sharedData.getEntity();
    PersonDto person = sharedData.getPerson();
    contact.setPerson(person.toReference());
    updateReportingUser(contact, existingData);
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto)

Example 3 with SormasToSormasContactDto

use of de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto 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 SormasToSormasContactDto

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

the class SormasToSormasContactFacadeEjbTest method testShareContact.

@Test
public void testShareContact() throws SormasToSormasException {
    useSurveillanceOfficerLogin(rdcf);
    PersonDto person = creator.createPerson();
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    ContactDto contact = creator.createContact(officer, officer, person.toReference(), null, new Date(), null, null, rdcf, dto -> dto.setResultingCaseUser(officer));
    SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
    options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
    options.setComment("Test comment");
    Mockito.when(MockProducer.getSormasToSormasClient().post(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
        assertThat(invocation.getArgument(0, String.class), is(SECOND_SERVER_ID));
        assertThat(invocation.getArgument(1, String.class), is("/sormasToSormas/contacts"));
        SormasToSormasDto postBody = invocation.getArgument(2, SormasToSormasDto.class);
        assertThat(postBody.getContacts().size(), is(1));
        SormasToSormasContactDto sharedContact = postBody.getContacts().get(0);
        assertThat(sharedContact.getPerson().getFirstName(), is(person.getFirstName()));
        assertThat(sharedContact.getPerson().getLastName(), is(person.getLastName()));
        assertThat(sharedContact.getEntity().getUuid(), is(contact.getUuid()));
        // users should be cleaned up
        assertThat(sharedContact.getEntity().getReportingUser(), is(nullValue()));
        assertThat(sharedContact.getEntity().getContactOfficer(), is(nullValue()));
        assertThat(sharedContact.getEntity().getResultingCaseUser(), is(nullValue()));
        // share information
        assertThat(postBody.getOriginInfo().getOrganizationId(), is(DEFAULT_SERVER_ID));
        assertThat(postBody.getOriginInfo().getSenderName(), is("Surv Off"));
        assertThat(postBody.getOriginInfo().getComment(), is("Test comment"));
        return Response.noContent().build();
    });
    getSormasToSormasContactFacade().share(Collections.singletonList(contact.getUuid()), options);
    List<SormasToSormasShareInfoDto> shareInfoList = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().contact(contact.toReference()), 0, 100);
    assertThat(shareInfoList.size(), is(1));
    assertThat(shareInfoList.get(0).getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
    assertThat(shareInfoList.get(0).getSender().getCaption(), is("Surv OFF - Surveillance Officer"));
    assertThat(shareInfoList.get(0).getComment(), is("Test comment"));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Date(java.util.Date) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 5 with SormasToSormasContactDto

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

the class SormasToSormasCaseFacadeEjbTest method testSaveSharedCaseWithContacts.

@Test
public void testSaveSharedCaseWithContacts() throws SormasToSormasException, SormasToSormasValidationException {
    PersonDto person = createPersonDto(rdcf);
    CaseDataDto caze = createRemoteCaseDto(rdcf, person);
    ContactDto contact = createRemoteContactDto(rdcf, caze);
    PersonDto contactPerson = createPersonDto(rdcf);
    contact.setPerson(contactPerson.toReference());
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
    shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
    shareData.setContacts(Collections.singletonList(new SormasToSormasContactDto(contactPerson, contact)));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
    CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
    ContactDto savedContact = getContactFacade().getByUuid(contact.getUuid());
    assertThat(savedContact, is(notNullValue()));
    assertThat(savedContact.getRegion(), is(rdcf.region));
    assertThat(savedContact.getDistrict(), is(rdcf.district));
    assertThat(savedContact.getCommunity(), is(rdcf.community));
    assertThat(savedCase.getSormasToSormasOriginInfo().getUuid(), is(savedContact.getSormasToSormasOriginInfo().getUuid()));
}
Also used : SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Aggregations

SormasToSormasContactDto (de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto)16 ContactDto (de.symeda.sormas.api.contact.ContactDto)11 PersonDto (de.symeda.sormas.api.person.PersonDto)10 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)9 SormasToSormasSampleDto (de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto)9 Test (org.junit.Test)9 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)8 SormasToSormasEncryptedDataDto (de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto)7 SormasToSormasCaseDto (de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto)7 Date (java.util.Date)6 SampleDto (de.symeda.sormas.api.sample.SampleDto)5 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)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 SormasToSormasValidationException (de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException)5 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)5 Disease (de.symeda.sormas.api.Disease)4 QuarantineType (de.symeda.sormas.api.contact.QuarantineType)4