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