use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testReturnCase.
@Test
public void testReturnCase() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
PersonDto person = creator.createPerson();
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);
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
dto.setSormasToSormasOriginInfo(originInfo);
});
SormasToSormasShareRequestDto shareRequest = new SormasToSormasShareRequestDto();
shareRequest.setUuid(DataHelper.createUuid());
shareRequest.setOriginInfo(caze.getSormasToSormasOriginInfo());
getSormasToSormasShareRequestFacade().saveShareRequest(shareRequest);
ContactDto sharedContact = creator.createContact(officer, officer, creator.createPerson().toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf, c -> c.setSormasToSormasOriginInfo(caze.getSormasToSormasOriginInfo()));
SampleDto sharedSample = creator.createSample(caze.toReference(), officer, rdcf.facility, s -> s.setSormasToSormasOriginInfo(caze.getSormasToSormasOriginInfo()));
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
options.setHandOverOwnership(true);
options.setWithAssociatedContacts(true);
options.setWithSamples(true);
options.setComment("Test comment");
Mockito.when(MockProducer.getSormasToSormasClient().put(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> Response.noContent().build());
getSormasToSormasCaseFacade().share(Collections.singletonList(caze.getUuid()), options);
// case ownership should be lost
CaseDataDto sharedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(sharedCase.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
// contact ownership should be lost
sharedContact = getContactFacade().getByUuid(sharedContact.getUuid());
assertThat(sharedContact.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
// sample ownership should be lost
sharedSample = getSampleFacade().getSampleByUuid(sharedSample.getUuid());
assertThat(sharedSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasContactFacadeEjbTest method testSyncContacts.
@Test
public void testSyncContacts() throws SormasToSormasValidationException, SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto contactPerson = creator.createPerson();
ContactDto contact = creator.createContact(officer, officer, contactPerson.toReference(), null, new Date(), new Date(), Disease.CORONAVIRUS, 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);
});
getShareRequestInfoService().persist(createShareRequestInfo(getUserService().getByUuid(officer.getUuid()), SECOND_SERVER_ID, false, ShareRequestStatus.ACCEPTED, i -> {
i.setContact(getContactService().getByUuid(contact.getUuid()));
}));
contact.setAdditionalDetails("Test updated details");
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)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(new SyncDataDto(shareData, new ShareTreeCriteria(contact.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.any(), ArgumentMatchers.any(), ArgumentMatchers.any())).then(restInvocation -> {
SyncDataDto syncData = restInvocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(contact.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(SECOND_SERVER_ID));
assertThat(syncData.getCriteria().isForwardOnly(), is(false));
assertThat(syncData.getShareData().getContacts().get(0).getEntity().getUuid(), is(contact.getUuid()));
assertThat(syncData.getShareData().getContacts().get(0).getEntity().getAdditionalDetails(), is("Test updated details"));
return Response.noContent().build();
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/contacts/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(contact.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(nullValue()));
assertThat(syncData.getCriteria().isForwardOnly(), is(true));
assertThat(syncData.getShareData().getContacts().get(0).getEntity().getUuid(), is(contact.getUuid()));
assertThat(syncData.getShareData().getContacts().get(0).getEntity().getAdditionalDetails(), is("Test updated details"));
return Response.noContent().build();
});
getSormasToSormasContactFacade().saveSyncedEntity(encryptedData);
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/contacts/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/contacts/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testGetAllSharesOnMiddleLevel.
@Test
public void testGetAllSharesOnMiddleLevel() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
CaseDataDto caze = creator.createCase(officer, creator.createPerson().toReference(), rdcf, c -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
originInfo.setComment("first share");
c.setSormasToSormasOriginInfo(originInfo);
});
// initial share by the creator of case
SormasToSormasShareInfoDto shareToSecond = createShareInfoDto(officer, SECOND_SERVER_ID, true);
// another share by the creator
SormasToSormasShareInfoDto anotherShareFromDefault = createShareInfoDto(officer, "anotherShareFromDefault", false);
// forwarded by the second system
User officerUser = getUserService().getByReferenceDto(officer);
ShareRequestInfo shareFromSecond = createShareRequestInfo(officerUser, "shareFromSecond", false, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference())));
getShareRequestInfoService().persist(shareFromSecond);
// The share tree for the above code is:
// |- default
// |- second
// |- shareFromSecond
// |- another from default
mockSecondServerAccess();
// mock share tree on the case creator system
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(DEFAULT_SERVER_ID), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
List<SormasToSormasShareTree> shareTrees = new ArrayList<>();
shareTrees.add(new SormasToSormasShareTree(null, shareToSecond, Collections.emptyList(), false));
shareTrees.add(new SormasToSormasShareTree(null, anotherShareFromDefault, Collections.emptyList(), false));
return encryptShareData(shareTrees);
});
// Mock shares from "anotherShareFromDefault" -> no more shares
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("anotherShareFromDefault"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
// Mock shares from "shareFromSecond" server -> no more shares
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("shareFromSecond"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
List<SormasToSormasShareTree> shares = getSormasToSormasCaseFacade().getAllShares(caze.getUuid());
assertThat(shares, hasSize(2));
SormasToSormasShareInfoDto fistShare = shares.get(0).getShare();
assertThat(fistShare.getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(fistShare.isOwnershipHandedOver(), is(true));
List<SormasToSormasShareTree> reShares = shares.get(0).getReShares();
assertThat(reShares, hasSize(1));
SormasToSormasShareInfoDto reShare = reShares.get(0).getShare();
assertThat(reShare.getTargetDescriptor().getId(), is("shareFromSecond"));
assertThat(reShare.isOwnershipHandedOver(), is(false));
assertThat(reShares.get(0).getReShares(), hasSize(0));
SormasToSormasShareTree secondReShareFromDefault = shares.get(1);
assertThat(secondReShareFromDefault.getShare().getTargetDescriptor().getId(), is("anotherShareFromDefault"));
assertThat(secondReShareFromDefault.getShare().isOwnershipHandedOver(), is(false));
assertThat(secondReShareFromDefault.getReShares(), hasSize(0));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCase.
@Test
public void testSaveReturnedCase() throws SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(officer, person.toReference(), rdcf);
PersonDto sharedContactPerson = creator.createPerson();
ContactDto sharedContact = creator.createContact(officer, sharedContactPerson.toReference(), caze);
PersonDto newContactPerson = creator.createPerson();
ContactDto newContact = createContactRemoteContact(officer, newContactPerson.toReference(), caze);
ContactDto newContact2 = createContactRemoteContact(officer, newContactPerson.toReference(), caze);
SampleDto sharedSample = creator.createSample(caze.toReference(), officer, rdcf.facility);
SampleDto newSample = createRemoteSample(caze.toReference(), officer, rdcf.facility);
SampleDto newSample2 = createRemoteSample(caze.toReference(), officer, rdcf.facility);
User officerUser = getUserService().getByReferenceDto(officer);
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setContact(getContactService().getByReferenceDto(sharedContact.toReference()))));
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setSample(getSampleService().getByReferenceDto(sharedSample.toReference()))));
caze.setQuarantine(QuarantineType.HOTEL);
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)));
shareData.setContacts(Arrays.asList(new SormasToSormasContactDto(sharedContactPerson, sharedContact), new SormasToSormasContactDto(newContactPerson, newContact), new SormasToSormasContactDto(newContactPerson, newContact2)));
shareData.setSamples(Arrays.asList(new SormasToSormasSampleDto(sharedSample, Collections.emptyList(), Collections.emptyList()), new SormasToSormasSampleDto(newSample, Collections.emptyList(), Collections.emptyList()), new SormasToSormasSampleDto(newSample2, Collections.emptyList(), Collections.emptyList())));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
try {
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
} catch (Exception e) {
e.printStackTrace();
}
CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(returnedCase.getQuarantine(), is(QuarantineType.HOTEL));
assertThat(returnedCase.getReportingUser(), is(officer));
List<SormasToSormasShareInfoDto> caseShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().caze(caze.toReference()), 0, 100);
assertThat(caseShares.get(0).isOwnershipHandedOver(), is(false));
List<SormasToSormasShareInfoDto> contactShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().contact(sharedContact.toReference()), 0, 100);
assertThat(contactShares.get(0).isOwnershipHandedOver(), is(false));
ContactDto returnedNewContact = getContactFacade().getByUuid(newContact.getUuid());
assertThat(returnedNewContact.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
ContactDto returnedNewContact2 = getContactFacade().getByUuid(newContact.getUuid());
assertThat(returnedNewContact2.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
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));
SampleDto returnedNewSample2 = getSampleFacade().getSampleByUuid(newSample.getUuid());
assertThat(returnedNewSample2.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSaveSyncedEvent.
@Test
public void testSaveSyncedEvent() throws SormasToSormasException, SormasToSormasValidationException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", officer, e -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(false);
e.setSormasToSormasOriginInfo(originInfo);
});
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson(), "Involved", officer, (ep) -> ep.setSormasToSormasOriginInfo(event.getSormasToSormasOriginInfo()), null);
EventParticipantDto newEventParticipant = createEventParticipantDto(event.toReference(), UserDto.build().toReference(), rdcf);
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, false));
shareData.setEvents(Collections.singletonList(new SormasToSormasEventDto(event)));
shareData.setEventParticipants(Arrays.asList(new SormasToSormasEventParticipantDto(eventParticipant), new SormasToSormasEventParticipantDto(newEventParticipant)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(new SyncDataDto(shareData, new ShareTreeCriteria(event.getUuid(), null, false)));
getSormasToSormasEventFacade().saveSyncedEntity(encryptedData);
EventDto syncedEvent = getEventFacade().getEventByUuid(event.getUuid(), false);
assertThat(syncedEvent.getEventDesc(), is("Test updated description"));
assertThat(syncedEvent.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
EventParticipantDto syncedEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(eventParticipant.getUuid());
assertThat(syncedEventParticipant.getPerson().getBirthName(), is("Test birth name"));
assertThat(syncedEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
EventParticipantDto returnedNewEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(newEventParticipant.getUuid());
assertThat(returnedNewEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
}
Aggregations