Search in sources :

Example 86 with PropertyMap

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

the class AbstractFeedCleanerTest method createPerson.

private boolean createPerson(String userName) {
    if (this.personService.personExists(userName) == false) {
        // create person properties
        PropertyMap personProps = new PropertyMap();
        personProps.put(ContentModel.PROP_USERNAME, userName);
        personProps.put(ContentModel.PROP_FIRSTNAME, userName);
        personProps.put(ContentModel.PROP_LASTNAME, userName);
        personProps.put(ContentModel.PROP_EMAIL, userName + "@email.com");
        // create person node for user
        this.personService.createPerson(personProps);
        return true;
    }
    // already exists
    return false;
}
Also used : PropertyMap(org.alfresco.util.PropertyMap)

Example 87 with PropertyMap

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

the class AbstractMailActionExecuterTest method createUser.

/**
 * Creates a test user with the specified username and optionally custom email.
 *
 * @param userName String
 * @param email Optional, if not specified assigned to <code>userName + "@email.com"</code>
 * @return NodeRef
 */
private NodeRef createUser(String userName, String email) {
    PropertyMap personProps = new PropertyMap();
    personProps.put(ContentModel.PROP_USERNAME, userName);
    personProps.put(ContentModel.PROP_FIRSTNAME, userName);
    personProps.put(ContentModel.PROP_LASTNAME, userName);
    if (email != null) {
        personProps.put(ContentModel.PROP_EMAIL, email);
    } else {
        personProps.put(ContentModel.PROP_EMAIL, userName + "@email.com");
    }
    return PERSON_SERVICE.createPerson(personProps);
}
Also used : PropertyMap(org.alfresco.util.PropertyMap)

Example 88 with PropertyMap

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

the class FTPServerTest method createUser.

/**
 * create a test user
 * @param userName
 * @param password
 * @param quota
 */
private void createUser(String userName, String password, long quota) {
    if (this.authenticationService.authenticationExists(userName) == false) {
        this.authenticationService.createAuthentication(userName, password.toCharArray());
        PropertyMap ppOne = new PropertyMap(4);
        ppOne.put(ContentModel.PROP_USERNAME, userName);
        ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
        ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
        ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
        ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
        if (quota > 0) {
            ppOne.put(ContentModel.PROP_SIZE_QUOTA, quota);
        }
        this.personService.createPerson(ppOne);
    }
}
Also used : PropertyMap(org.alfresco.util.PropertyMap)

Example 89 with PropertyMap

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

the class DictionaryModelTypeTest method testUpdateDictionaryModelPropertyDelete.

@Test
public void testUpdateDictionaryModelPropertyDelete() throws Exception {
    // just to make sure we don't regress ACE-5852, some tests should run as System
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    try {
        // Check that the model has not yet been loaded into the dictionary
        this.dictionaryService.getModel(TEST_MODEL_ONE);
        fail("This model has not yet been loaded into the dictionary service");
    } catch (DictionaryException exception) {
    // We expect this exception
    }
    // Check that the namespace is not yet in the namespace service
    String uri = this.namespaceService.getNamespaceURI("test1");
    assertNull(uri);
    // Create a model node
    PropertyMap properties = new PropertyMap(1);
    properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
    final NodeRef modelNode = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"), ContentModel.TYPE_DICTIONARY_MODEL, properties).getChildRef();
    assertNotNull(modelNode);
    // Add the model content to the model node
    ContentWriter contentWriter = this.contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true);
    contentWriter.setEncoding("UTF-8");
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
    contentWriter.putContent(MODEL_ONE_MODIFIED_XML);
    // End the transaction to force update
    TestTransaction.flagForCommit();
    TestTransaction.end();
    // create node using new type
    final NodeRef node1 = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Exception {
            // Check that the namespace is in the namespace service
            String uri = namespaceService.getNamespaceURI("test1");
            assertNotNull(uri);
            // Create a model node
            PropertyMap properties = new PropertyMap(1);
            // boolean
            properties.put(QName.createQName("http://www.alfresco.org/test/testmodel1/1.0", "prop2"), "false");
            NodeRef node = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "node1"), QName.createQName("http://www.alfresco.org/test/testmodel1/1.0", "base"), properties).getChildRef();
            assertNotNull(node);
            return node;
        }
    }, false, true);
    final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Exception {
            // Update model
            NodeRef workingCopy = DictionaryModelTypeTest.this.cociService.checkout(modelNode);
            ContentWriter contentWriter2 = DictionaryModelTypeTest.this.contentService.getWriter(workingCopy, ContentModel.PROP_CONTENT, true);
            contentWriter2.putContent(MODEL_ONE_MODIFIED2_XML);
            return workingCopy;
        }
    }, false, true);
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

            public Object execute() throws Exception {
                // Check that the policy has not been fired since we have updated a working copy
                assertEquals("1.1", DictionaryModelTypeTest.this.nodeService.getProperty(workingCopy, ContentModel.PROP_MODEL_VERSION));
                // Check-in the model change
                DictionaryModelTypeTest.this.cociService.checkin(workingCopy, null);
                return null;
            }
        });
        fail("Unexpected - should not be able to update model");
    } catch (AlfrescoRuntimeException are) {
    // expected
    }
    // delete node
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

        public Object execute() throws Exception {
            nodeService.deleteNode(node1);
            return null;
        }
    }, false, true);
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

        public Object execute() throws Exception {
            // Check that the policy has not been fired since we have updated a working copy
            assertEquals("1.1", DictionaryModelTypeTest.this.nodeService.getProperty(workingCopy, ContentModel.PROP_MODEL_VERSION));
            // Check-in the model change
            DictionaryModelTypeTest.this.cociService.checkin(workingCopy, null);
            return null;
        }
    }, false, true);
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

        public Object execute() throws Exception {
            // Now check that the model has been updated
            assertEquals("1.2", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_VERSION));
            return null;
        }
    }, false, true);
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

        public Object execute() throws Exception {
            DictionaryModelTypeTest.this.nodeService.deleteNode(modelNode);
            return null;
        }
    }, false, true);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PropertyMap(org.alfresco.util.PropertyMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException) ExpectedException(org.junit.rules.ExpectedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 90 with PropertyMap

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

the class DictionaryModelTypeTest method testImportingSameNamespaceFails.

/* MNT-15345 test */
@Test
public void testImportingSameNamespaceFails() throws Exception {
    // just to make sure we don't regress ACE-5852, some tests should run as System
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    // Create model
    final NodeRef modelNode = createActiveModel("dictionary/testModel.xml");
    TestTransaction.flagForCommit();
    TestTransaction.end();
    // add second model to introduce self referencing dependency
    TestTransaction.start();
    PropertyMap properties = new PropertyMap(1);
    properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
    final NodeRef modelNode2 = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"), ContentModel.TYPE_DICTIONARY_MODEL, properties).getChildRef();
    TestTransaction.flagForCommit();
    TestTransaction.end();
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            public Void execute() throws Exception {
                ContentWriter contentWriter = DictionaryModelTypeTest.this.contentService.getWriter(modelNode2, ContentModel.PROP_CONTENT, true);
                contentWriter.putContent(Thread.currentThread().getContextClassLoader().getResourceAsStream("dictionary/testModel2.xml"));
                return null;
            }
        });
        fail("Validation should fail as a circular dependency was introduced");
    } catch (AlfrescoRuntimeException e) {
        assertTrue(e.getCause().getMessage().contains("URI mage.model cannot be imported as it is already contained in the model's namespaces"));
    } finally // delete model
    {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

            public Object execute() throws Exception {
                // Delete the model
                DictionaryModelTypeTest.this.nodeService.deleteNode(modelNode);
                return null;
            }
        });
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PropertyMap(org.alfresco.util.PropertyMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException) ExpectedException(org.junit.rules.ExpectedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

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