Search in sources :

Example 1 with UnsupportedOperationException

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.");
}
Also used : ServiceLimits(io.lumeer.api.model.ServiceLimits) LinkInstance(io.lumeer.api.model.LinkInstance) RemoveLinkInstance(io.lumeer.engine.api.event.RemoveLinkInstance) UpdateLinkInstance(io.lumeer.engine.api.event.UpdateLinkInstance) AuditRecord(io.lumeer.api.model.AuditRecord) LinkType(io.lumeer.api.model.LinkType) UnsupportedOperationException(io.lumeer.core.exception.UnsupportedOperationException) HashSet(java.util.HashSet)

Example 2 with UnsupportedOperationException

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");
    }
}
Also used : Organization(io.lumeer.api.model.Organization) UnsupportedOperationException(io.lumeer.core.exception.UnsupportedOperationException)

Example 3 with UnsupportedOperationException

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) User(io.lumeer.api.model.User) LinkType(io.lumeer.api.model.LinkType) UnsupportedOperationException(io.lumeer.core.exception.UnsupportedOperationException)

Example 4 with UnsupportedOperationException

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) User(io.lumeer.api.model.User) LinkType(io.lumeer.api.model.LinkType) UnsupportedOperationException(io.lumeer.core.exception.UnsupportedOperationException)

Example 5 with UnsupportedOperationException

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);
    }
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) AuditRecord(io.lumeer.api.model.AuditRecord) CreateLinkInstance(io.lumeer.engine.api.event.CreateLinkInstance) LinkInstance(io.lumeer.api.model.LinkInstance) RemoveLinkInstance(io.lumeer.engine.api.event.RemoveLinkInstance) UpdateLinkInstance(io.lumeer.engine.api.event.UpdateLinkInstance) LinkType(io.lumeer.api.model.LinkType) UnsupportedOperationException(io.lumeer.core.exception.UnsupportedOperationException) HashSet(java.util.HashSet)

Aggregations

UnsupportedOperationException (io.lumeer.core.exception.UnsupportedOperationException)15 DataDocument (io.lumeer.engine.api.data.DataDocument)10 User (io.lumeer.api.model.User)8 Collection (io.lumeer.api.model.Collection)7 AuditRecord (io.lumeer.api.model.AuditRecord)6 LinkType (io.lumeer.api.model.LinkType)6 HashSet (java.util.HashSet)4 Document (io.lumeer.api.model.Document)3 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)3 UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)3 LinkInstance (io.lumeer.api.model.LinkInstance)2 ServiceLimits (io.lumeer.api.model.ServiceLimits)2 CreateDocument (io.lumeer.engine.api.event.CreateDocument)2 RemoveLinkInstance (io.lumeer.engine.api.event.RemoveLinkInstance)2 UpdateLinkInstance (io.lumeer.engine.api.event.UpdateLinkInstance)2 Organization (io.lumeer.api.model.Organization)1 Payment (io.lumeer.api.model.Payment)1 CreateLinkInstance (io.lumeer.engine.api.event.CreateLinkInstance)1