use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasOriginInfoFacadeEjb method toDto.
public static SormasToSormasOriginInfoDto toDto(SormasToSormasOriginInfo source) {
if (source == null) {
return null;
}
SormasToSormasOriginInfoDto target = new SormasToSormasOriginInfoDto();
DtoHelper.fillDto(target, source);
target.setOrganizationId(source.getOrganizationId());
target.setSenderName(source.getSenderName());
target.setSenderEmail(source.getSenderEmail());
target.setSenderPhoneNumber(source.getSenderPhoneNumber());
target.setOwnershipHandedOver(source.isOwnershipHandedOver());
target.setWithAssociatedContacts(source.isWithAssociatedContacts());
target.setWithSamples(source.isWithSamples());
target.setWithEventParticipants(source.isWithEventParticipants());
target.setWithImmunizations(source.isWithImmunizations());
target.setComment(source.getComment());
return target;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class ShareDataBuilderHelper method createSormasToSormasOriginInfo.
public SormasToSormasOriginInfoDto createSormasToSormasOriginInfo(User user, SormasToSormasOptionsDto options) {
SormasToSormasOriginInfoDto sormasToSormasOriginInfo = new SormasToSormasOriginInfoDto();
sormasToSormasOriginInfo.setOrganizationId(configFacadeEjb.getS2SConfig().getId());
sormasToSormasOriginInfo.setSenderName(String.format("%s %s", user.getFirstName(), user.getLastName()));
sormasToSormasOriginInfo.setSenderEmail(user.getUserEmail());
sormasToSormasOriginInfo.setSenderPhoneNumber(user.getPhone());
sormasToSormasOriginInfo.setOwnershipHandedOver(options.isHandOverOwnership());
sormasToSormasOriginInfo.setWithAssociatedContacts(options.isWithAssociatedContacts());
sormasToSormasOriginInfo.setWithSamples(options.isWithSamples());
sormasToSormasOriginInfo.setWithEventParticipants(options.isWithEventParticipants());
sormasToSormasOriginInfo.setWithImmunizations(options.isWithImmunizations());
sormasToSormasOriginInfo.setComment(options.getComment());
return sormasToSormasOriginInfo;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class ReceivedEntitiesProcessor method processReceivedRequest.
public List<ValidationErrors> processReceivedRequest(ShareRequestData shareData) {
List<ValidationErrors> validationErrors = new ArrayList<>();
SormasToSormasOriginInfoDto originInfo = shareData.getOriginInfo();
originInfo.setUuid(DataHelper.createUuid());
originInfo.setChangeDate(new Date());
ValidationErrors originInfoErrors = validateOriginInfo(originInfo, Captions.sormasToSormasOriginInfo);
if (originInfoErrors.hasError()) {
validationErrors.add(new ValidationErrors(new ValidationErrorGroup(Captions.sormasToSormasOriginInfo), originInfoErrors));
}
shareData.getPreviews().getCases().forEach(c -> {
ValidationErrors caseErrors = caseProcessor.processReceivedPreview(c);
if (caseErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildCaseValidationGroupName(c), caseErrors));
}
});
shareData.getPreviews().getContacts().forEach(c -> {
ValidationErrors contactErrors = contactProcessor.processReceivedPreview(c);
if (contactErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildContactValidationGroupName(c), contactErrors));
}
});
shareData.getPreviews().getEvents().forEach(e -> {
ValidationErrors eventErrors = eventProcessor.processReceivedPreview(e);
if (eventErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildEventValidationGroupName(e), eventErrors));
}
});
shareData.getPreviews().getEventParticipants().forEach(ep -> {
ValidationErrors eventParticipantErrors = eventParticipantProcessor.processReceivedPreview(ep);
if (eventParticipantErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildEventParticipantValidationGroupName(ep), eventParticipantErrors));
}
});
return validationErrors;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto 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.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasContactFacadeEjbTest method testReturnContact.
@Test
public void testReturnContact() 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(), 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.setOwnershipHandedOver(true);
c.setSormasToSormasOriginInfo(originInfo);
});
SormasToSormasShareRequestDto shareRequest = new SormasToSormasShareRequestDto();
shareRequest.setUuid(DataHelper.createUuid());
shareRequest.setOriginInfo(contact.getSormasToSormasOriginInfo());
getSormasToSormasShareRequestFacade().saveShareRequest(shareRequest);
SampleDto sharedSample = creator.createSample(contact.toReference(), officer, rdcf.facility, s -> s.setSormasToSormasOriginInfo(contact.getSormasToSormasOriginInfo()));
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
options.setHandOverOwnership(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());
getSormasToSormasContactFacade().share(Collections.singletonList(contact.getUuid()), options);
// contact ownership should be lost
ContactDto sharedContact = getContactFacade().getByUuid(contact.getUuid());
assertThat(sharedContact.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
// sample ownership should be lost
sharedSample = getSampleFacade().getSampleByUuid(sharedSample.getUuid());
assertThat(sharedSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
}
Aggregations