Search in sources :

Example 6 with NamespaceService

use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.

the class BaseInviteUsersWizard method getEmailTemplates.

/**
 * @return Returns the list of email templates for user notification
 */
public List<SelectItem> getEmailTemplates() {
    List<SelectItem> wrappers = null;
    try {
        FacesContext fc = FacesContext.getCurrentInstance();
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
        List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, getEmailTemplateXPath(), null, resolver, false);
        wrappers = new ArrayList<SelectItem>(results.size() + 1);
        if (results.size() != 0) {
            DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
            for (NodeRef ref : results) {
                if (this.getNodeService().exists(ref) == true) {
                    Node childNode = new Node(ref);
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
                        wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
                    }
                }
            }
            // make sure the list is sorted by the label
            QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
            sorter.sort();
        }
    } catch (AccessDeniedException accessErr) {
    // ignore the result if we cannot access the root
    }
    // add an entry (at the start) to instruct the user to select an item
    if (wrappers == null) {
        wrappers = new ArrayList<SelectItem>(1);
    }
    wrappers.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
    return wrappers;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NamespaceService(org.alfresco.service.namespace.NamespaceService) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node)

Example 7 with NamespaceService

use of org.alfresco.service.namespace.NamespaceService in project acs-community-packaging by Alfresco.

the class SearchContext method toXML.

/**
 * @return this SearchContext as XML
 *
 * Example:
 * <code>
 * <?xml version="1.0" encoding="UTF-8"?>
 * <search>
 *    <text>CDATA</text>
 *    <mode>int</mode>
 *    <location>XPath</location>
 *    <categories>
 *       <category>XPath</category>
 *    </categories>
 *    <content-type>String</content-type>
 *    <folder-type>String</folder-type>
 *    <mimetype>String</mimetype>
 *    <attributes>
 *       <attribute name="String">String</attribute>
 *    </attributes>
 *    <ranges>
 *       <range name="String">
 *          <lower>String</lower>
 *          <upper>String</upper>
 *          <inclusive>boolean</inclusive>
 *       </range>
 *    </ranges>
 *    <fixed-values>
 *       <value name="String">String</value>
 *    </fixed-values>
 *    <query>CDATA</query>
 * </search>
 * </code>
 */
public String toXML() {
    try {
        NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
        Document doc = DocumentHelper.createDocument();
        Element root = doc.addElement(ELEMENT_SEARCH);
        root.addElement(ELEMENT_TEXT).addCDATA(this.text);
        root.addElement(ELEMENT_MODE).addText(Integer.toString(this.mode));
        if (this.location != null) {
            root.addElement(ELEMENT_LOCATION).addText(this.location);
        }
        Element categories = root.addElement(ELEMENT_CATEGORIES);
        for (String path : this.categories) {
            categories.addElement(ELEMENT_CATEGORY).addText(path);
        }
        if (this.contentType != null) {
            root.addElement(ELEMENT_CONTENT_TYPE).addText(this.contentType);
        }
        if (this.folderType != null) {
            root.addElement(ELEMENT_FOLDER_TYPE).addText(this.folderType);
        }
        if (this.mimeType != null && this.mimeType.length() != 0) {
            root.addElement(ELEMENT_MIMETYPE).addText(this.mimeType);
        }
        Element attributes = root.addElement(ELEMENT_ATTRIBUTES);
        for (QName attrName : this.queryAttributes.keySet()) {
            attributes.addElement(ELEMENT_ATTRIBUTE).addAttribute(ELEMENT_NAME, attrName.toPrefixString(ns)).addCDATA(this.queryAttributes.get(attrName));
        }
        Element ranges = root.addElement(ELEMENT_RANGES);
        for (QName rangeName : this.rangeAttributes.keySet()) {
            RangeProperties rangeProps = this.rangeAttributes.get(rangeName);
            Element range = ranges.addElement(ELEMENT_RANGE);
            range.addAttribute(ELEMENT_NAME, rangeName.toPrefixString(ns));
            range.addElement(ELEMENT_LOWER).addText(rangeProps.lower);
            range.addElement(ELEMENT_UPPER).addText(rangeProps.upper);
            range.addElement(ELEMENT_INCLUSIVE).addText(Boolean.toString(rangeProps.inclusive));
        }
        Element values = root.addElement(ELEMENT_FIXED_VALUES);
        for (QName valueName : this.queryFixedValues.keySet()) {
            values.addElement(ELEMENT_VALUE).addAttribute(ELEMENT_NAME, valueName.toPrefixString(ns)).addCDATA(this.queryFixedValues.get(valueName));
        }
        // outputing the full lucene query may be useful for some situations
        Element query = root.addElement(ELEMENT_QUERY);
        String queryString = buildQuery(0);
        if (queryString != null) {
            query.addCDATA(queryString);
        }
        StringWriter out = new StringWriter(1024);
        XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
        writer.setWriter(out);
        writer.write(doc);
        return out.toString();
    } catch (Throwable err) {
        throw new AlfrescoRuntimeException("Failed to export SearchContext to XML.", err);
    }
}
Also used : NamespaceService(org.alfresco.service.namespace.NamespaceService) StringWriter(java.io.StringWriter) QName(org.alfresco.service.namespace.QName) Element(org.dom4j.Element) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter)

Example 8 with NamespaceService

use of org.alfresco.service.namespace.NamespaceService 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)

Example 9 with NamespaceService

use of org.alfresco.service.namespace.NamespaceService in project alfresco-remote-api by Alfresco.

the class WebDAVonContentUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    searchService = ctx.getBean("SearchService", SearchService.class);
    fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
    lockService = ctx.getBean("LockService", LockService.class);
    policyComponent = ctx.getBean("policyComponent", PolicyComponent.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_XML);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoFile = IOUtils.toByteArray(davLockInfoIS);
    testDataIS.close();
    davLockInfoIS.close();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : PolicyComponent(org.alfresco.repo.policy.PolicyComponent) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) NamespaceService(org.alfresco.service.namespace.NamespaceService) InputStream(java.io.InputStream) SearchService(org.alfresco.service.cmr.search.SearchService) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) Before(org.junit.Before)

Example 10 with NamespaceService

use of org.alfresco.service.namespace.NamespaceService in project alfresco-remote-api by Alfresco.

the class TestEnterpriseAtomPubTCK method setup.

@Before
public void setup() throws Exception {
    JettyComponent jetty = getTestFixture().getJettyComponent();
    final SearchService searchService = (SearchService) jetty.getApplicationContext().getBean("searchService");
    ;
    final NodeService nodeService = (NodeService) jetty.getApplicationContext().getBean("nodeService");
    final FileFolderService fileFolderService = (FileFolderService) jetty.getApplicationContext().getBean("fileFolderService");
    final NamespaceService namespaceService = (NamespaceService) jetty.getApplicationContext().getBean("namespaceService");
    final TransactionService transactionService = (TransactionService) jetty.getApplicationContext().getBean("transactionService");
    final String name = "abc" + System.currentTimeMillis();
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
            Repository repositoryHelper = (Repository) jetty.getApplicationContext().getBean("repositoryHelper");
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            fileFolderService.create(companyHome, name, ContentModel.TYPE_FOLDER).getNodeRef();
            return null;
        }
    }, false, true);
    int port = jetty.getPort();
    Map<String, String> cmisParameters = new HashMap<String, String>();
    cmisParameters.put(TestParameters.DEFAULT_RELATIONSHIP_TYPE, "R:cm:replaces");
    cmisParameters.put(TestParameters.DEFAULT_TEST_FOLDER_PARENT, "/" + name);
    clientContext = new OpenCMISClientContext(BindingType.ATOMPUB, MessageFormat.format(CMIS_URL, "localhost", String.valueOf(port), "alfresco"), "admin", "admin", cmisParameters, jetty.getApplicationContext());
    overrideVersionableAspectProperties(jetty.getApplicationContext());
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) HashMap(java.util.HashMap) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) JettyComponent(org.alfresco.repo.web.util.JettyComponent) OpenCMISClientContext(org.alfresco.opencmis.OpenCMISClientContext) Before(org.junit.Before)

Aggregations

NamespaceService (org.alfresco.service.namespace.NamespaceService)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 NodeService (org.alfresco.service.cmr.repository.NodeService)5 SearchService (org.alfresco.service.cmr.search.SearchService)5 TransactionService (org.alfresco.service.transaction.TransactionService)5 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)3 QName (org.alfresco.service.namespace.QName)3 Before (org.junit.Before)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 FacesContext (javax.faces.context.FacesContext)2 SelectItem (javax.faces.model.SelectItem)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 ServiceRegistry (org.alfresco.service.ServiceRegistry)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 LockService (org.alfresco.service.cmr.lock.LockService)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 Node (org.alfresco.web.bean.repository.Node)2 QuickSort (org.alfresco.web.data.QuickSort)2