Search in sources :

Example 1 with SormasToSormasOriginInfo

use of de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo in project SORMAS-Project by hzi-braunschweig.

the class AbstractSormasToSormasInterface method shareEntities.

private void shareEntities(List<String> entityUuids, SormasToSormasOptionsDto options) throws SormasToSormasException {
    User currentUser = userService.getCurrentUser();
    List<ADO> entities = getEntityService().getByUuids(entityUuids);
    validateEntitiesBeforeShare(entities, options.isHandOverOwnership());
    ensureConsistentOptions(options);
    String requestUuid = DataHelper.createUuid();
    ShareRequestInfo requestInfo = createShareRequestInfoForEntities(requestUuid, ShareRequestStatus.ACCEPTED, options, entities, currentUser, false);
    SormasToSormasDto dataToSend = shareDataBuilder.buildShareDataForRequest(requestInfo, currentUser);
    sormasToSormasRestClient.post(options.getOrganization().getId(), saveEndpoint, dataToSend, null);
    shareRequestInfoService.ensurePersisted(requestInfo);
    entities.forEach(e -> {
        SormasToSormasOriginInfo entityOriginInfo = e.getSormasToSormasOriginInfo();
        if (entityOriginInfo != null) {
            entityOriginInfo.setOwnershipHandedOver(!options.isHandOverOwnership());
            originInfoService.ensurePersisted(entityOriginInfo);
        }
    });
    try {
        shareInfoService.handleOwnershipChangeInExternalSurvTool(requestInfo);
    } catch (ExternalSurveillanceToolException e) {
        LOGGER.error("Failed to delete shared entities in external surveillance tool", e);
        throw SormasToSormasException.fromStringPropertyWithWarning(Strings.errorSormasToSormasDeleteFromExternalSurveillanceTool);
    }
}
Also used : User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)

Example 2 with SormasToSormasOriginInfo

use of de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo in project SORMAS-Project by hzi-braunschweig.

the class AbstractSormasToSormasInterface method walkShareTree.

private void walkShareTree(ShareTreeCriteria criteria, WalkParent<ADO> walkParent, WalkReShare<ADO> walkReShare) {
    ADO entity = getEntityService().getByUuid(criteria.getEntityUuid());
    if (entity == null) {
        return;
    }
    SormasToSormasOriginInfo originInfo = entity.getSormasToSormasOriginInfo();
    List<SormasToSormasShareInfo> entityShares = entity.getSormasToSormasShares();
    if (!criteria.isForwardOnly() && originInfo != null && !originInfo.getOrganizationId().equals(criteria.getExceptedOrganizationId())) {
        SormasToSormasShareRequest shareRequest = originInfo.getRequest();
        String ownOrganizationId = configFacadeEjb.getS2SConfig().getId();
        if (shareRequest == null || shareRequest.getStatus() == ShareRequestStatus.ACCEPTED) {
            walkParent.walk(entity, originInfo, new ShareTreeCriteria(criteria.getEntityUuid(), ownOrganizationId, false));
        }
    }
    for (SormasToSormasShareInfo s : entityShares) {
        boolean notAccepted = s.getRequests().stream().noneMatch(r -> r.getRequestStatus() == ShareRequestStatus.ACCEPTED);
        boolean noForward = notAccepted || s.getOrganizationId().equals(criteria.getExceptedOrganizationId());
        if (originInfo != null) {
            noForward = noForward || s.getOrganizationId().equals(originInfo.getOrganizationId());
        }
        walkReShare.walk(entity, s, new ShareTreeCriteria(criteria.getEntityUuid(), criteria.getExceptedOrganizationId(), true), noForward);
    }
}
Also used : ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) SormasToSormasShareRequest(de.symeda.sormas.backend.sormastosormas.share.sharerequest.SormasToSormasShareRequest) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo)

Example 3 with SormasToSormasOriginInfo

use of de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method getUuidsNotShareableWithExternalReportingTools.

@Override
public List<String> getUuidsNotShareableWithExternalReportingTools(List<String> caseUuids) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<String> cq = cb.createQuery(String.class);
    Root<Case> caseRoot = cq.from(Case.class);
    Join<Case, SormasToSormasOriginInfo> originInfoJoin = caseRoot.join(Case.SORMAS_TO_SORMAS_ORIGIN_INFO, JoinType.LEFT);
    Join<Case, SormasToSormasShareInfo> shareInfoJoin = caseRoot.join(Case.SORMAS_TO_SORMAS_SHARES, JoinType.LEFT);
    cq.select(caseRoot.get(Case.UUID));
    cq.where(cb.and(cb.or(cb.isFalse(originInfoJoin.get(SormasToSormasOriginInfo.OWNERSHIP_HANDED_OVER)), cb.isTrue(shareInfoJoin.get(SormasToSormasShareInfo.OWNERSHIP_HANDED_OVER)), cb.isTrue(caseRoot.get(Case.DONT_SHARE_WITH_REPORTING_TOOL))), caseRoot.get(Case.UUID).in(caseUuids)));
    cq.orderBy(cb.asc(caseRoot.get(AbstractDomainObject.CREATION_DATE)));
    return QueryHelper.getResultList(em, cq, null, null);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo)

Example 4 with SormasToSormasOriginInfo

use of de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasShareRequestFacadeEJB method getIndexList.

@Override
public List<SormasToSormasShareRequestIndexDto> getIndexList(ShareRequestCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<SormasToSormasShareRequestIndexDto> cq = cb.createQuery(SormasToSormasShareRequestIndexDto.class);
    Root<SormasToSormasShareRequest> requestRoot = cq.from(SormasToSormasShareRequest.class);
    Path<SormasToSormasOriginInfo> originInfo = requestRoot.get(SormasToSormasShareRequest.ORIGIN_INFO);
    cq.multiselect(requestRoot.get(SormasToSormasShareRequest.UUID), requestRoot.get(SormasToSormasShareRequest.CREATION_DATE), requestRoot.get(SormasToSormasShareRequest.DATA_TYPE), requestRoot.get(SormasToSormasShareRequest.STATUS), originInfo.get(SormasToSormasOriginInfo.ORGANIZATION_ID), originInfo.get(SormasToSormasOriginInfo.SENDER_NAME), originInfo.get(SormasToSormasOriginInfo.OWNERSHIP_HANDED_OVER), originInfo.get(SormasToSormasOriginInfo.COMMENT));
    Predicate filter = null;
    if (criteria != null) {
        filter = shareRequestService.buildCriteriaFilter(criteria, cb, requestRoot);
    }
    if (filter != null) {
        cq.where(filter);
    }
    List<Order> order = new ArrayList<>();
    if (sortProperties != null && sortProperties.size() > 0) {
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case SormasToSormasShareRequest.UUID:
                case SormasToSormasShareRequest.CREATION_DATE:
                case SormasToSormasShareRequest.DATA_TYPE:
                case SormasToSormasShareRequest.STATUS:
                    expression = requestRoot.get(sortProperty.propertyName);
                    break;
                case SormasToSormasOriginInfo.ORGANIZATION_ID:
                case SormasToSormasOriginInfo.SENDER_NAME:
                case SormasToSormasOriginInfo.COMMENT:
                case SormasToSormasOriginInfo.OWNERSHIP_HANDED_OVER:
                    expression = originInfo.get(sortProperty.propertyName);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
    }
    cq.orderBy(order);
    List<SormasToSormasShareRequestIndexDto> requests = QueryHelper.getResultList(em, cq, first, max);
    if (!requests.isEmpty()) {
        Map<String, SormasServerDescriptor> serverDescriptorMap = sormasToSormasDiscoveryService.getAllAvailableServers().stream().collect(Collectors.toMap(SormasServerDescriptor::getId, Function.identity()));
        requests.forEach(request -> {
            String organizationId = request.getOrganizationId();
            SormasServerDescriptor serverDescriptor = serverDescriptorMap.get(organizationId);
            request.setOrganizationName(serverDescriptor != null ? serverDescriptor.getName() : organizationId);
        });
    }
    return requests;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) SormasToSormasShareRequestIndexDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestIndexDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo)

Aggregations

SormasToSormasOriginInfo (de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo)4 SormasToSormasShareInfo (de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 ExternalSurveillanceToolException (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)1 ShareTreeCriteria (de.symeda.sormas.api.sormastosormas.ShareTreeCriteria)1 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)1 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)1 SormasToSormasShareRequestIndexDto (de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestIndexDto)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1 ShareRequestInfo (de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo)1 SormasToSormasShareRequest (de.symeda.sormas.backend.sormastosormas.share.sharerequest.SormasToSormasShareRequest)1 User (de.symeda.sormas.backend.user.User)1 ArrayList (java.util.ArrayList)1 Order (javax.persistence.criteria.Order)1 Predicate (javax.persistence.criteria.Predicate)1