Search in sources :

Example 1 with PropertyMap

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

the class RecordServiceImpl method createRecord.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createRecord(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, boolean)
 */
@Override
public void createRecord(final NodeRef filePlan, final NodeRef nodeRef, final boolean isLinked) {
    // filePlan can be null. In this case the default RM site will be used.
    ParameterCheck.mandatory("nodeRef", nodeRef);
    ParameterCheck.mandatory("isLinked", isLinked);
    recordCreationSanityCheckOnNode(nodeRef);
    final NodeRef checkedFilePlan = recordCreationSanityCheckOnFilePlan(filePlan);
    invokeBeforeRecordDeclaration(nodeRef);
    // do the work of creating the record as the system user
    AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

        @Override
        public Void doWork() {
            if (!nodeService.hasAspect(nodeRef, ASPECT_RECORD)) {
                // disable delete rules
                ruleService.disableRuleType("outbound");
                try {
                    // get the new record container for the file plan
                    NodeRef newRecordContainer = filePlanService.getUnfiledContainer(checkedFilePlan);
                    if (newRecordContainer == null) {
                        throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
                    }
                    // get the documents readers and writers
                    Pair<Set<String>, Set<String>> readersAndWriters = extendedPermissionService.getReadersAndWriters(nodeRef);
                    // get the current owner
                    String owner = ownableService.getOwner(nodeRef);
                    // get the documents primary parent assoc
                    ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
                    // get the latest version record, if there is one
                    NodeRef latestVersionRecord = getLatestVersionRecord(nodeRef);
                    behaviourFilter.disableBehaviour();
                    try {
                        // move the document into the file plan
                        nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
                    } finally {
                        behaviourFilter.enableBehaviour();
                    }
                    // save the information about the originating details
                    Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(3);
                    aspectProperties.put(PROP_RECORD_ORIGINATING_LOCATION, parentAssoc.getParentRef());
                    aspectProperties.put(PROP_RECORD_ORIGINATING_USER_ID, owner);
                    aspectProperties.put(PROP_RECORD_ORIGINATING_CREATION_DATE, new Date());
                    nodeService.addAspect(nodeRef, ASPECT_RECORD_ORIGINATING_DETAILS, aspectProperties);
                    // make the document a record
                    makeRecord(nodeRef);
                    generateRecordIdentifier(nodeService, identifierService, nodeRef);
                    if (latestVersionRecord != null) {
                        // indicate that this is the 'final' record version
                        PropertyMap versionRecordProps = new PropertyMap(2);
                        versionRecordProps.put(RecordableVersionModel.PROP_VERSION_LABEL, I18NUtil.getMessage(FINAL_VERSION));
                        versionRecordProps.put(RecordableVersionModel.PROP_VERSION_DESCRIPTION, I18NUtil.getMessage(FINAL_DESCRIPTION));
                        nodeService.addAspect(nodeRef, RecordableVersionModel.ASPECT_VERSION_RECORD, versionRecordProps);
                        // link to previous version
                        relationshipService.addRelationship(CUSTOM_REF_VERSIONS.getLocalName(), nodeRef, latestVersionRecord);
                    }
                    if (isLinked) {
                        // turn off rules
                        ruleService.disableRules();
                        try {
                            // maintain the original primary location
                            nodeService.addChild(parentAssoc.getParentRef(), nodeRef, parentAssoc.getTypeQName(), parentAssoc.getQName());
                            // set the extended security
                            extendedSecurityService.set(nodeRef, readersAndWriters);
                        } finally {
                            ruleService.enableRules();
                        }
                    }
                } finally {
                    ruleService.enableRuleType("outbound");
                }
            }
            return null;
        }
    });
    invokeOnRecordDeclaration(nodeRef);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Map(java.util.Map) PropertyMap(org.alfresco.util.PropertyMap) HashMap(java.util.HashMap) Pair(org.alfresco.util.Pair)

Example 2 with PropertyMap

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

the class NotificationServiceHelperSystemTest method setupTestData.

@Override
protected void setupTestData() {
    super.setupTestData();
    retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
            // Create a user
            userName = GUID.generate();
            authenticationService.createAuthentication(userName, "".toCharArray());
            PropertyMap props = new PropertyMap();
            props.put(PROP_USERNAME, userName);
            props.put(PROP_FIRSTNAME, "Test");
            props.put(PROP_LASTNAME, "User");
            props.put(PROP_EMAIL, EMAIL_ADDRESS);
            person = personService.createPerson(props);
            // Find the authority for the given role
            Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE);
            assertNotNull("Notification role could not be retrieved", role);
            String roleGroup = role.getRoleGroupName();
            assertNotNull("Notification role group can not be null.", roleGroup);
            // Add user to notification role group
            authorityService.addAuthority(roleGroup, userName);
            return null;
        }
    });
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role) PropertyMap(org.alfresco.util.PropertyMap)

Example 3 with PropertyMap

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

the class BaseRMWebScriptTestCase method createUser.

protected void createUser(String userName) {
    if (!authenticationService.authenticationExists(userName)) {
        authenticationService.createAuthentication(userName, "PWD".toCharArray());
        PropertyMap ppOne = new PropertyMap(4);
        ppOne.put(ContentModel.PROP_USERNAME, userName);
        ppOne.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, "title" + 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");
        personService.createPerson(ppOne);
    }
}
Also used : PropertyMap(org.alfresco.util.PropertyMap)

Example 4 with PropertyMap

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

the class RMCaveatConfigServiceImplTest method createUser.

protected void createUser(String userName) {
    if (!authenticationService.authenticationExists(userName)) {
        authenticationService.createAuthentication(userName, "PWD".toCharArray());
    }
    if (!personService.personExists(userName)) {
        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");
        personService.createPerson(ppOne);
    }
}
Also used : PropertyMap(org.alfresco.util.PropertyMap)

Example 5 with PropertyMap

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

the class ServiceBaseImpl method getNextCount.

/**
 * Utility method to get the next counter for a node.
 * <p>
 * If the node is not already countable, then rma:countable is added and 0 returned.
 *
 * @param nodeRef   node reference
 * @return int      next counter value
 */
protected int getNextCount(NodeRef nodeRef) {
    int counter = 0;
    if (!nodeService.hasAspect(nodeRef, ASPECT_COUNTABLE)) {
        PropertyMap props = new PropertyMap(1);
        props.put(PROP_COUNT, 1);
        nodeService.addAspect(nodeRef, ASPECT_COUNTABLE, props);
        counter = 1;
    } else {
        Integer value = (Integer) this.nodeService.getProperty(nodeRef, PROP_COUNT);
        if (value != null) {
            counter = value.intValue() + 1;
        } else {
            counter = 1;
        }
        nodeService.setProperty(nodeRef, PROP_COUNT, counter);
    }
    return counter;
}
Also used : PropertyMap(org.alfresco.util.PropertyMap)

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