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);
}
}
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);
}
}
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);
}
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;
}
Aggregations