use of de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjb method getOrCreateShareInfos.
@Override
protected List<SormasToSormasShareInfo> getOrCreateShareInfos(Event event, SormasToSormasOptionsDto options, User user, boolean forSync) {
String organizationId = options.getOrganization().getId();
SormasToSormasShareInfo eventShareInfo = event.getSormasToSormasShares().stream().filter(s -> s.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> ShareInfoHelper.createShareInfo(organizationId, event, SormasToSormasShareInfo::setEvent, options));
Stream<SormasToSormasShareInfo> eventParticipantShareInfos = Stream.empty();
List<EventParticipant> eventParticipants = Collections.emptyList();
if (options.isWithEventParticipants()) {
eventParticipants = eventParticipantService.getAllActiveByEvent(event);
eventParticipantShareInfos = eventParticipants.stream().map(ep -> ep.getSormasToSormasShares().stream().filter(share -> share.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> {
if (forSync) {
// do not share new event participants on sync
return ep.getSormasToSormasOriginInfo() != null && ep.getSormasToSormasOriginInfo().getOrganizationId().equals(organizationId) ? ShareInfoHelper.createShareInfo(organizationId, ep, SormasToSormasShareInfo::setEventParticipant, options) : null;
} else {
return ShareInfoHelper.createShareInfo(organizationId, ep, SormasToSormasShareInfo::setEventParticipant, options);
}
})).filter(Objects::nonNull);
}
Stream<SormasToSormasShareInfo> sampleShareInfos = Stream.empty();
Stream<SormasToSormasShareInfo> immunizationShareInfos = Stream.empty();
if (eventParticipants.size() > 0) {
if (options.isWithSamples()) {
List<String> eventParticipantUuids = eventParticipants.stream().map(EventParticipant::getUuid).collect(Collectors.toList());
sampleShareInfos = sampleService.getByEventParticipantUuids(eventParticipantUuids).stream().map(s -> s.getSormasToSormasShares().stream().filter(share -> share.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> ShareInfoHelper.createShareInfo(organizationId, s, SormasToSormasShareInfo::setSample, options)));
}
if (options.isWithImmunizations()) {
immunizationShareInfos = getAssociatedImmunizations(eventParticipants).stream().map(i -> i.getSormasToSormasShares().stream().filter(share -> share.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> ShareInfoHelper.createShareInfo(organizationId, i, SormasToSormasShareInfo::setImmunization, options)));
}
}
return Stream.of(Stream.of(eventShareInfo), eventParticipantShareInfos, sampleShareInfos, immunizationShareInfos).flatMap(Function.identity()).collect(Collectors.toList());
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method syncEntityToOrigin.
private void syncEntityToOrigin(ADO entity, SormasToSormasOriginInfo originInfo, ShareTreeCriteria criteria) throws SormasToSormasException {
User currentUser = userService.getCurrentUser();
SormasToSormasOptionsDto options = dataBuilderHelper.createOptionsFromOriginInfoDto(originInfo);
options.setHandOverOwnership(false);
ShareRequestInfo shareRequestInfo = createShareRequestInfoForEntities(DataHelper.createUuid(), ShareRequestStatus.ACCEPTED, options, Collections.singletonList(entity), currentUser, true);
SormasToSormasDto shareData = shareDataBuilder.buildShareData(shareRequestInfo.getShares(), dataBuilderHelper.createSormasToSormasOriginInfo(currentUser, options), shareRequestInfo);
sormasToSormasRestClient.post(originInfo.getOrganizationId(), syncEndpoint, new SyncDataDto(shareData, criteria), null);
// remove existing shares from the request info
shareRequestInfo.setShares(shareRequestInfo.getShares().stream().filter(s -> s.getId() == null).collect(Collectors.toList()));
if (!shareRequestInfo.getShares().isEmpty()) {
shareRequestInfoService.ensurePersisted(shareRequestInfo);
}
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto in project SORMAS-Project by hzi-braunschweig.
the class ShareDataBuilderHelper method createOptionsFromOriginInfoDto.
public SormasToSormasOptionsDto createOptionsFromOriginInfoDto(SormasToSormasOriginInfo originInfo) {
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(originInfo.getOrganizationId()));
options.setHandOverOwnership(originInfo.isOwnershipHandedOver());
options.setWithAssociatedContacts(originInfo.isWithAssociatedContacts());
options.setWithSamples(originInfo.isWithSamples());
options.setWithEventParticipants(originInfo.isWithEventParticipants());
options.setComment(originInfo.getComment());
return options;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto 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.SormasToSormasOptionsDto 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