Search in sources :

Example 1 with ConfigurableService

use of org.alfresco.repo.configuration.ConfigurableService in project acs-community-packaging by Alfresco.

the class User method getUserPreferencesRef.

/**
 * Get or create the node used to store user preferences.
 * Utilises the 'configurable' aspect on the Person linked to this user.
 */
synchronized NodeRef getUserPreferencesRef(WebApplicationContext context) {
    final ServiceRegistry registry = (ServiceRegistry) context.getBean("ServiceRegistry");
    final NodeService nodeService = registry.getNodeService();
    final SearchService searchService = registry.getSearchService();
    final NamespaceService namespaceService = registry.getNamespaceService();
    final TransactionService txService = registry.getTransactionService();
    final ConfigurableService configurableService = (ConfigurableService) context.getBean("ConfigurableService");
    RetryingTransactionHelper txnHelper = registry.getTransactionService().getRetryingTransactionHelper();
    return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            NodeRef prefRef = null;
            NodeRef person = getPerson();
            if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false) {
                // if the repository is in read-only mode just return null
                if (txService.isReadOnly()) {
                    return null;
                } else {
                    // create the configuration folder for this Person node
                    configurableService.makeConfigurable(person);
                }
            }
            // target of the assoc is the configurations folder ref
            NodeRef configRef = configurableService.getConfigurationFolder(person);
            if (configRef == null) {
                throw new IllegalStateException("Unable to find associated 'configurations' folder for node: " + person);
            }
            String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
            List<NodeRef> nodes = searchService.selectNodes(configRef, xpath, null, namespaceService, false);
            if (nodes.size() == 1) {
                prefRef = nodes.get(0);
            } else {
                // create the preferences Node for this user (if repo is not read-only)
                if (txService.isReadOnly() == false) {
                    ChildAssociationRef childRef = nodeService.createNode(configRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"), ContentModel.TYPE_CMOBJECT);
                    prefRef = childRef.getChildRef();
                }
            }
            return prefRef;
        }
    }, txService.isReadOnly());
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) List(java.util.List) ServiceRegistry(org.alfresco.service.ServiceRegistry) ConfigurableService(org.alfresco.repo.configuration.ConfigurableService)

Aggregations

List (java.util.List)1 ConfigurableService (org.alfresco.repo.configuration.ConfigurableService)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 SearchService (org.alfresco.service.cmr.search.SearchService)1 NamespaceService (org.alfresco.service.namespace.NamespaceService)1 TransactionService (org.alfresco.service.transaction.TransactionService)1