use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCaseWithKnownOtherFacility.
@Test
public void testSaveReturnedCaseWithKnownOtherFacility() throws SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(officer, rdcf, c -> {
c.setPerson(person.toReference());
c.setHealthFacility(getFacilityFacade().getByUuid(FacilityDto.OTHER_FACILITY_UUID).toReference());
c.setHealthFacilityDetails("Test HF details");
});
User officerUser = getUserService().getByReferenceDto(officer);
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
caze.setHealthFacilityDetails(rdcf.facility.getCaption());
Calendar calendar = Calendar.getInstance();
calendar.setTime(caze.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
caze.setChangeDate(calendar.getTime());
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(originInfo);
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
try {
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
} catch (Exception e) {
e.printStackTrace();
}
CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(returnedCase.getHealthFacility(), is(rdcf.facility));
assertThat(returnedCase.getHealthFacilityDetails(), is(nullValue()));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCaseWithKnownOtherPointOfEntry.
@Test
public void testSaveReturnedCaseWithKnownOtherPointOfEntry() throws SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(officer, rdcf, c -> {
c.setPerson(person.toReference());
c.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
c.setPointOfEntry(new PointOfEntryReferenceDto(PointOfEntryDto.OTHER_SEAPORT_UUID, null, null, null));
c.setPointOfEntryDetails("Test Seaport");
});
User officerUser = getUserService().getByReferenceDto(officer);
getSormasToSormasShareInfoService().persist(createShareInfo(DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
caze.setPointOfEntryDetails(rdcf.pointOfEntry.getCaption());
Calendar calendar = Calendar.getInstance();
calendar.setTime(caze.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
caze.setChangeDate(calendar.getTime());
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(originInfo);
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
try {
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
} catch (Exception e) {
e.printStackTrace();
}
CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(returnedCase.getPointOfEntry(), is(rdcf.pointOfEntry));
assertThat(returnedCase.getPointOfEntryDetails(), is(nullValue()));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasTest method createSormasToSormasOriginInfo.
protected SormasToSormasOriginInfoDto createSormasToSormasOriginInfo(String serverId, boolean ownershipHandedOver) {
SormasToSormasOriginInfoDto source = new SormasToSormasOriginInfoDto();
source.setOrganizationId(serverId);
source.setSenderName("John doe");
source.setOwnershipHandedOver(ownershipHandedOver);
return source;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEncryptionServiceTest method testEncryptDecrypt.
@Test
public void testEncryptDecrypt() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
PersonDto person = creator.createPerson("FirstName", "LastName");
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
CaseDataDto caze = creator.createCase(officer, rdcf, dto -> {
dto.setPerson(person.toReference());
dto.setSurveillanceOfficer(officer);
dto.setClassificationUser(officer);
});
SormasToSormasDto bodyToEncrypt = new SormasToSormasDto();
SormasToSormasOriginInfoDto s2sOriginInfo = new SormasToSormasOriginInfoDto();
s2sOriginInfo.setComment("Test comment");
bodyToEncrypt.setOriginInfo(s2sOriginInfo);
bodyToEncrypt.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
mockS2Snetwork();
// encrypt
mockDefaultServerAccess();
SormasToSormasEncryptedDataDto encryptedBody = getSormasToSormasEncryptionFacade().signAndEncrypt(bodyToEncrypt, SECOND_SERVER_ID);
mockSecondServerAccess();
assertThat(encryptedBody.getSenderId(), is(DEFAULT_SERVER_ID));
assertThat(encryptedBody.getData(), instanceOf(byte[].class));
// decrypt
mockSecondServerAccess();
SormasToSormasDto decryptedBody = getSormasToSormasEncryptionFacade().decryptAndVerify(encryptedBody, SormasToSormasDto.class);
mockDefaultServerAccess();
assertThat(decryptedBody.getCases().size(), is(1));
SormasToSormasCaseDto decryptedCase = decryptedBody.getCases().get(0);
assertThat(decryptedCase.getPerson().getFirstName(), is("FirstName"));
assertThat(decryptedCase.getPerson().getLastName(), is("LastName"));
assertThat(decryptedBody.getOriginInfo().getComment(), is("Test comment"));
assertThat(decryptedBody.getSamples(), is(nullValue()));
assertThat(decryptedBody.getContacts(), is(nullValue()));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSyncCases.
@Test
public void testSyncCases() throws SormasToSormasValidationException, SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto casePerson = creator.createPerson();
CaseDataDto caze = creator.createCase(officer, casePerson.toReference(), rdcf, c -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setWithAssociatedContacts(true);
originInfo.setOwnershipHandedOver(true);
c.setSormasToSormasOriginInfo(originInfo);
});
PersonDto contactPerson = creator.createPerson();
ContactDto contact = creator.createContact(officer, officer, contactPerson.toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf, (c) -> c.setSormasToSormasOriginInfo(caze.getSormasToSormasOriginInfo()));
ShareRequestInfo shareRequestInfo = createShareRequestInfo(getUserService().getByUuid(officer.getUuid()), SECOND_SERVER_ID, false, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByUuid(caze.getUuid())));
shareRequestInfo.setWithAssociatedContacts(true);
shareRequestInfo.getShares().add(createShareInfo(SECOND_SERVER_ID, false, i -> i.setContact(getContactService().getByUuid(contact.getUuid()))));
getShareRequestInfoService().persist(shareRequestInfo);
PersonDto newContactPerson = creator.createPerson();
ContactDto newContact = creator.createContact(officer, officer, newContactPerson.toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf, (c) -> c.setSormasToSormasOriginInfo(caze.getSormasToSormasOriginInfo()));
caze.setAdditionalDetails("Test updated details");
contact.setContactStatus(ContactStatus.DROPPED);
Calendar calendar = Calendar.getInstance();
calendar.setTime(caze.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
caze.setChangeDate(calendar.getTime());
SormasToSormasDto shareData = new SormasToSormasDto();
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
originInfo.setWithAssociatedContacts(true);
shareData.setOriginInfo(originInfo);
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(casePerson, caze)));
shareData.setContacts(Arrays.asList(new SormasToSormasContactDto(contactPerson, contact), new SormasToSormasContactDto(newContactPerson, newContact)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(new SyncDataDto(shareData, new ShareTreeCriteria(caze.getUuid(), null, false)));
MockProducer.getProperties().setProperty(SormasToSormasConfig.SORMAS2SORMAS_IGNORE_ADDITIONAL_DETAILS, Boolean.FALSE.toString());
Mockito.when(MockProducer.getManagedScheduledExecutorService().schedule(ArgumentMatchers.any(Runnable.class), ArgumentMatchers.anyLong(), ArgumentMatchers.any())).then(invocation -> {
((Runnable) invocation.getArgument(0)).run();
return null;
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(caze.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(SECOND_SERVER_ID));
assertThat(syncData.getCriteria().isForwardOnly(), is(false));
assertThat(syncData.getShareData().getCases().get(0).getEntity().getUuid(), is(caze.getUuid()));
assertThat(syncData.getShareData().getCases().get(0).getEntity().getAdditionalDetails(), is("Test updated details"));
assertThat(syncData.getShareData().getContacts(), hasSize(2));
return Response.noContent().build();
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(caze.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(nullValue()));
assertThat(syncData.getCriteria().isForwardOnly(), is(true));
assertThat(syncData.getShareData().getCases().get(0).getEntity().getUuid(), is(caze.getUuid()));
assertThat(syncData.getShareData().getCases().get(0).getEntity().getAdditionalDetails(), is("Test updated details"));
// new contact should not be shared
assertThat(syncData.getShareData().getContacts(), hasSize(1));
assertThat(syncData.getShareData().getContacts().get(0).getEntity().getUuid(), is(contact.getUuid()));
return Response.noContent().build();
});
getSormasToSormasCaseFacade().saveSyncedEntity(encryptedData);
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
}
Aggregations