Search in sources :

Example 71 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 72 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)

Example 73 with PropertyMap

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

the class People method createPerson.

/**
 * Create a Person with the given user name
 *
 * @param userName the user name of the person to create
 * @return the person node (type cm:person) created or null if the user name already exists
 */
public ScriptNode createPerson(String userName) {
    ParameterCheck.mandatoryString("userName", userName);
    ScriptNode person = null;
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_USERNAME, userName);
    if (!personService.personExists(userName)) {
        NodeRef personRef = personService.createPerson(properties);
        person = new ScriptNode(personRef, services, getScope());
    }
    return person;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap)

Example 74 with PropertyMap

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

the class CopyServiceImplTest method testRecursiveCopy.

/**
 * Test a potentially recursive copy
 */
public void testRecursiveCopy() {
    PropertyMap props = new PropertyMap();
    // Need to create a potentially recursive node structure
    props.put(ContentModel.PROP_NODE_UUID, "nodeOne");
    NodeRef nodeOne = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTAINER, props).getChildRef();
    props.put(ContentModel.PROP_NODE_UUID, "nodeTwo");
    NodeRef nodeTwo = nodeService.createNode(nodeOne, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTAINER, props).getChildRef();
    props.put(ContentModel.PROP_NODE_UUID, "nodeThree");
    NodeRef nodeThree = nodeService.createNode(nodeTwo, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTAINER, props).getChildRef();
    // Issue a potentialy recursive copy
    copyService.copy(nodeOne, nodeThree, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, true);
// System.out.println(
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap)

Example 75 with PropertyMap

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

the class CopyServiceImplTest method setUp.

@Override
protected void setUp() throws Exception {
    ctx = ApplicationContextHelper.getApplicationContext();
    if (AlfrescoTransactionSupport.isActualTransactionActive()) {
        fail("Test started with transaction in progress");
    }
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    // Set the services
    transactionService = serviceRegistry.getTransactionService();
    nodeService = (NodeService) ctx.getBean("dbNodeService");
    publicNodeService = serviceRegistry.getNodeService();
    copyService = (CopyService) ctx.getBean("copyService");
    contentService = (ContentService) ctx.getBean("contentService");
    ruleService = (RuleService) ctx.getBean("ruleService");
    actionService = (ActionService) ctx.getBean("actionService");
    permissionService = (PermissionService) ctx.getBean("PermissionService");
    personService = serviceRegistry.getPersonService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    cociService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService");
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    authenticationComponent.setSystemUserAsCurrentUser();
    // Ensure that a transaction is present
    txn = transactionService.getUserTransaction();
    txn.begin();
    // Create the test model
    createTestModel();
    // Create the store and get the root node reference
    storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    // Create the node used for copying
    ChildAssociationRef childAssocRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}test"), TEST_TYPE_QNAME, createTypePropertyBag());
    sourceNodeRef = childAssocRef.getChildRef();
    // Create another bag of properties
    Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
    aspectProperties.put(PROP3_QNAME_MANDATORY, TEST_VALUE_1);
    aspectProperties.put(PROP4_QNAME_OPTIONAL, TEST_VALUE_2);
    // Apply the test aspect
    nodeService.addAspect(sourceNodeRef, TEST_ASPECT_QNAME, aspectProperties);
    nodeService.addAspect(sourceNodeRef, ContentModel.ASPECT_TITLED, null);
    // Add a child
    ChildAssociationRef temp3 = nodeService.createNode(sourceNodeRef, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME, TEST_TYPE_QNAME, createTypePropertyBag());
    childNodeRef = temp3.getChildRef();
    // Add a child that is primary
    ChildAssociationRef temp2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testNonPrimaryChild"), TEST_TYPE_QNAME, createTypePropertyBag());
    nonPrimaryChildNodeRef = temp2.getChildRef();
    nodeService.addChild(sourceNodeRef, nonPrimaryChildNodeRef, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME2);
    // Add a target assoc
    ChildAssociationRef temp = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testAssoc"), TEST_TYPE_QNAME, createTypePropertyBag());
    targetNodeRef = temp.getChildRef();
    nodeService.createAssociation(sourceNodeRef, targetNodeRef, TEST_ASSOC_TYPE_QNAME);
    // Create a node we can use as the destination in a copy
    Map<QName, Serializable> destinationProps = new HashMap<QName, Serializable>();
    destinationProps.put(PROP1_QNAME_MANDATORY, TEST_VALUE_1);
    destinationProps.put(PROP5_QNAME_MANDATORY, TEST_VALUE_3);
    destinationProps.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    ChildAssociationRef temp5 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testDestinationNode"), TEST_TYPE_QNAME, destinationProps);
    destinationNodeRef = temp5.getChildRef();
    // Create two users, for use as part of
    // the permission related tests
    authenticationService.createAuthentication(USER_1, "PWD".toCharArray());
    authenticationService.createAuthentication(USER_2, "PWD".toCharArray());
    PropertyMap personProperties = new PropertyMap();
    personProperties.put(ContentModel.PROP_USERNAME, USER_1);
    personProperties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, "title" + USER_1);
    personProperties.put(ContentModel.PROP_FIRSTNAME, "firstName");
    personProperties.put(ContentModel.PROP_LASTNAME, "lastName");
    personProperties.put(ContentModel.PROP_EMAIL, USER_1 + "@example.com");
    personProperties.put(ContentModel.PROP_JOBTITLE, "jobTitle");
    personService.createPerson(personProperties);
    personProperties = new PropertyMap();
    personProperties.put(ContentModel.PROP_USERNAME, USER_2);
    personProperties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, "title" + USER_2);
    personProperties.put(ContentModel.PROP_FIRSTNAME, "firstName");
    personProperties.put(ContentModel.PROP_LASTNAME, "lastName");
    personProperties.put(ContentModel.PROP_EMAIL, USER_2 + "@example.com");
    personProperties.put(ContentModel.PROP_JOBTITLE, "jobTitle");
    personService.createPerson(personProperties);
}
Also used : Serializable(java.io.Serializable) PropertyMap(org.alfresco.util.PropertyMap) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ServiceRegistry(org.alfresco.service.ServiceRegistry) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

PropertyMap (org.alfresco.util.PropertyMap)111 NodeRef (org.alfresco.service.cmr.repository.NodeRef)43 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)15 Test (org.junit.Test)14 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)13 QName (org.alfresco.service.namespace.QName)11 Serializable (java.io.Serializable)9 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)8 ContentReader (org.alfresco.service.cmr.repository.ContentReader)8 BaseSpringTest (org.alfresco.util.BaseSpringTest)8 FileContentReader (org.alfresco.repo.content.filestore.FileContentReader)7 DictionaryException (org.alfresco.service.cmr.dictionary.DictionaryException)7 ExpectedException (org.junit.rules.ExpectedException)7 ApplicationContext (org.springframework.context.ApplicationContext)7 StoreRef (org.alfresco.service.cmr.repository.StoreRef)6 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)5 NodeService (org.alfresco.service.cmr.repository.NodeService)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4