use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testReturnEvent.
@Test
public void testReturnEvent() 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);
e.setSormasToSormasOriginInfo(originInfo);
});
SormasToSormasShareRequestDto shareRequest = new SormasToSormasShareRequestDto();
shareRequest.setUuid(DataHelper.createUuid());
shareRequest.setOriginInfo(event.getSormasToSormasOriginInfo());
getSormasToSormasShareRequestFacade().saveShareRequest(shareRequest);
PersonDto person = creator.createPerson();
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), person, "Involved", officer, (p) -> p.setSormasToSormasOriginInfo(event.getSormasToSormasOriginInfo()), null);
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
options.setHandOverOwnership(true);
options.setWithEventParticipants(true);
options.setComment("Test comment");
Mockito.when(MockProducer.getSormasToSormasClient().post(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> Response.noContent().build());
getSormasToSormasEventFacade().share(Collections.singletonList(event.getUuid()), options);
// event ownership should be lost
EventDto sharedEvent = getEventFacade().getEventByUuid(event.getUuid(), false);
assertThat(sharedEvent.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
// sample ownership should be lost
EventParticipantDto sharedEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(eventParticipant.getUuid());
assertThat(sharedEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSyncRecursively.
@Test
public void testSyncRecursively() 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.setWithEventParticipants(true);
originInfo.setOwnershipHandedOver(false);
e.setSormasToSormasOriginInfo(originInfo);
});
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson(), "Involved", officer, (ep) -> ep.setSormasToSormasOriginInfo(event.getSormasToSormasOriginInfo()), 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 = 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();
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false);
originInfo.setWithEventParticipants(true);
shareData.setOriginInfo(originInfo);
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)));
Mockito.when(MockProducer.getManagedScheduledExecutorService().schedule(ArgumentMatchers.any(Runnable.class), ArgumentMatchers.anyLong(), ArgumentMatchers.any())).then(invocation -> {
((Runnable) invocation.getArgument(0)).run();
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
return null;
});
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(SECOND_SERVER_ID));
assertThat(syncData.getCriteria().isForwardOnly(), is(false));
assertThat(syncData.getShareData().getEvents().get(0).getEntity().getUuid(), is(event.getUuid()));
assertThat(syncData.getShareData().getEventParticipants(), hasSize(2));
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()));
assertThat(syncData.getShareData().getEventParticipants(), hasSize(1));
return Response.noContent().build();
});
getSormasToSormasEventFacade().saveSyncedEntity(encryptedData);
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method sendShareRequest.
/**
* Send a S2S share request for the ADOs identified by the given UUIDs to a remote S2S instance specified by options.
*
* @param entityUuids
* The entities for which should be delivered to the remote as preview.
* @param options
* S2S request options also including the receiver.
* @throws SormasToSormasException
* Errors out in case validation fails or request cannot be sent.
*/
private void sendShareRequest(List<String> entityUuids, SormasToSormasOptionsDto options) throws SormasToSormasException {
User currentUser = userService.getCurrentUser();
List<ADO> entities = getEntityService().getByUuids(entityUuids);
if (options.isHandOverOwnership()) {
validateOwnership(entities);
ensureConsistentOptions(options);
}
validateEntitiesBeforeShare(entities, options.isHandOverOwnership());
String requestUuid = DataHelper.createUuid();
ShareRequestInfo shareRequestInfo = createShareRequestInfoForEntities(requestUuid, ShareRequestStatus.PENDING, options, entities, currentUser, false);
ShareRequestPreviews previewsToSend = shareDataBuilder.buildShareDataPreview(shareRequestInfo);
SormasToSormasOriginInfoDto originInfo = dataBuilderHelper.createSormasToSormasOriginInfo(currentUser, options);
sormasToSormasRestClient.post(options.getOrganization().getId(), requestEndpoint, new ShareRequestData(requestUuid, previewsToSend, originInfo), null);
// remove shares to the origin
shareRequestInfoService.ensurePersisted(shareRequestInfo);
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class ReceivedEntitiesProcessor method processReceivedData.
public List<ValidationErrors> processReceivedData(SormasToSormasDto receivedData, ShareDataExistingEntities existingEntities) {
List<ValidationErrors> validationErrors = new ArrayList<>();
SormasToSormasOriginInfoDto originInfo = receivedData.getOriginInfo();
originInfo.setUuid(DataHelper.createUuid());
originInfo.setChangeDate(new Date());
ValidationErrors originInfoErrors = validateOriginInfo(originInfo, Captions.sormasToSormasOriginInfo);
if (originInfoErrors.hasError()) {
validationErrors.add(originInfoErrors);
}
List<SormasToSormasCaseDto> cases = receivedData.getCases();
if (CollectionUtils.isNotEmpty(cases)) {
cases.forEach(c -> {
ValidationErrors caseErrors = caseProcessor.processReceivedData(c, existingEntities.getCases().get(c.getEntity().getUuid()));
if (caseErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildCaseValidationGroupName(c.getEntity()), caseErrors));
}
});
}
List<SormasToSormasContactDto> contacts = receivedData.getContacts();
if (CollectionUtils.isNotEmpty(contacts)) {
contacts.forEach(c -> {
ValidationErrors contactErrors = contactProcessor.processReceivedData(c, existingEntities.getContacts().get(c.getEntity().getUuid()));
if (contactErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildContactValidationGroupName(c.getEntity()), contactErrors));
}
});
}
List<SormasToSormasEventDto> events = receivedData.getEvents();
if (CollectionUtils.isNotEmpty(events)) {
events.forEach(e -> {
ValidationErrors eventErrors = eventProcessor.processReceivedData(e, existingEntities.getEvents().get(e.getEntity().getUuid()));
if (eventErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildEventValidationGroupName(e.getEntity()), eventErrors));
}
});
}
List<SormasToSormasEventParticipantDto> eventParticipants = receivedData.getEventParticipants();
if (CollectionUtils.isNotEmpty(eventParticipants)) {
eventParticipants.forEach(ep -> {
ValidationErrors eventParticipantErrors = eventParticipantProcessor.processReceivedData(ep, existingEntities.getEventParticipants().get(ep.getEntity().getUuid()));
if (eventParticipantErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildEventParticipantValidationGroupName(ep.getEntity()), eventParticipantErrors));
}
});
}
List<SormasToSormasSampleDto> samples = receivedData.getSamples();
if (CollectionUtils.isNotEmpty(samples)) {
samples.forEach(s -> {
ValidationErrors contactErrors = sampleProcessor.processReceivedData(s, existingEntities.getSamples().get(s.getEntity().getUuid()));
if (contactErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildSampleValidationGroupName(s.getEntity()), contactErrors));
}
});
}
List<SormasToSormasImmunizationDto> immunizations = receivedData.getImmunizations();
if (CollectionUtils.isNotEmpty(immunizations)) {
immunizations.forEach(s -> {
ValidationErrors immunizationErrors = immunizationProcessor.processReceivedData(s, existingEntities.getImmunizations().get(s.getEntity().getUuid()));
if (immunizationErrors.hasError()) {
validationErrors.add(new ValidationErrors(ValidationHelper.buildImmunizationValidationGroupName(s.getEntity()), immunizationErrors));
}
});
}
return validationErrors;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasListComponent method reloadList.
public void reloadList() {
UI currentUI = UI.getCurrent();
UserDto currentUser = FacadeProvider.getUserFacade().getCurrentUser();
sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.sormasToSormasLoadingShares));
Thread loadSharesThread = new Thread(() -> {
try {
I18nProperties.setUserLanguage(currentUser.getLanguage());
FacadeProvider.getI18nFacade().setUserLanguage(currentUser.getLanguage());
currentUI.setPollInterval(300);
List<SormasToSormasShareTree> shareInfos = loadShares.load();
String currentServerOrgId = FacadeProvider.getSormasToSormasFacade().getOrganizationId();
List<SormasToSormasShareInfoDto> shareInfoList = getShareInfoList(shareInfos);
SormasToSormasShareInfoDto ownerShare = getOwnerShare(shareInfos);
SormasToSormasOriginInfoDto rootOrigin = findRootOriginInfo(shareInfos);
List<String> directShareUuids = getDirectShares(shareInfos).stream().map(s -> s.getShare().getUuid()).collect(Collectors.toList());
String ownerOrganizationId = getOwnerOrganizationId(ownerShare, rootOrigin, currentServerOrgId);
boolean isOwnedByCurrentOrg = currentServerOrgId.equals(ownerOrganizationId);
boolean isOwnedByOrigin = originInfo != null && originInfo.getOrganizationId().equals(ownerOrganizationId);
boolean isOwnedByRootOrg = rootOrigin != null && rootOrigin.getOrganizationId().equals(ownerOrganizationId);
currentUI.access(() -> {
try {
// render origin
if (originInfo != null) {
HorizontalLayout originLayout = buildSormasOriginInfo(originInfo, isOwnedByOrigin);
originLayout.addStyleName(CssStyles.VSPACE_3);
addComponent(originLayout, getComponentIndex(sormasToSormasList));
}
// render the owner of the entity
if (!isOwnedByCurrentOrg && !isOwnedByOrigin) {
AbstractOrderedLayout ownerLayout = null;
if (isOwnedByRootOrg) {
ownerLayout = buildSormasOriginInfo(rootOrigin, true);
} else if (ownerShare != null && !ownerShare.getTargetDescriptor().getId().equals(currentServerOrgId)) {
ownerLayout = buildOwnerShareLayout(ownerShare);
}
if (ownerLayout != null) {
ownerLayout.addStyleName(CssStyles.VSPACE_3);
addComponent(ownerLayout, getComponentIndex(sormasToSormasList));
}
}
// show shares to other systems then owner and current one
List<SormasToSormasShareListEntryData> listData = shareInfoList.stream().filter(s -> {
String shareOrganizationId = s.getTargetDescriptor().getId();
if (ownerShare != null && shareOrganizationId.equals(ownerShare.getTargetDescriptor().getId())) {
return false;
}
if (originInfo != null && shareOrganizationId.equals(originInfo.getOrganizationId()) && // show return share
!(s.getRequestStatus() == ShareRequestStatus.PENDING && directShareUuids.contains(s.getUuid()))) {
return false;
}
if (isOwnedByRootOrg && shareOrganizationId.equals(rootOrigin.getOrganizationId())) {
return false;
}
return !shareOrganizationId.equals(currentServerOrgId);
}).map(s -> {
SormasToSormasShareListEntryData entryData = new SormasToSormasShareListEntryData();
entryData.shareUuid = s.getUuid();
entryData.target = s.getTargetDescriptor().getName();
entryData.sender = s.getSender().getShortCaption();
entryData.status = s.getRequestStatus();
entryData.creationDate = s.getCreationDate();
entryData.comment = s.getComment();
entryData.ownershipHandedOver = s.isOwnershipHandedOver();
entryData.responseComment = s.getResponseComment();
entryData.isDirectShare = directShareUuids.contains(s.getUuid());
return entryData;
}).collect(Collectors.toList());
// add the creator of the entity as a share
if (!isOwnedByRootOrg && rootOrigin != null && originInfo != null && !rootOrigin.getOrganizationId().equals(currentServerOrgId) && !rootOrigin.getOrganizationId().equals(originInfo.getOrganizationId())) {
SormasServerDescriptor serverDescriptor = FacadeProvider.getSormasToSormasFacade().getSormasServerDescriptorById(rootOrigin.getOrganizationId());
SormasToSormasShareListEntryData entryData = new SormasToSormasShareListEntryData();
entryData.shareUuid = null;
entryData.target = serverDescriptor.getName();
entryData.sender = rootOrigin.getSenderName();
entryData.status = ShareRequestStatus.ACCEPTED;
entryData.creationDate = rootOrigin.getCreationDate();
entryData.comment = rootOrigin.getComment();
entryData.ownershipHandedOver = rootOrigin.isOwnershipHandedOver();
listData.add(entryData);
}
if (shareInfoList.size() > 0) {
if (listData.size() > 0) {
Label shareListLabel = new Label(I18nProperties.getCaption(Captions.sormasToSormasSharedWith));
shareListLabel.addStyleNames(CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
addComponent(shareListLabel, getComponentIndex(sormasToSormasList));
sormasToSormasList.setData(listData);
} else {
sormasToSormasList.setVisible(false);
}
} else {
sormasToSormasList.showPlaceholder(null);
}
} catch (Exception e) {
logger.error("Failed to load shares", e);
sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.errorSormasToSormasLoadShares));
} finally {
currentUI.setPollInterval(-1);
}
});
} catch (Exception e) {
logger.error(e.getMessage(), e);
currentUI.setPollInterval(-1);
currentUI.access(() -> {
sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.errorSormasToSormasLoadShares));
});
}
});
loadSharesThread.start();
}
Aggregations