use of de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasListComponent method getOwnerShare.
private SormasToSormasShareInfoDto getOwnerShare(List<SormasToSormasShareTree> shareInfos) {
Optional<SormasToSormasShareTree> sharedWithOwnership = shareInfos.stream().filter(s -> {
SormasToSormasShareInfoDto share = s.getShare();
return share.getRequestStatus() == ShareRequestStatus.ACCEPTED && share.isOwnershipHandedOver();
}).findFirst();
if (sharedWithOwnership.isPresent()) {
SormasToSormasShareTree ownerTree = sharedWithOwnership.get();
SormasToSormasShareInfoDto ownerShare = getOwnerShare(ownerTree.getReShares());
return ownerShare == null ? ownerTree.getShare() : ownerShare;
}
return null;
}
use of de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto 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.shareinfo.SormasToSormasShareInfoDto 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.shareinfo.SormasToSormasShareInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSyncEvent.
@Test
public void testSyncEvent() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", officer, e -> {
e.getEventLocation().setRegion(rdcf.region);
e.getEventLocation().setDistrict(rdcf.district);
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
originInfo.setWithEventParticipants(true);
e.setSormasToSormasOriginInfo(originInfo);
});
PersonDto person = creator.createPerson();
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), person, "Involved", officer, ep -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
originInfo.setWithEventParticipants(true);
ep.setSormasToSormasOriginInfo(originInfo);
}, null);
ShareRequestInfo shareRequestInfo = createShareRequestInfo(getUserService().getByUuid(officer.getUuid()), SECOND_SERVER_ID, false, ShareRequestStatus.ACCEPTED, i -> i.setEvent(getEventService().getByUuid(event.getUuid())));
shareRequestInfo.setWithEventParticipants(true);
shareRequestInfo.getShares().add(createShareInfo(SECOND_SERVER_ID, false, i -> i.setEventParticipant(getEventParticipantService().getByUuid(eventParticipant.getUuid()))));
getShareRequestInfoService().persist(shareRequestInfo);
EventParticipantDto newEventParticipant = creator.createEventParticipant(event.toReference(), person, "Involved", officer);
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(event.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(DEFAULT_SERVER_ID));
assertThat(syncData.getCriteria().isForwardOnly(), is(false));
assertThat(syncData.getShareData().getEvents().get(0).getEntity().getUuid(), is(event.getUuid()));
// new event participant should not be shared
assertThat(syncData.getShareData().getEventParticipants(), hasSize(1));
return Response.noContent().build();
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(event.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(nullValue()));
assertThat(syncData.getCriteria().isForwardOnly(), is(true));
assertThat(syncData.getShareData().getEvents().get(0).getEntity().getUuid(), is(event.getUuid()));
// the new event participant should not be shared
assertThat(syncData.getShareData().getEventParticipants(), hasSize(1));
assertThat(syncData.getShareData().getEventParticipants().get(0).getEntity().getUuid(), is(eventParticipant.getUuid()));
return Response.noContent().build();
});
getSormasToSormasEventFacade().syncShares(new ShareTreeCriteria(event.getUuid(), null, false));
// new event participant should have share info with ownership handed over
List<SormasToSormasShareInfoDto> newEventParticipantShareInfoList = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().eventParticipant(newEventParticipant.toReference()), 0, 100);
assertThat(newEventParticipantShareInfoList, hasSize(0));
}
use of de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testShareEventWithSamples.
@Test
public void testShareEventWithSamples() throws SormasToSormasException {
UserDto user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
useSurveillanceOfficerLogin(rdcf);
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", user.toReference(), (e) -> {
e.getEventLocation().setRegion(rdcf.region);
e.getEventLocation().setDistrict(rdcf.district);
});
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson("John", "Doe", p -> p.setBirthName("Test birth name")), "Involved", user.toReference(), (ep) -> {
ep.setRegion(rdcf.region);
ep.setDistrict(rdcf.district);
ep.setVaccinationStatus(VaccinationStatus.VACCINATED);
}, null);
SampleDto sample = creator.createSample(eventParticipant.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
creator.createPathogenTest(sample.toReference(), PathogenTestType.CULTURE, Disease.CORONAVIRUS, new Date(), rdcf.facility, user.toReference(), PathogenTestResultType.INDETERMINATE, "Test result", true, null);
creator.createAdditionalTest(sample.toReference());
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
options.setWithEventParticipants(true);
options.setWithSamples(true);
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/events"));
SormasToSormasDto postBody = invocation.getArgument(2, SormasToSormasDto.class);
assertThat(postBody.getEvents().size(), is(1));
List<SormasToSormasEventParticipantDto> eventParticipants = postBody.getEventParticipants();
assertThat(eventParticipants, hasSize(1));
List<SormasToSormasSampleDto> samples = postBody.getSamples();
assertThat(samples, hasSize(1));
assertThat(samples.get(0).getPathogenTests(), hasSize(1));
assertThat(samples.get(0).getAdditionalTests(), hasSize(1));
return Response.noContent().build();
});
getSormasToSormasEventFacade().share(Collections.singletonList(event.getUuid()), options);
List<SormasToSormasShareInfoDto> shareInfoList = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().event(event.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"));
}
Aggregations