Search in sources :

Example 16 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 17 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 18 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 19 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)

Example 20 with PropertyMap

use of org.alfresco.util.PropertyMap 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)

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