use of de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method getShareTrees.
@Override
public SormasToSormasEncryptedDataDto getShareTrees(SormasToSormasEncryptedDataDto encryptedCriteria) throws SormasToSormasException {
ShareTreeCriteria criteria = sormasToSormasEncryptionEjb.decryptAndVerify(encryptedCriteria, ShareTreeCriteria.class);
List<SormasToSormasShareTree> shares = getShareTrees(criteria, false);
return sormasToSormasEncryptionEjb.signAndEncrypt(shares, encryptedCriteria.getSenderId());
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testGetReShares.
@Test
public void testGetReShares() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
CaseDataDto caze = creator.createCase(officer, creator.createPerson().toReference(), rdcf);
User officerUser = getUserService().getByReferenceDto(officer);
ShareRequestInfo shareRequestInfo = createShareRequestInfo(officerUser, SECOND_SERVER_ID, true, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference())));
getShareRequestInfoService().persist(shareRequestInfo);
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
SormasToSormasShareInfoDto shareInfo = new SormasToSormasShareInfoDto();
shareInfo.setTargetDescriptor(new SormasServerDescriptor("dummy SORMAS"));
shareInfo.setOwnershipHandedOver(false);
shareInfo.setComment("re-shared");
return encryptShareDataAsArray(new SormasToSormasShareTree(null, shareInfo, Collections.emptyList(), false));
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("dummy SORMAS"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
mockS2Snetwork();
SormasToSormasEncryptedDataDto encryptedCriteria = encryptShareData(new ShareTreeCriteria(caze.getUuid(), null, false));
SormasToSormasEncryptedDataDto encryptedShares = getSormasToSormasCaseFacade().getShareTrees(encryptedCriteria);
mockDefaultServerAccess();
SormasToSormasShareTree[] shares = getSormasToSormasEncryptionFacade().decryptAndVerify(new SormasToSormasEncryptedDataDto(SECOND_SERVER_ID, encryptedShares.getData()), SormasToSormasShareTree[].class);
assertThat(shares, arrayWithSize(1));
assertThat(shares[0].getShare().getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(shares[0].getShare().isOwnershipHandedOver(), is(true));
assertThat(shares[0].getReShares().get(0).getShare().getTargetDescriptor().getId(), is("dummy SORMAS"));
assertThat(shares[0].getReShares().get(0).getShare().isOwnershipHandedOver(), is(false));
assertThat(shares[0].getReShares().get(0).getReShares(), hasSize(0));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree 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.SormasToSormasShareTree in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method getShareTrees.
private List<SormasToSormasShareTree> getShareTrees(ShareTreeCriteria criteria, boolean rootCall) {
String ownOrganizationId = configFacadeEjb.getS2SConfig().getId();
List<SormasToSormasShareTree> shares = new ArrayList<>();
List<SormasToSormasShareTree> reShareTrees = new ArrayList<>();
LOGGER.info("Get shares for {} from {} by {}", criteria.getEntityUuid(), ownOrganizationId, criteria.getOriginInfo() != null ? criteria.getOriginInfo().getOrganizationId() : ownOrganizationId);
walkShareTree(criteria, (entity, originInfo, parentCriteria) -> {
try {
SormasToSormasEncryptedDataDto encryptedShares = sormasToSormasRestClient.post(originInfo.getOrganizationId(), sharesEndpoint, parentCriteria, SormasToSormasEncryptedDataDto.class);
shares.addAll(Arrays.asList(sormasToSormasEncryptionEjb.decryptAndVerify(encryptedShares, SormasToSormasShareTree[].class)));
} catch (SormasToSormasException e) {
// stop iteration and fail in case of error
throw new RuntimeException("Failed to get all shares form server [" + originInfo.getOrganizationId() + "]", e);
}
}, (entity, shareInfo, reShareCriteria, noForward) -> {
try {
List<SormasToSormasShareTree> reShares = Collections.emptyList();
if (!noForward) {
SormasToSormasEncryptedDataDto encryptedShares = sormasToSormasRestClient.post(shareInfo.getOrganizationId(), sharesEndpoint, new ShareTreeCriteria(reShareCriteria.getEntityUuid(), reShareCriteria.getExceptedOrganizationId(), true), SormasToSormasEncryptedDataDto.class);
reShares = Arrays.asList(sormasToSormasEncryptionEjb.decryptAndVerify(encryptedShares, SormasToSormasShareTree[].class));
}
reShareTrees.add(new SormasToSormasShareTree(SormasToSormasOriginInfoFacadeEjb.toDto(entity.getSormasToSormasOriginInfo()), shareInfoFacade.toDto(shareInfo), reShares, rootCall));
} catch (SormasToSormasException e) {
// stop iteration and fail in case of error
throw new RuntimeException("Failed to get all shares form server [" + shareInfo.getOrganizationId() + "]", e);
}
});
SormasToSormasShareTree parentShare = findParentShare(shares, ownOrganizationId);
if (parentShare != null) {
parentShare.setReShares(reShareTrees);
} else {
shares.addAll(reShareTrees);
}
return shares;
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree 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