Search in sources :

Example 1 with VersionType

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

the class NodesImpl method createNewFile.

private NodeRef createNewFile(NodeRef parentNodeRef, String fileName, QName nodeType, Content content, Map<QName, Serializable> props, QName assocTypeQName, Parameters params, Boolean versionMajor, String versionComment) {
    NodeRef nodeRef = createNodeImpl(parentNodeRef, fileName, nodeType, props, assocTypeQName);
    if (content == null) {
        // Write "empty" content
        writeContent(nodeRef, fileName, new ByteArrayInputStream("".getBytes()), false);
    } else {
        // Write content
        writeContent(nodeRef, fileName, content.getInputStream(), true);
    }
    if ((versionMajor != null) || (versionComment != null)) {
        behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
        try {
            // by default, first version is major, unless specified otherwise
            VersionType versionType = VersionType.MAJOR;
            if ((versionMajor != null) && (!versionMajor)) {
                versionType = VersionType.MINOR;
            }
            createVersion(nodeRef, false, versionType, versionComment);
            extractMetadata(nodeRef);
        } finally {
            behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
        }
    }
    return nodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionType(org.alfresco.service.cmr.version.VersionType)

Example 2 with VersionType

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

the class NodesImpl method updateExistingFile.

private Node updateExistingFile(NodeRef parentNodeRef, NodeRef nodeRef, String fileName, BasicContentInfo contentInfo, InputStream stream, Parameters parameters, Boolean versionMajor, String versionComment) {
    boolean isVersioned = versionService.isVersioned(nodeRef);
    behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
    try {
        writeContent(nodeRef, fileName, stream, true);
        if ((isVersioned) || (versionMajor != null) || (versionComment != null)) {
            VersionType versionType = null;
            if (versionMajor != null) {
                versionType = (versionMajor ? VersionType.MAJOR : VersionType.MINOR);
            } else {
                // note: it is possible to have versionable aspect but no versions (=> no version label)
                if ((!isVersioned) || (nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL) == null)) {
                    versionType = VersionType.MAJOR;
                } else {
                    versionType = VersionType.MINOR;
                }
            }
            createVersion(nodeRef, isVersioned, versionType, versionComment);
        }
        ActivityInfo activityInfo = getActivityInfo(parentNodeRef, nodeRef);
        postActivity(Activity_Type.UPDATED, activityInfo, false);
        extractMetadata(nodeRef);
    } finally {
        behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
    }
    return getFolderOrDocumentFullInfo(nodeRef, null, null, parameters);
}
Also used : ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) VersionType(org.alfresco.service.cmr.version.VersionType)

Example 3 with VersionType

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

the class NodeVersionsRelation method revertById.

@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
        NodeRef nodeRef = v.getVersionedNodeRef();
        String versionComment = versionOptions.getComment();
        VersionType versionType = VersionType.MINOR;
        Boolean versionMajor = versionOptions.getMajorVersion();
        if ((versionMajor != null) && (versionMajor)) {
            versionType = VersionType.MAJOR;
        }
        Map<String, Serializable> versionProperties = new HashMap<>(2);
        versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
        if (versionComment != null) {
            versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
        }
        // cancel editing if we want to revert
        if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
            nodeRef = cociService.cancelCheckout(nodeRef);
        }
        // TODO review default for deep and/or whether we should make it an option
        versionService.revert(nodeRef, v, false);
        // Checkout/Checkin the node - to store the new version in version history
        NodeRef wcNodeRef = cociService.checkout(nodeRef);
        cociService.checkin(wcNodeRef, versionProperties);
        // get latest version
        v = versionService.getVersionHistory(nodeRef).getHeadVersion();
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) Version(org.alfresco.service.cmr.version.Version) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionType(org.alfresco.service.cmr.version.VersionType) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Aggregations

VersionType (org.alfresco.service.cmr.version.VersionType)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Node (org.alfresco.rest.api.model.Node)1 Operation (org.alfresco.rest.framework.Operation)1 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 ActivityInfo (org.alfresco.service.cmr.activities.ActivityInfo)1 CheckOutCheckInService (org.alfresco.service.cmr.coci.CheckOutCheckInService)1 Version (org.alfresco.service.cmr.version.Version)1