use of io.lumeer.core.exception.UnsupportedOperationException in project engine by Lumeer.
the class AuditFacade method revertLastLinkAuditOperation.
public LinkInstance revertLastLinkAuditOperation(final String linkTypeId, final String linkInstanceId, final String auditRecordId) {
final LinkType linkType = linkTypeDao.getLinkType(linkTypeId);
final LinkInstance linkInstance = LinkInstanceUtils.loadLinkInstanceWithData(linkInstanceDao, linkDataDao, linkInstanceId);
permissionsChecker.checkEditLinkInstance(linkType, linkInstance);
if (workspaceKeeper.getOrganization().isPresent()) {
final ServiceLimits limits = paymentFacade.getCurrentServiceLimits(workspaceKeeper.getOrganization().get());
if (limits.getServiceLevel().equals(Payment.ServiceLevel.FREE)) {
throw new UnsupportedOperationException("Reverting audit log entries is not available on the free plan.");
}
final AuditRecord auditRecord = auditDao.findLatestAuditRecord(linkTypeId, ResourceType.LINK, linkInstanceId);
if (auditRecord != null && auditRecord.getId().equals(auditRecordId) && auditRecord.getOldState() != null) {
var keysToBeRemoved = new HashSet<>(auditRecord.getNewState().keySet());
keysToBeRemoved.removeAll(auditRecord.getOldState().keySet());
linkInstance.getData().putAll(auditRecord.getOldState());
keysToBeRemoved.forEach(key -> linkInstance.getData().remove(key));
dataDao.patchData(linkTypeId, linkInstanceId, auditRecord.getOldState());
auditDao.deleteAuditRecord(auditRecordId);
}
linkInstance.setData(constraintManager.decodeDataTypes(linkType, linkInstance.getData()));
return linkInstanceAdapter.mapLinkInstanceData(linkInstance);
}
throw new UnsupportedOperationException("No organization specified.");
}
use of io.lumeer.core.exception.UnsupportedOperationException in project engine by Lumeer.
the class ResourceVariableFacade method checkPermissions.
private void checkPermissions(final ResourceVariable variable, final RoleType roleType) {
switch(variable.getResourceType()) {
case ORGANIZATION:
Organization organization = organizationDao.getOrganizationById(variable.getOrganizationId());
permissionsChecker.checkRole(organization, roleType);
break;
case PROJECT:
checkProjectPermissions(variable.getProjectId(), roleType);
break;
default:
throw new UnsupportedOperationException("Resource type '" + variable.getResourceType() + "' is not supported now");
}
}
use of io.lumeer.core.exception.UnsupportedOperationException in project engine by Lumeer.
the class AuditFacade method registerLinkUpdate.
private AuditRecord registerLinkUpdate(final LinkInstance oldLink, final LinkInstance newLink) {
if (oldLink == null || newLink == null || oldLink.getData() == null || newLink.getData() == null || !oldLink.getId().equals(newLink.getId())) {
throw new UnsupportedOperationException("Cannot create audit record from different or incomplete link instances.");
}
final User user = authenticatedUser.getCurrentUser();
final LinkType linkType = linkTypeDao.getLinkType(oldLink.getLinkTypeId());
final DataDocument oldDataDecoded = constraintManager.decodeDataTypes(linkType, oldLink.getData());
final DataDocument newDataDecoded = constraintManager.decodeDataTypes(linkType, newLink.getData());
return auditAdapter.registerDataChange(linkType.getId(), ResourceType.LINK, oldLink.getId(), user, null, getCurrentViewId(), oldLink.getData(), oldDataDecoded, newLink.getData(), newDataDecoded);
}
use of io.lumeer.core.exception.UnsupportedOperationException in project engine by Lumeer.
the class AuditFacade method registerLinkCreate.
private AuditRecord registerLinkCreate(final LinkInstance newLink) {
if (newLink == null) {
throw new UnsupportedOperationException("Cannot create audit record from different or incomplete link instances.");
}
final User user = authenticatedUser.getCurrentUser();
final LinkType linkType = linkTypeDao.getLinkType(newLink.getLinkTypeId());
final DataDocument newDataDecoded = constraintManager.decodeDataTypes(linkType, newLink.getData());
return auditAdapter.registerCreate(linkType.getId(), ResourceType.LINK, newLink.getId(), user, null, getCurrentViewId(), newDataDecoded);
}
use of io.lumeer.core.exception.UnsupportedOperationException in project engine by Lumeer.
the class AuditFacade method revertLinkChange.
public void revertLinkChange(final AuditRecord requestedRecord) {
final AuditRecord auditRecord = auditDao.findLatestAuditRecord(requestedRecord.getParentId(), ResourceType.LINK, requestedRecord.getResourceId(), AuditType.Updated);
if (auditRecord == null || !auditRecord.getId().equals(requestedRecord.getId())) {
throw new UnsupportedOperationException("Cannot revert audit record that is not the last.");
}
final LinkType linkType = linkTypeDao.getLinkType(auditRecord.getParentId());
final LinkInstance linkInstance = LinkInstanceUtils.loadLinkInstanceWithData(linkInstanceDao, linkDataDao, auditRecord.getResourceId());
permissionsChecker.checkEditLinkInstance(linkType, linkInstance);
if (auditRecord.getOldState() != null) {
var keysToAdd = new HashSet<>(auditRecord.getOldState().keySet());
keysToAdd.removeAll(auditRecord.getNewState().keySet());
var keysToRemove = new HashSet<>(auditRecord.getNewState().keySet());
keysToRemove.removeAll(auditRecord.getOldState().keySet());
linkInstance.getData().putAll(auditRecord.getOldState());
keysToRemove.forEach(key -> linkInstance.getData().remove(key));
DataDocument storedData = linkDataDao.updateData(auditRecord.getParentId(), auditRecord.getResourceId(), linkInstance.getData());
checkAuditOnObjectRevert(auditRecord);
linkInstance.setUpdateDate(ZonedDateTime.now());
linkInstance.setUpdatedBy(getCurrentUserId());
LinkInstance storedLinkInstance = linkInstanceDao.updateLinkInstance(linkInstance.getId(), linkInstance);
storedLinkInstance.setData(storedData);
linkTypeAdapter.updateLinkTypeMetadata(linkType, keysToAdd, keysToRemove);
sendLinkNotification(linkType, storedLinkInstance, PusherFacade.UPDATE_EVENT_SUFFIX);
}
}
Aggregations