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;
}
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);
}
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));
}
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"));
}
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()));
}
Aggregations