Search in sources :

Example 1 with NamespaceService

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

the class PutMethodTest 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);
    authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
    personService = ctx.getBean("PersonService", PersonService.class);
    lockService = ctx.getBean("LockService", LockService.class);
    contentService = ctx.getBean("contentService", ContentService.class);
    checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
    permissionService = ctx.getBean("PermissionService", PermissionService.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
    actionService = ctx.getBean("ActionService", ActionService.class);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();
    txn = transactionService.getUserTransaction();
    txn.begin();
    createUser(USER1_NAME);
    createUser(USER2_NAME);
    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
    InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
    davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
    testDataIS.close();
    davLockInfoAdminIS.close();
    davLockInfoUser2IS.close();
    // Create a test file with versionable aspect and content
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    versionableDocName = "doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, versionableDocName);
    versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
    nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
}
Also used : Serializable(java.io.Serializable) TransactionService(org.alfresco.service.transaction.TransactionService) LockService(org.alfresco.service.cmr.lock.LockService) HashMap(java.util.HashMap) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) ContentService(org.alfresco.service.cmr.repository.ContentService) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) PermissionService(org.alfresco.service.cmr.security.PermissionService) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) ActionService(org.alfresco.service.cmr.action.ActionService) Before(org.junit.Before)

Example 2 with NamespaceService

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

the class TemplateSupportBean method selectDictionaryNodes.

/**
 * @param fc         FacesContext
 * @param xpath      XPath to the nodes to select
 * @param noSelectionLabel   Label to add to the list if no items are found in the search
 * @param mimetype   Optional mimetype of items to add, will not add to list if mimetype does not match
 *
 * @return List of SelectItem wrapper objects for the nodes found at the XPath
 */
private List<SelectItem> selectDictionaryNodes(FacesContext fc, String xpath, String noSelectionLabel, String mimetype) {
    List<SelectItem> wrappers = null;
    try {
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
        List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, 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);
                    ContentData content = (ContentData) childNode.getProperties().get(ContentModel.PROP_CONTENT);
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT) && (mimetype == null || mimetype.equals(content.getMimetype()))) {
                        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(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), noSelectionLabel)));
    return wrappers;
}
Also used : 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) ContentData(org.alfresco.service.cmr.repository.ContentData) NamespaceService(org.alfresco.service.namespace.NamespaceService) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node)

Example 3 with NamespaceService

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

the class SearchContext method fromXML.

/**
 * Restore a SearchContext from an XML definition
 *
 * @param xml     XML format SearchContext @see #toXML()
 */
public SearchContext fromXML(String xml) {
    try {
        NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
        // get the root element
        SAXReader reader = new SAXReader();
        Document document = reader.read(new StringReader(xml));
        Element rootElement = document.getRootElement();
        Element textElement = rootElement.element(ELEMENT_TEXT);
        if (textElement != null) {
            this.text = textElement.getText();
        }
        Element modeElement = rootElement.element(ELEMENT_MODE);
        if (modeElement != null) {
            this.mode = Integer.parseInt(modeElement.getText());
        }
        Element locationElement = rootElement.element(ELEMENT_LOCATION);
        if (locationElement != null) {
            this.location = locationElement.getText();
        }
        Element categoriesElement = rootElement.element(ELEMENT_CATEGORIES);
        if (categoriesElement != null) {
            List<String> categories = new ArrayList<String>(4);
            for (Iterator i = categoriesElement.elementIterator(ELEMENT_CATEGORY); i.hasNext(); ) /**/
            {
                Element categoryElement = (Element) i.next();
                categories.add(categoryElement.getText());
            }
            this.categories = categories.toArray(this.categories);
        }
        Element contentTypeElement = rootElement.element(ELEMENT_CONTENT_TYPE);
        if (contentTypeElement != null) {
            this.contentType = contentTypeElement.getText();
        }
        Element folderTypeElement = rootElement.element(ELEMENT_FOLDER_TYPE);
        if (folderTypeElement != null) {
            this.folderType = folderTypeElement.getText();
        }
        Element mimetypeElement = rootElement.element(ELEMENT_MIMETYPE);
        if (mimetypeElement != null) {
            this.mimeType = mimetypeElement.getText();
        }
        Element attributesElement = rootElement.element(ELEMENT_ATTRIBUTES);
        if (attributesElement != null) {
            for (Iterator i = attributesElement.elementIterator(ELEMENT_ATTRIBUTE); i.hasNext(); ) /**/
            {
                Element attrElement = (Element) i.next();
                QName qname = QName.createQName(attrElement.attributeValue(ELEMENT_NAME), ns);
                addAttributeQuery(qname, attrElement.getText());
            }
        }
        Element rangesElement = rootElement.element(ELEMENT_RANGES);
        if (rangesElement != null) {
            for (Iterator i = rangesElement.elementIterator(ELEMENT_RANGE); i.hasNext(); ) /**/
            {
                Element rangeElement = (Element) i.next();
                Element lowerElement = rangeElement.element(ELEMENT_LOWER);
                Element upperElement = rangeElement.element(ELEMENT_UPPER);
                Element incElement = rangeElement.element(ELEMENT_INCLUSIVE);
                if (lowerElement != null && upperElement != null && incElement != null) {
                    QName qname = QName.createQName(rangeElement.attributeValue(ELEMENT_NAME), ns);
                    addRangeQuery(qname, lowerElement.getText(), upperElement.getText(), Boolean.parseBoolean(incElement.getText()));
                }
            }
        }
        Element valuesElement = rootElement.element(ELEMENT_FIXED_VALUES);
        if (valuesElement != null) {
            for (Iterator i = valuesElement.elementIterator(ELEMENT_VALUE); i.hasNext(); ) /**/
            {
                Element valueElement = (Element) i.next();
                QName qname = QName.createQName(valueElement.attributeValue(ELEMENT_NAME), ns);
                addFixedValueQuery(qname, valueElement.getText());
            }
        }
    } catch (Throwable err) {
        throw new AlfrescoRuntimeException("Failed to import SearchContext from XML.", err);
    }
    return this;
}
Also used : NamespaceService(org.alfresco.service.namespace.NamespaceService) SAXReader(org.dom4j.io.SAXReader) QName(org.alfresco.service.namespace.QName) Element(org.dom4j.Element) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Document(org.dom4j.Document)

Example 4 with NamespaceService

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

the class SearchContext method getPathFromSpaceRef.

/**
 * Generate a search XPATH pointing to the specified node, optionally return an XPATH
 * that includes the child nodes.
 *
 * @param ref         Of the node to generate path too
 * @param children   Whether to include children of the node
 *
 * @return the path
 */
public static String getPathFromSpaceRef(NodeRef ref, boolean children) {
    FacesContext context = FacesContext.getCurrentInstance();
    Path path = Repository.getServiceRegistry(context).getNodeService().getPath(ref);
    NamespaceService ns = Repository.getServiceRegistry(context).getNamespaceService();
    StringBuilder buf = new StringBuilder(64);
    for (int i = 0; i < path.size(); i++) {
        String elementString = "";
        Path.Element element = path.get(i);
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                Collection<String> prefixes = ns.getPrefixes(elementRef.getQName().getNamespaceURI());
                if (prefixes.size() > 0) {
                    elementString = '/' + (String) prefixes.iterator().next() + ':' + ISO9075.encode(elementRef.getQName().getLocalName());
                }
            }
        }
        buf.append(elementString);
    }
    if (children == true) {
        // append syntax to get all children of the path
        buf.append("//*");
    } else {
        // append syntax to just represent the path, not the children
        buf.append("/*");
    }
    return buf.toString();
}
Also used : Path(org.alfresco.service.cmr.repository.Path) FacesContext(javax.faces.context.FacesContext) NamespaceService(org.alfresco.service.namespace.NamespaceService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 5 with NamespaceService

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

the class ContextListener method contextInitialized.

/**
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    // make sure that the spaces store in the repository exists
    this.servletContext = event.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    // If no context has been initialised, exit silently so config changes can be made
    if (ctx == null) {
        return;
    }
    ServiceRegistry registry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    TransactionService transactionService = registry.getTransactionService();
    NodeService nodeService = registry.getNodeService();
    SearchService searchService = registry.getSearchService();
    NamespaceService namespaceService = registry.getNamespaceService();
    AuthenticationContext authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
    // repo bootstrap code for our client
    UserTransaction tx = null;
    NodeRef companySpaceNodeRef = null;
    try {
        tx = transactionService.getUserTransaction();
        tx.begin();
        authenticationContext.setSystemUserAsCurrentUser();
        // get and setup the initial store ref and root path from config
        StoreRef storeRef = Repository.getStoreRef(servletContext);
        // get root path
        String rootPath = Application.getRootPath(servletContext);
        // Extract company space id and store it in the Application object
        companySpaceNodeRef = Repository.getCompanyRoot(nodeService, searchService, namespaceService, storeRef, rootPath);
        Application.setCompanyRootId(companySpaceNodeRef.getId());
        // commit the transaction
        tx.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        logger.error("Failed to initialise ", e);
        throw new AlfrescoRuntimeException("Failed to initialise ", e);
    } finally {
        try {
            authenticationContext.clearCurrentSecurityContext();
        } catch (Exception ex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) AuthenticationContext(org.alfresco.repo.security.authentication.AuthenticationContext) TransactionService(org.alfresco.service.transaction.TransactionService) NodeService(org.alfresco.service.cmr.repository.NodeService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ServiceRegistry(org.alfresco.service.ServiceRegistry)

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