Search in sources :

Example 1 with SormasToSormasShareInfo

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);
    }
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) Arrays(java.util.Arrays) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) Date(java.util.Date) RESOURCE_PATH(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants.RESOURCE_PATH) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) SormasToSormasContactFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.contact.SormasToSormasContactFacadeEjb.SormasToSormasContactFacadeEjbLocal) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasShareable(de.symeda.sormas.backend.sormastosormas.entities.SormasToSormasShareable) SormasToSormasCaseFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.caze.SormasToSormasCaseFacadeEjb.SormasToSormasCaseFacadeEjbLocal) LocalBean(javax.ejb.LocalBean) EJB(javax.ejb.EJB) ConfigFacadeEjb(de.symeda.sormas.backend.common.ConfigFacadeEjb) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) Transactional(javax.transaction.Transactional) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) SormasToSormasApiConstants(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants) ShareRequestDataType(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType) SormasToSormasEncryptionFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.crypto.SormasToSormasEncryptionFacadeEjb.SormasToSormasEncryptionFacadeEjbLocal) SormasToSormasRestClient(de.symeda.sormas.backend.sormastosormas.rest.SormasToSormasRestClient) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) Collectors(java.util.stream.Collectors) SormasToSormasEntityInterface(de.symeda.sormas.api.sormastosormas.SormasToSormasEntityInterface) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) UserRight(de.symeda.sormas.api.user.UserRight) SormasToSormasShareRequestFacadeEJBLocal(de.symeda.sormas.backend.sormastosormas.share.sharerequest.SormasToSormasShareRequestFacadeEJB.SormasToSormasShareRequestFacadeEJBLocal) List(java.util.List) SormasToSormasFacade(de.symeda.sormas.api.sormastosormas.SormasToSormasFacade) UserService(de.symeda.sormas.backend.user.UserService) SormasToSormasEventFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.event.SormasToSormasEventFacadeEjb.SormasToSormasEventFacadeEjbLocal) ShareRequestInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfoService) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RequestResponseDataDto(de.symeda.sormas.api.sormastosormas.sharerequest.RequestResponseDataDto) SormasToSormasDiscoveryService(de.symeda.sormas.backend.sormastosormas.access.SormasToSormasDiscoveryService) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) Transactional(javax.transaction.Transactional)

Example 2 with SormasToSormasShareInfo

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);
}
Also used : SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) Transactional(javax.transaction.Transactional)

Example 3 with SormasToSormasShareInfo

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());
}
Also used : EventService(de.symeda.sormas.backend.event.EventService) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) RESOURCE_PATH(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants.RESOURCE_PATH) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) ValidationErrorGroup(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup) AbstractSormasToSormasInterface(de.symeda.sormas.backend.sormastosormas.AbstractSormasToSormasInterface) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) Function(java.util.function.Function) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) ArrayList(java.util.ArrayList) SormasToSormasEventFacade(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventFacade) ValidationErrorMessage(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorMessage) EVENT_SYNC_ENDPOINT(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants.EVENT_SYNC_ENDPOINT) LocalBean(javax.ejb.LocalBean) EJB(javax.ejb.EJB) Stateless(javax.ejb.Stateless) Validations(de.symeda.sormas.api.i18n.Validations) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) ValidationHelper.buildEventValidationGroupName(de.symeda.sormas.backend.sormastosormas.ValidationHelper.buildEventValidationGroupName) SormasToSormasApiConstants(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants) ShareRequestDataType(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType) BaseAdoService(de.symeda.sormas.backend.common.BaseAdoService) EventDto(de.symeda.sormas.api.event.EventDto) ImmunizationService(de.symeda.sormas.backend.immunization.ImmunizationService) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) Objects(java.util.Objects) Event(de.symeda.sormas.backend.event.Event) EVENT_ENDPOINT(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants.EVENT_ENDPOINT) List(java.util.List) Stream(java.util.stream.Stream) User(de.symeda.sormas.backend.user.User) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) SampleService(de.symeda.sormas.backend.sample.SampleService) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) EventParticipant(de.symeda.sormas.backend.event.EventParticipant)

Example 4 with SormasToSormasShareInfo

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);
    }
}
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 5 with SormasToSormasShareInfo

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;
}
Also used : ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo)

Aggregations

SormasToSormasShareInfo (de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo)12 Strings (de.symeda.sormas.api.i18n.Strings)4 SormasToSormasApiConstants (de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants)4 RESOURCE_PATH (de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants.RESOURCE_PATH)4 SormasToSormasException (de.symeda.sormas.api.sormastosormas.SormasToSormasException)4 SormasToSormasOptionsDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto)4 ShareRequestDataType (de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType)4 SormasToSormasShareInfoService (de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService)4 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 EJB (javax.ejb.EJB)4 LocalBean (javax.ejb.LocalBean)4 Stateless (javax.ejb.Stateless)4 Captions (de.symeda.sormas.api.i18n.Captions)3 Validations (de.symeda.sormas.api.i18n.Validations)3 ValidationErrorGroup (de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup)3 ValidationErrorMessage (de.symeda.sormas.api.sormastosormas.validation.ValidationErrorMessage)3 ValidationErrors (de.symeda.sormas.api.sormastosormas.validation.ValidationErrors)3 BaseAdoService (de.symeda.sormas.backend.common.BaseAdoService)3