Search in sources :

Example 36 with PropertyMap

use of org.alfresco.util.PropertyMap in project records-management by Alfresco.

the class RecordableVersionServiceImpl method createNewRecordedVersion.

/**
 * Creates a new recorded version
 *
 * @param sourceTypeRef source type name
 * @param versionHistoryRef version history reference
 * @param standardVersionProperties standard version properties
 * @param versionProperties version properties
 * @param versionNumber version number
 * @param nodeDetails policy scope
 * @return {@link NodeRef} record version
 */
protected NodeRef createNewRecordedVersion(QName sourceTypeRef, NodeRef versionHistoryRef, Map<QName, Serializable> standardVersionProperties, Map<String, Serializable> versionProperties, int versionNumber, PolicyScope nodeDetails) {
    NodeRef versionNodeRef = null;
    // Disable auto-version behaviour
    policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
    // disable other behaviours that we don't want to trigger during this process
    policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
    policyBehaviourFilter.disableBehaviour(ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    // disable model security check
    modelSecurityService.disable();
    // disable property editable check
    recordService.disablePropertyEditableCheck();
    try {
        // get the destination file plan
        final NodeRef filePlan = (NodeRef) versionProperties.get(KEY_FILE_PLAN);
        if (filePlan == null) {
            throw new AlfrescoRuntimeException("Can't create a new recorded version, because no file plan has been specified in the version properties.");
        }
        // create a copy of the source node and place in the file plan
        final NodeRef nodeRef = (NodeRef) standardVersionProperties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF);
        cmObjectType.disableCopy();
        try {
            // create record
            final NodeRef record = recordService.createRecordFromCopy(filePlan, nodeRef);
            // apply version record aspect to record
            final PropertyMap versionRecordProps = new PropertyMap(3);
            versionRecordProps.put(PROP_VERSIONED_NODEREF, nodeRef);
            versionRecordProps.put(RecordableVersionModel.PROP_VERSION_LABEL, standardVersionProperties.get(QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.PROP_VERSION_LABEL)));
            versionRecordProps.put(RecordableVersionModel.PROP_VERSION_DESCRIPTION, standardVersionProperties.get(QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.PROP_VERSION_DESCRIPTION)));
            // run as system as we can't be sure if the user has add aspect rights
            authenticationUtil.runAsSystem(new RunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    nodeService.addAspect(record, ASPECT_VERSION_RECORD, versionRecordProps);
                    return null;
                }
            });
            // wire record up to previous record
            linkToPreviousVersionRecord(nodeRef, record);
            // create version nodeRef
            ChildAssociationRef childAssocRef = dbNodeService.createNode(versionHistoryRef, Version2Model.CHILD_QNAME_VERSIONS, QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.CHILD_VERSIONS + "-" + versionNumber), sourceTypeRef, null);
            versionNodeRef = childAssocRef.getChildRef();
            // add aspect with the standard version properties to the 'version' node
            nodeService.addAspect(versionNodeRef, Version2Model.ASPECT_VERSION, standardVersionProperties);
            // add the recordedVersion aspect with link to record
            nodeService.addAspect(versionNodeRef, ASPECT_RECORDED_VERSION, Collections.singletonMap(PROP_RECORD_NODE_REF, (Serializable) record));
            // freeze auditable aspect information
            freezeAuditableAspect(nodeRef, versionNodeRef);
        } finally {
            cmObjectType.enableCopy();
        }
    } finally {
        // enable model security check
        modelSecurityService.enable();
        // enable property editable check
        recordService.enablePropertyEditableCheck();
        // Enable behaviours
        this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
        this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
        this.policyBehaviourFilter.enableBehaviour(ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    }
    // If the auditable aspect is not there then add it to the 'version' node (after original aspects have been frozen)
    if (!dbNodeService.hasAspect(versionNodeRef, ContentModel.ASPECT_AUDITABLE)) {
        dbNodeService.addAspect(versionNodeRef, ContentModel.ASPECT_AUDITABLE, null);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("createNewRecordedVersion created (" + versionNumber + ") " + versionNodeRef);
    }
    return versionNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) PropertyMap(org.alfresco.util.PropertyMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ReservedVersionNameException(org.alfresco.service.cmr.version.ReservedVersionNameException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 37 with PropertyMap

use of org.alfresco.util.PropertyMap in project records-management by Alfresco.

the class RecordableVersionsBaseTest method prepareContent.

protected void prepareContent(NodeRef content) {
    // add titled aspect
    PropertyMap titledProperties = new PropertyMap(2);
    titledProperties.put(ContentModel.PROP_TITLE, "document title");
    titledProperties.put(ContentModel.PROP_DESCRIPTION, "document description");
    nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProperties);
    // add ownable aspect
    PropertyMap ownableProperties = new PropertyMap(1);
    ownableProperties.put(ContentModel.PROP_OWNER, OWNER);
    nodeService.addAspect(content, ContentModel.ASPECT_OWNABLE, ownableProperties);
    // add Dublin core aspect
    PropertyMap dublinCoreProperties = new PropertyMap(2);
    dublinCoreProperties.put(QNAME_PUBLISHER, PUBLISHER);
    dublinCoreProperties.put(QNAME_SUBJECT, SUBJECT);
    nodeService.addAspect(content, ContentModel.ASPECT_DUBLINCORE, dublinCoreProperties);
    // add content
    ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-8");
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.putContent(CONTENT);
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PropertyMap(org.alfresco.util.PropertyMap)

Example 38 with PropertyMap

use of org.alfresco.util.PropertyMap in project records-management by Alfresco.

the class AutoRecordableVersionsTest method testVersionRecordsRelated.

/**
 * Given that all revisions will be automatically recorded,
 * When I update a document 3 times,
 * Then all 3 created records will be related together using the "VersionedBy" relationship
 */
public void testVersionRecordsRelated() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator, false) {

        /**
         * given *
         */
        public void given() throws Exception {
            doTestInTransaction(new VoidTest() {

                @Override
                public void runImpl() throws Exception {
                    // set the recordable version policy
                    PropertyMap recordableVersionProperties = new PropertyMap(1);
                    recordableVersionProperties.put(PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
                    recordableVersionProperties.put(PROP_FILE_PLAN, filePlan);
                    nodeService.addAspect(dmDocument, RecordableVersionModel.ASPECT_VERSIONABLE, recordableVersionProperties);
                    // make the node versionable
                    PropertyMap versionableProperties = new PropertyMap(1);
                    versionableProperties.put(ContentModel.PROP_INITIAL_VERSION, false);
                    nodeService.addAspect(dmDocument, ContentModel.ASPECT_VERSIONABLE, versionableProperties);
                }
            });
        }

        /**
         * when *
         */
        public void when() {
            // update the content 3 times
            updateContent();
            updateContent();
            updateContent();
        }

        /**
         * then
         */
        public void then() {
            doTestInTransaction(new VoidTest() {

                @Override
                public void runImpl() throws Exception {
                    // check that the record has been recorded
                    checkRecordedVersion(dmDocument, null, "0.3");
                    Version version = versionService.getCurrentVersion(dmDocument);
                    NodeRef record = recordableVersionService.getVersionRecord(version);
                    boolean foundPrevious = false;
                    Set<Relationship> relationships = relationshipService.getRelationshipsFrom(record);
                    assertNotNull(relationships);
                    assertEquals(1, relationships.size());
                    for (Relationship relationship : relationships) {
                        if (relationship.getUniqueName().equals(CUSTOM_REF_VERSIONS.getLocalName())) {
                            NodeRef previousVersionRecord = relationship.getTarget();
                            assertNotNull(previousVersionRecord);
                            foundPrevious = true;
                        }
                    }
                    assertTrue(foundPrevious);
                }
            });
        }

        /**
         * Helper method to update content of dmDocument
         */
        private void updateContent() {
            doTestInTransaction(new VoidTest() {

                @Override
                public void runImpl() throws Exception {
                    ContentWriter writer = contentService.getWriter(dmDocument, ContentModel.PROP_CONTENT, true);
                    writer.putContent(MY_NEW_CONTENT);
                }
            });
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PropertyMap(org.alfresco.util.PropertyMap) Version(org.alfresco.service.cmr.version.Version) Relationship(org.alfresco.module.org_alfresco_module_rm.relationship.Relationship)

Aggregations

PropertyMap (org.alfresco.util.PropertyMap)38 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 Serializable (java.io.Serializable)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 HashMap (java.util.HashMap)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 Version (org.alfresco.service.cmr.version.Version)2 QName (org.alfresco.service.namespace.QName)2 Date (java.util.Date)1 Map (java.util.Map)1 Set (java.util.Set)1 Relationship (org.alfresco.module.org_alfresco_module_rm.relationship.Relationship)1 Role (org.alfresco.module.org_alfresco_module_rm.role.Role)1 Repository (org.alfresco.repo.model.Repository)1 AuthenticationComponent (org.alfresco.repo.security.authentication.AuthenticationComponent)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 ContentService (org.alfresco.service.cmr.repository.ContentService)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)1