Search in sources :

Example 16 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImpl method getRecordedVersion.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#getRecordedVersion(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public Version getRecordedVersion(NodeRef versionRecord) {
    Version version = null;
    NodeRef versionedNodeRef = (NodeRef) nodeService.getProperty(versionRecord, RecordableVersionModel.PROP_VERSIONED_NODEREF);
    if (versionedNodeRef != null) {
        String versionLabel = (String) nodeService.getProperty(versionRecord, RecordableVersionModel.PROP_VERSION_LABEL);
        if (StringUtils.isNotBlank(versionLabel)) {
            VersionHistory versionHistory = getVersionHistory(versionedNodeRef);
            if (versionHistory != null) {
                version = versionHistory.getVersion(versionLabel);
            }
        }
    }
    return version;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 17 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImpl method createRecordFromLatestVersion.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#createRecordFromLatestVersion(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public NodeRef createRecordFromLatestVersion(final NodeRef filePlan, final NodeRef nodeRef) {
    ParameterCheck.mandatory("filePlan", filePlan);
    ParameterCheck.mandatory("nodeRef", nodeRef);
    NodeRef record = null;
    // check for versionable aspect
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
        createSnapshotVersion(nodeRef);
        // get the latest version
        final Version currentVersion = getCurrentVersion(nodeRef);
        if (currentVersion != null && !isRecordedVersion(currentVersion)) {
            // create the record from the current frozen state
            record = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {

                public NodeRef doWork() throws Exception {
                    // get the documents readers and writers
                    Pair<Set<String>, Set<String>> readersAndWriters = extendedPermissionService.getReadersAndWriters(nodeRef);
                    // grab the frozen state
                    NodeRef currentFrozenState = currentVersion.getFrozenStateNodeRef();
                    // determine the type of the object
                    QName type = nodeService.getType(currentFrozenState);
                    // grab all the properties
                    Map<QName, Serializable> properties = nodeService.getProperties(currentFrozenState);
                    // grab all the aspects
                    Set<QName> aspects = nodeService.getAspects(currentFrozenState);
                    // create the record
                    NodeRef record = recordService.createRecordFromContent(filePlan, (String) properties.get(ContentModel.PROP_NAME), type, properties, null);
                    // apply aspects to record
                    for (QName aspect : aspects) {
                        // add the aspect, properties have already been set
                        nodeService.addAspect(record, aspect, null);
                    }
                    // apply version record aspect to record
                    PropertyMap versionRecordProps = new PropertyMap(3);
                    versionRecordProps.put(PROP_VERSIONED_NODEREF, nodeRef);
                    versionRecordProps.put(RecordableVersionModel.PROP_VERSION_LABEL, currentVersion.getVersionLabel());
                    versionRecordProps.put(RecordableVersionModel.PROP_VERSION_DESCRIPTION, currentVersion.getDescription());
                    versionRecordProps.put(ContentModel.PROP_VERSION_TYPE, currentVersion.getVersionType());
                    nodeService.addAspect(record, ASPECT_VERSION_RECORD, versionRecordProps);
                    // wire record up to previous record
                    linkToPreviousVersionRecord(nodeRef, record);
                    // set the extended security
                    extendedSecurityService.set(record, readersAndWriters);
                    return record;
                }
            });
            // get the version history
            NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
            // get details from the version before we remove it
            int versionNumber = getVersionNumber(currentVersion);
            Map<QName, Serializable> versionProperties = getVersionAspectProperties(currentVersion);
            QName sourceTypeRef = getVersionType(currentVersion);
            // patch-up owner information, which needs to be frozen for recorded versions
            String owner = (String) nodeService.getProperty(currentVersion.getFrozenStateNodeRef(), ContentModel.PROP_OWNER);
            if (owner != null) {
                versionProperties.put(PROP_FROZEN_OWNER, owner);
            }
            // delete the current version
            this.dbNodeService.deleteNode(convertNodeRef(currentVersion.getFrozenStateNodeRef()));
            // create a new version history if we need to
            if (!nodeService.exists(versionHistoryRef)) {
                versionHistoryRef = createVersionHistory(nodeRef);
            }
            // create recorded version nodeRef
            ChildAssociationRef childAssocRef = dbNodeService.createNode(versionHistoryRef, Version2Model.CHILD_QNAME_VERSIONS, QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.CHILD_VERSIONS + "-" + versionNumber), sourceTypeRef, null);
            NodeRef versionNodeRef = childAssocRef.getChildRef();
            // add aspect with the standard version properties to the 'version' node
            nodeService.addAspect(versionNodeRef, Version2Model.ASPECT_VERSION, versionProperties);
            // add the recordedVersion aspect with link to record
            nodeService.addAspect(versionNodeRef, ASPECT_RECORDED_VERSION, Collections.singletonMap(PROP_RECORD_NODE_REF, (Serializable) record));
        }
    }
    return record;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) Version(org.alfresco.service.cmr.version.Version)

Example 18 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImpl method isCurrentVersionRecorded.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#isLatestVersionRecorded(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public boolean isCurrentVersionRecorded(NodeRef nodeRef) {
    boolean result = false;
    Version version = getCurrentVersion(nodeRef);
    if (version != null) {
        result = isRecordedVersion(version);
    }
    return result;
}
Also used : Version(org.alfresco.service.cmr.version.Version)

Example 19 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImpl method isCurrentVersionDirty.

/**
 * Check if current version of the node is modified compared with versioned version
 *
 * @param nodeRef internal node reference
 * @return boolean true if nodeRef is modified, otherwise false
 */
public boolean isCurrentVersionDirty(NodeRef nodeRef) {
    if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
        return false;
    }
    // get the latest version
    Version currentVersion = getCurrentVersion(nodeRef);
    Date modificationDate = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
    if (currentVersion == null) {
        return true;
    }
    // grab the frozen state
    NodeRef currentFrozenState = currentVersion.getFrozenStateNodeRef();
    Date frozenModificationDate = (Date) nodeService.getProperty(currentFrozenState, ContentModel.PROP_MODIFIED);
    boolean versionStoreOutdated = ((frozenModificationDate != null) && (modificationDate.getTime() > frozenModificationDate.getTime()));
    return versionStoreOutdated;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) Date(java.util.Date)

Example 20 with Version

use of org.alfresco.service.cmr.version.Version in project acs-community-packaging by Alfresco.

the class DocumentDetailsDialog method getVersionHistory.

/**
 * Returns a list of objects representing the versions of the
 * current document
 *
 * @return List of previous versions
 */
public List getVersionHistory() {
    List<MapNode> versions = new ArrayList<MapNode>();
    if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE)) {
        VersionHistory history = this.getVersionService().getVersionHistory(getDocument().getNodeRef());
        if (history != null) {
            for (Version version : history.getAllVersions()) {
                // create a map node representation of the version
                MapNode clientVersion = new MapNode(version.getFrozenStateNodeRef());
                clientVersion.put("versionLabel", version.getVersionLabel());
                clientVersion.put("notes", version.getDescription());
                clientVersion.put("author", version.getCreator());
                clientVersion.put("versionDate", version.getCreatedDate());
                if (getDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
                    clientVersion.put("url", null);
                } else {
                    clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(), clientVersion.getName()));
                }
                // add the client side version to the list
                versions.add(clientVersion);
            }
        }
    }
    return versions;
}
Also used : Version(org.alfresco.service.cmr.version.Version) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Aggregations

Version (org.alfresco.service.cmr.version.Version)39 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)17 Serializable (java.io.Serializable)12 QName (org.alfresco.service.namespace.QName)9 ArrayList (java.util.ArrayList)8 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Set (java.util.Set)6 MapNode (org.alfresco.web.bean.repository.MapNode)5 Locale (java.util.Locale)4 Map (java.util.Map)4 Node (org.alfresco.rest.api.model.Node)4 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)4 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 PropertyMap (org.alfresco.util.PropertyMap)3 Collection (java.util.Collection)2