Search in sources :

Example 1 with ShareRequestInfo

use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasFacadeEjb method requestRejected.

@Override
@Transactional(rollbackOn = { Exception.class })
public void requestRejected(SormasToSormasEncryptedDataDto encryptedRejectData) throws SormasToSormasException {
    RequestResponseDataDto rejectData = sormasToSormasEncryptionEjb.decryptAndVerify(encryptedRejectData, RequestResponseDataDto.class);
    ShareRequestInfo requestInfo = shareRequestInfoService.getByUuid(rejectData.getRequestUuid());
    if (requestInfo == null || requestInfo.getRequestStatus() != ShareRequestStatus.PENDING) {
        throw SormasToSormasException.fromStringProperty(Strings.errorSormasToSormasRejectNotPending);
    }
    requestInfo.setRequestStatus(ShareRequestStatus.REJECTED);
    requestInfo.setResponseComment(rejectData.getComment());
    requestInfo.getShares().forEach(s -> s.setOwnershipHandedOver(false));
    shareRequestInfoService.ensurePersisted(requestInfo);
}
Also used : ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) RequestResponseDataDto(de.symeda.sormas.api.sormastosormas.sharerequest.RequestResponseDataDto) Transactional(javax.transaction.Transactional)

Example 2 with ShareRequestInfo

use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo 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 3 with ShareRequestInfo

use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo in project SORMAS-Project by hzi-braunschweig.

the class AbstractSormasToSormasInterface method syncEntityToOrigin.

private void syncEntityToOrigin(ADO entity, SormasToSormasOriginInfo originInfo, ShareTreeCriteria criteria) throws SormasToSormasException {
    User currentUser = userService.getCurrentUser();
    SormasToSormasOptionsDto options = dataBuilderHelper.createOptionsFromOriginInfoDto(originInfo);
    options.setHandOverOwnership(false);
    ShareRequestInfo shareRequestInfo = createShareRequestInfoForEntities(DataHelper.createUuid(), ShareRequestStatus.ACCEPTED, options, Collections.singletonList(entity), currentUser, true);
    SormasToSormasDto shareData = shareDataBuilder.buildShareData(shareRequestInfo.getShares(), dataBuilderHelper.createSormasToSormasOriginInfo(currentUser, options), shareRequestInfo);
    sormasToSormasRestClient.post(originInfo.getOrganizationId(), syncEndpoint, new SyncDataDto(shareData, criteria), null);
    // remove existing shares from the request info
    shareRequestInfo.setShares(shareRequestInfo.getShares().stream().filter(s -> s.getId() == null).collect(Collectors.toList()));
    if (!shareRequestInfo.getShares().isEmpty()) {
        shareRequestInfoService.ensurePersisted(shareRequestInfo);
    }
}
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) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) SyncDataDto(de.symeda.sormas.backend.sormastosormas.entities.SyncDataDto)

Example 4 with ShareRequestInfo

use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo 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 5 with ShareRequestInfo

use of de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo in project SORMAS-Project by hzi-braunschweig.

the class AbstractSormasToSormasInterface method getDataForShareRequest.

@Override
public SormasToSormasEncryptedDataDto getDataForShareRequest(SormasToSormasEncryptedDataDto encryptedRequestUuid) throws SormasToSormasException {
    User currentUser = userService.getCurrentUser();
    String requestUuid = sormasToSormasEncryptionEjb.decryptAndVerify(encryptedRequestUuid, String.class);
    ShareRequestInfo requestInfo = shareRequestInfoService.getByUuid(requestUuid);
    validateEntitiesBeforeShare(requestInfo.getShares());
    SormasToSormasDto shareData = shareDataBuilder.buildShareDataForRequest(requestInfo, currentUser);
    return sormasToSormasEncryptionEjb.signAndEncrypt(shareData, requestInfo.getShares().get(0).getOrganizationId());
}
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)

Aggregations

ShareRequestInfo (de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo)18 User (de.symeda.sormas.backend.user.User)13 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)8 ShareTreeCriteria (de.symeda.sormas.api.sormastosormas.ShareTreeCriteria)7 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)7 SormasToSormasEncryptedDataDto (de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto)7 SormasToSormasShareInfoDto (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto)7 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)7 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)7 Collections (java.util.Collections)7 Date (java.util.Date)7 List (java.util.List)7 Test (org.junit.Test)7 SormasToSormasException (de.symeda.sormas.api.sormastosormas.SormasToSormasException)6 SormasToSormasOptionsDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto)6 ShareRequestStatus (de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus)6 SormasToSormasShareRequestDto (de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto)6 SormasToSormasValidationException (de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException)6 Arrays (java.util.Arrays)6 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)5