@Override public void verifyRevision(final Revision revision, final NiFiUser user) { final Revision curRevision = revisionManager.getRevision(revision.getComponentId()); if (revision.equals(curRevision)) { return; } throw new InvalidRevisionException(revision + " is not the most up-to-date revision. This component appears to have been modified"); }
@Override public <T> T deleteRevision(final RevisionClaim claim, final NiFiUser user, final DeleteRevisionTask<T> task) throws ExpiredRevisionClaimException { Objects.requireNonNull(user); logger.debug("Attempting to delete revision using {}", claim); final List<Revision> revisionList = new ArrayList<>(claim.getRevisions()); revisionList.sort(new RevisionComparator()); // Verify the provided revisions. String failedId = null; for (final Revision revision : revisionList) { final Revision curRevision = getRevision(revision.getComponentId()); if (!curRevision.equals(revision)) { throw new ExpiredRevisionClaimException("Invalid Revision was given for component with ID '" + failedId + "'"); } } // Perform the action provided final T taskResult = task.performTask(); for (final Revision revision : revisionList) { revisionMap.remove(revision.getComponentId()); } return taskResult; }
@Override public <T> RevisionUpdate<T> updateRevision(final RevisionClaim originalClaim, final NiFiUser user, final UpdateRevisionTask<T> task) throws ExpiredRevisionClaimException { Objects.requireNonNull(user); logger.debug("Attempting to update revision using {}", originalClaim); final List<Revision> revisionList = new ArrayList<>(originalClaim.getRevisions()); revisionList.sort(new RevisionComparator()); for (final Revision revision : revisionList) { final Revision currentRevision = getRevision(revision.getComponentId()); final boolean verified = revision.equals(currentRevision); if (!verified) { // Throw an Exception indicating that we failed to obtain the locks throw new InvalidRevisionException("Invalid Revision was given for component with ID '" + revision.getComponentId() + "'"); } } // We successfully verified all revisions. logger.debug("Successfully verified Revision Claim for all revisions"); // Perform the update final RevisionUpdate<T> updatedComponent = task.update(); // If the update succeeded then put the updated revisions into the revisionMap // If an exception is thrown during the update we don't want to update revision so it is ok to bounce out of this method if (updatedComponent != null) { for (final Revision updatedRevision : updatedComponent.getUpdatedRevisions()) { revisionMap.put(updatedRevision.getComponentId(), updatedRevision); } } return updatedComponent; }