Search in sources :

Example 1 with SormasToSormasShareTree

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());
}
Also used : ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree)

Example 2 with SormasToSormasShareTree

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));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) User(de.symeda.sormas.backend.user.User) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 3 with SormasToSormasShareTree

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;
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) PaginationList(de.symeda.sormas.ui.utils.PaginationList) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) Date(java.util.Date) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) VerticalLayout(com.vaadin.ui.VerticalLayout) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) LoggerFactory(org.slf4j.LoggerFactory) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CssStyles(de.symeda.sormas.ui.utils.CssStyles) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) Logger(org.slf4j.Logger) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) UserDto(de.symeda.sormas.api.user.UserDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) Consumer(java.util.function.Consumer) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) SampleDto(de.symeda.sormas.api.sample.SampleDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ContactDto(de.symeda.sormas.api.contact.ContactDto) Optional(java.util.Optional) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree)

Example 4 with SormasToSormasShareTree

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;
}
Also used : SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) ArrayList(java.util.ArrayList) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree)

Example 5 with SormasToSormasShareTree

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();
}
Also used : SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) FeatureType(de.symeda.sormas.api.feature.FeatureType) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) PaginationList(de.symeda.sormas.ui.utils.PaginationList) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) Date(java.util.Date) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) VerticalLayout(com.vaadin.ui.VerticalLayout) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) LoggerFactory(org.slf4j.LoggerFactory) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CssStyles(de.symeda.sormas.ui.utils.CssStyles) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) Logger(org.slf4j.Logger) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) UserDto(de.symeda.sormas.api.user.UserDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) Consumer(java.util.function.Consumer) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) SampleDto(de.symeda.sormas.api.sample.SampleDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ContactDto(de.symeda.sormas.api.contact.ContactDto) Optional(java.util.Optional) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) UserDto(de.symeda.sormas.api.user.UserDto) Label(com.vaadin.ui.Label) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) UI(com.vaadin.ui.UI) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Aggregations

SormasToSormasShareTree (de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree)7 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)5 SormasToSormasShareInfoDto (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto)5 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)4 ShareTreeCriteria (de.symeda.sormas.api.sormastosormas.ShareTreeCriteria)3 SormasToSormasOriginInfoDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)3 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)3 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)3 ShareRequestInfo (de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo)3 User (de.symeda.sormas.backend.user.User)3 VaadinIcons (com.vaadin.icons.VaadinIcons)2 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)2 Alignment (com.vaadin.ui.Alignment)2 Button (com.vaadin.ui.Button)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 UI (com.vaadin.ui.UI)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ValoTheme (com.vaadin.ui.themes.ValoTheme)2 FacadeProvider (de.symeda.sormas.api.FacadeProvider)2