use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasFacadeEjb method revokeShare.
@Override
@Transactional(rollbackOn = Exception.class)
public void revokeShare(String shareInfoUuid) throws SormasToSormasException {
SormasToSormasShareInfo shareInfo = shareInfoService.getByUuid(shareInfoUuid);
List<ShareRequestInfo> pendingRequests = shareInfo.getRequests().stream().filter(r -> r.getRequestStatus() == ShareRequestStatus.PENDING).collect(Collectors.toList());
if (pendingRequests.isEmpty()) {
throw SormasToSormasException.fromStringProperty(Strings.errorSormasToSormasRevokeNotPending);
}
for (ShareRequestInfo request : pendingRequests) {
sormasToSormasRestClient.post(shareInfo.getOrganizationId(), REVOKE_REQUEST_ENDPOINT, Collections.singletonList(request.getUuid()), null);
request.setRequestStatus(ShareRequestStatus.REVOKED);
shareInfoService.ensurePersisted(shareInfo);
}
}
use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo in project SORMAS-Project by hzi-braunschweig.
the class ProcessedDataPersister method persistSyncData.
@Transactional(rollbackOn = { Exception.class })
public void persistSyncData(S processedData, SormasToSormasOriginInfoDto originInfo, E existingEntity) throws SormasToSormasValidationException {
T entity = processedData.getEntity();
SormasToSormasShareInfo shareInfo = getShareInfoByEntityAndOrganization(entity, originInfo.getOrganizationId());
if (shareInfo == null) {
entity.setSormasToSormasOriginInfo(originInfo);
}
persistSharedData(processedData, existingEntity);
}
use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjb method getOrCreateShareInfos.
@Override
protected List<SormasToSormasShareInfo> getOrCreateShareInfos(Event event, SormasToSormasOptionsDto options, User user, boolean forSync) {
String organizationId = options.getOrganization().getId();
SormasToSormasShareInfo eventShareInfo = event.getSormasToSormasShares().stream().filter(s -> s.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> ShareInfoHelper.createShareInfo(organizationId, event, SormasToSormasShareInfo::setEvent, options));
Stream<SormasToSormasShareInfo> eventParticipantShareInfos = Stream.empty();
List<EventParticipant> eventParticipants = Collections.emptyList();
if (options.isWithEventParticipants()) {
eventParticipants = eventParticipantService.getAllActiveByEvent(event);
eventParticipantShareInfos = eventParticipants.stream().map(ep -> ep.getSormasToSormasShares().stream().filter(share -> share.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> {
if (forSync) {
// do not share new event participants on sync
return ep.getSormasToSormasOriginInfo() != null && ep.getSormasToSormasOriginInfo().getOrganizationId().equals(organizationId) ? ShareInfoHelper.createShareInfo(organizationId, ep, SormasToSormasShareInfo::setEventParticipant, options) : null;
} else {
return ShareInfoHelper.createShareInfo(organizationId, ep, SormasToSormasShareInfo::setEventParticipant, options);
}
})).filter(Objects::nonNull);
}
Stream<SormasToSormasShareInfo> sampleShareInfos = Stream.empty();
Stream<SormasToSormasShareInfo> immunizationShareInfos = Stream.empty();
if (eventParticipants.size() > 0) {
if (options.isWithSamples()) {
List<String> eventParticipantUuids = eventParticipants.stream().map(EventParticipant::getUuid).collect(Collectors.toList());
sampleShareInfos = sampleService.getByEventParticipantUuids(eventParticipantUuids).stream().map(s -> s.getSormasToSormasShares().stream().filter(share -> share.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> ShareInfoHelper.createShareInfo(organizationId, s, SormasToSormasShareInfo::setSample, options)));
}
if (options.isWithImmunizations()) {
immunizationShareInfos = getAssociatedImmunizations(eventParticipants).stream().map(i -> i.getSormasToSormasShares().stream().filter(share -> share.getOrganizationId().equals(organizationId)).findFirst().orElseGet(() -> ShareInfoHelper.createShareInfo(organizationId, i, SormasToSormasShareInfo::setImmunization, options)));
}
}
return Stream.of(Stream.of(eventShareInfo), eventParticipantShareInfos, sampleShareInfos, immunizationShareInfos).flatMap(Function.identity()).collect(Collectors.toList());
}
use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo 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.share.shareinfo.SormasToSormasShareInfo in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasTest method createShareRequestInfo.
protected ShareRequestInfo createShareRequestInfo(User sender, String serverId, boolean ownershipHandedOver, ShareRequestStatus status, Consumer<SormasToSormasShareInfo> setTarget) {
SormasToSormasShareInfo shareInfo = new SormasToSormasShareInfo();
shareInfo.setOwnershipHandedOver(ownershipHandedOver);
shareInfo.setOrganizationId(serverId);
setTarget.accept(shareInfo);
ShareRequestInfo requestInfo = new ShareRequestInfo();
requestInfo.setUuid(DataHelper.createUuid());
requestInfo.setSender(sender);
requestInfo.setRequestStatus(status);
requestInfo.setShares(new ArrayList<>());
requestInfo.getShares().add(shareInfo);
return requestInfo;
}
Aggregations