Search in sources :

Example 1 with VersionDoesNotExistException

use of org.alfresco.service.cmr.version.VersionDoesNotExistException in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method findVersionIfApplicable.

private NodeRef findVersionIfApplicable(NodeRef nodeRef, String versionLabelId) {
    if (versionLabelId != null) {
        nodeRef = nodes.validateOrLookupNode(nodeRef.getId(), null);
        VersionHistory vh = versionService.getVersionHistory(nodeRef);
        if (vh != null) {
            try {
                Version v = vh.getVersion(versionLabelId);
                nodeRef = VersionUtil.convertNodeRef(v.getFrozenStateNodeRef());
            } catch (VersionDoesNotExistException vdne) {
                throw new NotFoundException("Couldn't find version: [" + nodeRef.getId() + ", " + versionLabelId + "]");
            }
        }
    }
    return nodeRef;
}
Also used : VersionDoesNotExistException(org.alfresco.service.cmr.version.VersionDoesNotExistException) Version(org.alfresco.service.cmr.version.Version) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 2 with VersionDoesNotExistException

use of org.alfresco.service.cmr.version.VersionDoesNotExistException in project alfresco-repository by Alfresco.

the class CMISNodeInfoImpl method analyseObjectId.

protected void analyseObjectId() {
    currentNodeId = objectId;
    currentObjectId = objectId;
    versionLabel = null;
    nodeRef = null;
    hasPWC = false;
    if (objectId == null) {
        objecVariant = CMISObjectVariant.INVALID_ID;
        return;
    }
    try {
        // is it a version?
        int sepIndex = objectId.lastIndexOf(CMISConnector.ID_SEPERATOR);
        if (sepIndex > -1) {
            currentNodeId = objectId.substring(0, sepIndex);
            versionLabel = objectId.substring(sepIndex + 1);
        }
        if (objectId.startsWith(CMISConnector.ASSOC_ID_PREFIX)) {
            // check the association id
            Long assocId = null;
            try {
                assocId = new Long(objectId.substring(CMISConnector.ASSOC_ID_PREFIX.length()));
            } catch (NumberFormatException nfe) {
                objecVariant = CMISObjectVariant.INVALID_ID;
                return;
            }
            // check the association
            associationRef = connector.getNodeService().getAssoc(assocId);
            if (associationRef == null) {
                objecVariant = CMISObjectVariant.NOT_EXISTING;
            } else {
                objecVariant = CMISObjectVariant.ASSOC;
            }
        } else {
            if (NodeRef.isNodeRef(objectId)) {
                NodeRef tmpNodeRef = new NodeRef(objectId);
                objectId = connector.constructObjectId(tmpNodeRef, null);
            }
            if (!NodeRef.isNodeRef(currentNodeId)) {
                currentNodeId = connector.getRootStoreRef() + "/" + currentNodeId;
            }
            // nodeRef is a "live" node, the version label identifies the specific version of the node
            nodeRef = new NodeRef(currentNodeId);
            // check for existence
            if (!connector.getNodeService().exists(nodeRef)) {
                objecVariant = CMISObjectVariant.NOT_EXISTING;
                return;
            }
            // check PWC
            if (isNodeWorkingCopy()) {
                NodeRef checkedOut = connector.getCheckOutCheckInService().getCheckedOut(nodeRef);
                if (connector.filter(nodeRef)) {
                    objecVariant = CMISObjectVariant.NOT_EXISTING;
                } else {
                    objecVariant = CMISObjectVariant.PWC;
                }
                currentObjectId = connector.createObjectId(checkedOut);
                currentNodeId = checkedOut.toString();
                versionLabel = CMISConnector.PWC_VERSION_LABEL;
                hasPWC = true;
                return;
            }
            if (isFolder()) {
                // folders can't be versioned, so no need to check
                if (connector.filter(nodeRef)) {
                    objecVariant = CMISObjectVariant.NOT_EXISTING;
                } else {
                    objecVariant = CMISObjectVariant.FOLDER;
                }
                return;
            }
            if (isItem()) {
                objecVariant = CMISObjectVariant.ITEM;
                return;
            }
            if (versionLabel == null) {
                if (isDocument()) {
                    // for a document, absence of a version label implies the current (head) version
                    if (connector.filter(nodeRef)) {
                        objecVariant = CMISObjectVariant.NOT_EXISTING;
                    } else {
                        objecVariant = CMISObjectVariant.CURRENT_VERSION;
                    }
                    // Is it un-versioned, or currently versioned?
                    Version currentVersion = connector.getVersionService().getCurrentVersion(nodeRef);
                    if (currentVersion != null) {
                        versionLabel = currentVersion.getVersionLabel();
                        versionHistory = connector.getVersionService().getVersionHistory(nodeRef);
                    } else {
                        versionLabel = CMISConnector.UNVERSIONED_VERSION_LABEL;
                    }
                    objectId = connector.constructObjectId(objectId, versionLabel);
                    currentObjectId = objectId;
                    hasPWC = isNodeCheckedOut();
                } else {
                    objecVariant = CMISObjectVariant.NOT_A_CMIS_OBJECT;
                }
                return;
            }
            // check if it has PWC label
            if (versionLabel.equals(CMISConnector.PWC_VERSION_LABEL)) {
                NodeRef pwcNodeRef = connector.getCheckOutCheckInService().getWorkingCopy(nodeRef);
                if (pwcNodeRef == null) {
                    objecVariant = CMISObjectVariant.NOT_EXISTING;
                    return;
                } else if (connector.filter(nodeRef)) {
                    objecVariant = CMISObjectVariant.NOT_EXISTING;
                } else {
                    objecVariant = CMISObjectVariant.PWC;
                }
                currentObjectId = connector.createObjectId(nodeRef);
                currentNodeId = nodeRef.toString();
                hasPWC = true;
                nodeRef = pwcNodeRef;
                return;
            }
            // check version
            if (!isNodeVersioned(nodeRef)) {
                // the node isn't versioned
                if (connector.filter(nodeRef)) {
                    objecVariant = CMISObjectVariant.NOT_EXISTING;
                } else if (versionLabel.equals(CMISConnector.UNVERSIONED_VERSION_LABEL)) {
                    objecVariant = CMISObjectVariant.CURRENT_VERSION;
                } else {
                    objecVariant = CMISObjectVariant.NOT_EXISTING;
                }
            } else {
                // the node is versioned, determine whether the versionLabel refers to the head version or a
                // specific non-head version
                String headVersionLabel = (String) connector.getNodeService().getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
                currentObjectId = connector.constructObjectId(currentNodeId, headVersionLabel);
                if (versionLabel.equals(headVersionLabel)) {
                    // the version label refers to the current head version
                    objecVariant = CMISObjectVariant.CURRENT_VERSION;
                } else {
                    // the version label refers to a specific non-head version, find the nodeRef
                    // of the version node from the version history
                    versionHistory = connector.getVersionService().getVersionHistory(nodeRef);
                    if (versionHistory == null) {
                        // unexpected null versionHistory, assume not versioned
                        if (versionLabel.equals(CMISConnector.UNVERSIONED_VERSION_LABEL)) {
                            objecVariant = CMISObjectVariant.CURRENT_VERSION;
                        } else {
                            objecVariant = CMISObjectVariant.NOT_EXISTING;
                        }
                    } else {
                        try {
                            version = versionHistory.getVersion(versionLabel);
                            nodeRef = version.getFrozenStateNodeRef();
                            objecVariant = CMISObjectVariant.VERSION;
                        } catch (VersionDoesNotExistException e) {
                            objecVariant = CMISObjectVariant.NOT_EXISTING;
                        }
                    }
                }
            }
            // check if current node(not specified version) checked out
            hasPWC = connector.getCheckOutCheckInService().isCheckedOut(getCurrentNodeNodeRef());
        }
    } catch (AccessDeniedException e) {
        objecVariant = CMISObjectVariant.PERMISSION_DENIED;
    }// TODO: Somewhere this has not been wrapped correctly
     catch (net.sf.acegisecurity.AccessDeniedException e) {
        objecVariant = CMISObjectVariant.PERMISSION_DENIED;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) VersionDoesNotExistException(org.alfresco.service.cmr.version.VersionDoesNotExistException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) Version(org.alfresco.service.cmr.version.Version)

Example 3 with VersionDoesNotExistException

use of org.alfresco.service.cmr.version.VersionDoesNotExistException in project alfresco-repository by Alfresco.

the class VersionHistoryImplTest method testGetVersion.

/**
 * Test getVersion
 */
public void testGetVersion() {
    VersionHistoryImpl vh = testAddVersionImpl();
    Version version1 = vh.getVersion("1");
    assertEquals(version1.getVersionLabel(), this.rootVersion.getVersionLabel());
    Version version2 = vh.getVersion("2");
    assertEquals(version2.getVersionLabel(), this.childVersion1.getVersionLabel());
    Version version3 = vh.getVersion("3");
    assertEquals(version3.getVersionLabel(), this.childVersion2.getVersionLabel());
    try {
        vh.getVersion("invalidLabel");
        fail("An exception should have been thrown if the version can not be retrieved.");
    } catch (VersionDoesNotExistException exception) {
        System.out.println("Error message: " + exception.getMessage());
    }
}
Also used : VersionDoesNotExistException(org.alfresco.service.cmr.version.VersionDoesNotExistException) Version(org.alfresco.service.cmr.version.Version)

Aggregations

Version (org.alfresco.service.cmr.version.Version)3 VersionDoesNotExistException (org.alfresco.service.cmr.version.VersionDoesNotExistException)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)1