Search in sources :

Example 71 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getGlobalSearchesRef.

/**
 * @return the cached reference to the global Saved Searches folder
 */
protected NodeRef getGlobalSearchesRef() {
    if (properties.getGlobalSearchesRef() == null) {
        FacesContext fc = FacesContext.getCurrentInstance();
        String xpath = Application.getRootPath(fc) + "/" + Application.getGlossaryFolderName(fc) + "/" + Application.getSavedSearchesFolderName(fc);
        List<NodeRef> results = null;
        try {
            results = getSearchService().selectNodes(getNodeService().getRootNode(Repository.getStoreRef()), xpath, null, getNamespaceService(), false);
        } catch (AccessDeniedException err) {
        // ignore and return null
        }
        if (results != null && results.size() == 1) {
            properties.setGlobalSearchesRef(results.get(0));
        }
    }
    return properties.getGlobalSearchesRef();
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException)

Example 72 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getSavedSearches.

/**
 * @return list of saved searches as SelectItem objects
 */
public List<SelectItem> getSavedSearches() {
    List<SelectItem> savedSearches = properties.getCachedSavedSearches().get();
    if (savedSearches == null) {
        FacesContext fc = FacesContext.getCurrentInstance();
        ServiceRegistry services = Repository.getServiceRegistry(fc);
        // get the searches list from the current user or global searches location
        NodeRef searchesRef = null;
        if (SAVED_SEARCHES_USER.equals(properties.getSavedSearchMode()) == true) {
            searchesRef = getUserSearchesRef();
        } else if (SAVED_SEARCHES_GLOBAL.equals(properties.getSavedSearchMode()) == true) {
            searchesRef = getGlobalSearchesRef();
        }
        // read the content nodes under the folder
        if (searchesRef != null) {
            DictionaryService dd = services.getDictionaryService();
            List<ChildAssociationRef> childRefs = getNodeService().getChildAssocs(searchesRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            savedSearches = new ArrayList<SelectItem>(childRefs.size() + 1);
            if (childRefs.size() != 0) {
                for (ChildAssociationRef ref : childRefs) {
                    Node childNode = new Node(ref.getChildRef());
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
                        savedSearches.add(new SelectItem(childNode.getId(), childNode.getName()));
                    }
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(savedSearches, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            }
        } else {
            // handle missing/access denied folder case
            savedSearches = new ArrayList<SelectItem>(1);
        }
        // add an entry (at the start) to instruct the user to select a saved search
        savedSearches.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), MSG_SELECT_SAVED_SEARCH)));
        // store in the cache (will auto-expire)
        properties.getCachedSavedSearches().put(savedSearches);
    }
    return savedSearches;
}
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) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ServiceRegistry(org.alfresco.service.ServiceRegistry) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 73 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getContentTypes.

/**
 * @return Returns a list of content object types to allow the user to select from
 */
public List<SelectItem> getContentTypes() {
    if ((properties.getContentTypes() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
        // add the well known cm:content object type by default
        properties.setContentTypes(new ArrayList<SelectItem>(5));
        properties.getContentTypes().add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), dictionaryService.getType(ContentModel.TYPE_CONTENT).getTitle(dictionaryService)));
        // add any configured content sub-types to the list
        List<String> types = getSearchConfig().getContentTypes();
        if (types != null) {
            for (String type : types) {
                QName idQName = Repository.resolveToQName(type);
                if (idQName != null) {
                    TypeDefinition typeDef = dictionaryService.getType(idQName);
                    if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT)) {
                        // try and get label from the dictionary
                        String label = typeDef.getTitle(dictionaryService);
                        // else just use the localname
                        if (label == null) {
                            label = idQName.getLocalName();
                        }
                        properties.getContentTypes().add(new SelectItem(idQName.toString(), label));
                    }
                }
            }
        }
    }
    return properties.getContentTypes();
}
Also used : FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 74 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class EditSearchDialog method saveEditSearchOK.

public String saveEditSearchOK(FacesContext newContext, String newOutcome) {
    String outcome = newOutcome;
    final SearchContext search = this.navigator.getSearchContext();
    if (search != null) {
        try {
            final FacesContext context = newContext;
            RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

                public Object execute() throws Throwable {
                    // handle Edit e.g. Overwrite of existing search
                    // detect if was previously selected saved search (e.g.
                    // NodeRef not null)
                    NodeRef searchRef = new NodeRef(Repository.getStoreRef(), properties.getSavedSearch());
                    if (getNodeService().exists(searchRef)) {
                        Map<QName, Serializable> props = getNodeService().getProperties(searchRef);
                        props.put(ContentModel.PROP_NAME, properties.getSearchName());
                        props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
                        getNodeService().setProperties(searchRef, props);
                        ContentService contentService = Repository.getServiceRegistry(context).getContentService();
                        ContentWriter writer = contentService.getWriter(searchRef, ContentModel.PROP_CONTENT, true);
                        // get a writer to our new node ready for XML
                        // content
                        writer.setMimetype(MimetypeMap.MIMETYPE_XML);
                        writer.setEncoding("UTF-8");
                        // output an XML serialized version of the
                        // SearchContext object
                        writer.putContent(search.toXML());
                    }
                    return null;
                }
            };
            callback.execute();
            properties.getCachedSavedSearches().clear();
            properties.setSavedSearch(null);
        } catch (Throwable e) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(newContext, MSG_ERROR_SAVE_SEARCH), e.getMessage()), e);
            outcome = null;
            this.isFinished = false;
            ReportedException.throwIfNecessary(e);
        }
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ContentService(org.alfresco.service.cmr.repository.ContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 75 with FacesContext

use of javax.faces.context.FacesContext 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)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15