Search in sources :

Example 6 with MapNode

use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.

the class DocumentDetailsDialog method getVersionHistory.

/**
 * Returns a list of objects representing the versions of the
 * current document
 *
 * @return List of previous versions
 */
public List getVersionHistory() {
    List<MapNode> versions = new ArrayList<MapNode>();
    if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE)) {
        VersionHistory history = this.getVersionService().getVersionHistory(getDocument().getNodeRef());
        if (history != null) {
            for (Version version : history.getAllVersions()) {
                // create a map node representation of the version
                MapNode clientVersion = new MapNode(version.getFrozenStateNodeRef());
                clientVersion.put("versionLabel", version.getVersionLabel());
                clientVersion.put("notes", version.getDescription());
                clientVersion.put("author", version.getCreator());
                clientVersion.put("versionDate", version.getCreatedDate());
                if (getDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
                    clientVersion.put("url", null);
                } else {
                    clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(), clientVersion.getName()));
                }
                // add the client side version to the list
                versions.add(clientVersion);
            }
        }
    }
    return versions;
}
Also used : Version(org.alfresco.service.cmr.version.Version) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 7 with MapNode

use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.

the class DocumentDetailsDialog method initEditionHistory.

/**
 * Constructs a list of objects representing the editions of the
 * logical document
 *
 * @return List of editions
 */
@SuppressWarnings("unused")
private List<SingleEditionBean> initEditionHistory() {
    // get the mlContainer
    NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
    // get all editions (in descending order - ie. most recent first)
    List<Version> orderedEditionList = new ArrayList<Version>(getEditionService().getEditions(mlContainer).getAllVersions());
    // the list of Single Edition Bean to return
    editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
    boolean firstEdition = true;
    // for each edition, init a SingleEditionBean
    for (Version edition : orderedEditionList) {
        SingleEditionBean editionBean = new SingleEditionBean();
        MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
        String editionLabel = edition.getVersionLabel();
        if (firstEdition) {
            editionLabel += " (" + Application.getMessage(FacesContext.getCurrentInstance(), MSG_CURRENT) + ")";
        }
        clientEdition.put("editionLabel", editionLabel);
        clientEdition.put("editionNotes", edition.getDescription());
        clientEdition.put("editionAuthor", edition.getCreator());
        clientEdition.put("editionDate", edition.getCreatedDate());
        // Set the edition of the edition bean
        editionBean.setEdition(clientEdition);
        // get translations
        List<VersionHistory> translationHistories = null;
        if (firstEdition) {
            // Get the translations because the current edition doesn't content link with its
            // translation in the version store.
            Map<Locale, NodeRef> translations = getMultilingualContentService().getTranslations(mlContainer);
            translationHistories = new ArrayList<VersionHistory>(translations.size());
            for (NodeRef translation : translations.values()) {
                translationHistories.add(getVersionService().getVersionHistory(translation));
            }
        } else {
            translationHistories = getEditionService().getVersionedTranslations(edition);
        }
        // add each translation in the SingleEditionBean
        for (VersionHistory versionHistory : translationHistories) {
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
            // the last version (ie. most recent) is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            // get the properties of the lastVersion
            Map<QName, Serializable> lastVersionProperties = getEditionService().getVersionedMetadatas(lastVersion);
            Locale language = (Locale) lastVersionProperties.get(ContentModel.PROP_LOCALE);
            // create a map node representation of the last version
            MapNode clientLastVersion = new MapNode(lastVersion.getFrozenStateNodeRef());
            clientLastVersion.put("versionName", lastVersionProperties.get(ContentModel.PROP_NAME));
            // use the node service for the description to ensure that the returned value is a text and not a MLText
            clientLastVersion.put("versionDescription", getNodeService().getProperty(lastVersion.getFrozenStateNodeRef(), ContentModel.PROP_DESCRIPTION));
            clientLastVersion.put("versionAuthor", lastVersionProperties.get(ContentModel.PROP_AUTHOR));
            clientLastVersion.put("versionCreatedDate", lastVersionProperties.get(ContentModel.PROP_CREATED));
            clientLastVersion.put("versionModifiedDate", lastVersionProperties.get(ContentModel.PROP_MODIFIED));
            clientLastVersion.put("versionLanguage", this.getContentFilterLanguagesService().convertToNewISOCode(language.getLanguage()).toUpperCase());
            if (getNodeService().hasAspect(lastVersion.getFrozenStateNodeRef(), ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
                clientLastVersion.put("versionUrl", null);
            } else {
                clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
            }
            // add a translation of the editionBean
            editionBean.addTranslations(clientLastVersion);
        }
        editionHistory.add(editionBean);
        firstEdition = false;
    }
    return editionHistory;
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) SingleEditionBean(org.alfresco.web.bean.ml.SingleEditionBean)

Example 8 with MapNode

use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.

the class BrowseBean method getParentNodes.

/**
 * Page accessed bean method to get the parent container nodes currently being browsed
 *
 * @return List of parent container Node objects for the current browse location
 */
public List<Node> getParentNodes(NodeRef currNodeRef) {
    if (this.parentContainerNodes == null) {
        long startTime = 0;
        if (logger.isDebugEnabled())
            startTime = System.currentTimeMillis();
        UserTransaction tx = null;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            NodeRef parentRef = getNodeService().getPrimaryParent(currNodeRef).getParentRef();
            List<FileInfo> children = this.getFileFolderService().list(parentRef);
            this.parentContainerNodes = new ArrayList<Node>(children.size());
            for (FileInfo fileInfo : children) {
                // create our Node representation from the NodeRef
                NodeRef nodeRef = fileInfo.getNodeRef();
                // find it's type so we can see if it's a node we are interested in
                QName type = this.getNodeService().getType(nodeRef);
                // make sure the type is defined in the data dictionary
                TypeDefinition typeDef = this.getDictionaryService().getType(type);
                if (typeDef != null) {
                    MapNode node = null;
                    // look for Space folder node
                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        // create our Node representation
                        node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.parentContainerNodes.add(node);
                    } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                        // create our Folder Link Node representation
                        node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.parentContainerNodes.add(node);
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                }
            }
            // commit the transaction
            tx.commit();
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
            this.parentContainerNodes = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (Throwable err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
            this.parentContainerNodes = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
        if (logger.isDebugEnabled()) {
            long endTime = System.currentTimeMillis();
            logger.debug("Time to query and build map parent nodes: " + (endTime - startTime) + "ms");
        }
    }
    List<Node> result = this.parentContainerNodes;
    return result;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 9 with MapNode

use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.

the class BrowseBean method setupMLContainerContentAction.

/**
 * Action event called by all actions that need to setup a <b>Multilingual</b> Content Document context on the
 * BrowseBean before an action page/wizard is called. The context will be a Node in
 * setDocument() which can be retrieved on the action page from BrowseBean.getDocument().
 */
public void setupMLContainerContentAction(ActionEvent event) {
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    NodeRef translation = new NodeRef(Repository.getStoreRef(), id);
    // remember the bean from which the action comes
    FacesContext fc = FacesContext.getCurrentInstance();
    DocumentDetailsDialog docDetails = (DocumentDetailsDialog) FacesHelper.getManagedBean(fc, "DocumentDetailsDialog");
    docDetails.setTranslationDocument(new MapNode(translation));
    MultilingualManageDialog mmDialog = (MultilingualManageDialog) FacesHelper.getManagedBean(fc, "MultilingualManageDialog");
    mmDialog.setTranslationDocument(docDetails.getTranslationDocument());
    // set the ml container as the current document
    NodeRef mlContainer = getMultilingualContentService().getTranslationContainer(translation);
    setupContentAction(mlContainer.getId(), true);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) MultilingualManageDialog(org.alfresco.web.bean.ml.MultilingualManageDialog) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) DocumentDetailsDialog(org.alfresco.web.bean.content.DocumentDetailsDialog) MapNode(org.alfresco.web.bean.repository.MapNode)

Example 10 with MapNode

use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.

the class BrowseBean method searchBrowseNodes.

/**
 * Search for a list of nodes using the specific search context
 *
 * @param searchContext    To use to perform the search
 */
private void searchBrowseNodes(SearchContext searchContext) {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    // get the searcher object to build the query
    String query = searchContext.buildQuery(getMinimumSearchLength());
    if (query == null) {
        // failed to build a valid query, the user probably did not enter the
        // minimum text required to construct a valid search
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_SEARCH_MINIMUM), new Object[] { getMinimumSearchLength() }));
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        return;
    }
    // perform the search against the repo
    UserTransaction tx = null;
    ResultSet results = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        // build up the search parameters
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(query);
        sp.addStore(Repository.getStoreRef());
        // limit search results size as configured
        int searchLimit = Application.getClientConfig(FacesContext.getCurrentInstance()).getSearchMaxResults();
        if (searchLimit > 0) {
            sp.setLimitBy(LimitBy.FINAL_SIZE);
            sp.setLimit(searchLimit);
        }
        sp.setBulkFetchEnabled(Application.getClientConfig(FacesContext.getCurrentInstance()).isBulkFetchEnabled());
        results = this.getSearchService().query(sp);
        if (logger.isDebugEnabled())
            logger.debug("Search results returned: " + results.length());
        // create a list of items from the results
        this.containerNodes = new ArrayList<Node>(results.length());
        this.contentNodes = new ArrayList<Node>(results.length());
        if (results.length() != 0) {
            // in case of dynamic config, only lookup once
            Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
            for (ResultSetRow row : results) {
                NodeRef nodeRef = row.getNodeRef();
                if (this.getNodeService().exists(nodeRef)) {
                    // find it's type so we can see if it's a node we are interested in
                    QName type = this.getNodeService().getType(nodeRef);
                    // make sure the type is defined in the data dictionary
                    TypeDefinition typeDef = this.getDictionaryService().getType(type);
                    if (typeDef != null) {
                        MapNode node = null;
                        // look for Space or File nodes
                        if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                            // create our Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            node.addPropertyResolver("path", this.resolverPath);
                            node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                            node.addPropertyResolver("icon", this.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                            this.containerNodes.add(node);
                        } else if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                            // create our Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            setupCommonBindingProperties(node);
                            node.addPropertyResolver("path", this.resolverPath);
                            node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                            this.contentNodes.add(node);
                        } else // look for File Link object node
                        if (ApplicationModel.TYPE_FILELINK.equals(type)) {
                            // create our File Link Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            // only display the user has the permissions to navigate to the target of the link
                            NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                            if (new Node(destRef).hasPermission(PermissionService.READ) == true) {
                                node.addPropertyResolver("url", this.resolverLinkUrl);
                                node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
                                node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
                                node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
                                node.addPropertyResolver("fileType16", this.resolverFileType16);
                                node.addPropertyResolver("fileType32", this.resolverFileType32);
                                node.addPropertyResolver("lang", this.resolverLang);
                                node.addPropertyResolver("path", this.resolverPath);
                                node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                                this.contentNodes.add(node);
                            }
                        } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                            // create our Folder Link Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            // only display the user has the permissions to navigate to the target of the link
                            NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                            if (new Node(destRef).hasPermission(PermissionService.READ) == true) {
                                node.addPropertyResolver("icon", this.resolverSpaceIcon);
                                node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                                node.addPropertyResolver("path", this.resolverPath);
                                node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                                this.containerNodes.add(node);
                            }
                        }
                        // inform any listeners that a Node wrapper has been created
                        if (node != null) {
                            for (NodeEventListener listener : nodeEventListeners) {
                                listener.created(node, type);
                            }
                        }
                    } else {
                        if (logger.isWarnEnabled())
                            logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Missing object returned from search indexes: id = " + nodeRef + " search query: " + query);
                }
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (SearcherException serr) {
        logger.info("Search failed for: " + query, serr);
        Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_QUERY));
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_SEARCH), new Object[] { err.getMessage() }), err);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearcherException(org.alfresco.repo.search.SearcherException) ResultSet(org.alfresco.service.cmr.search.ResultSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Aggregations

MapNode (org.alfresco.web.bean.repository.MapNode)21 NodeRef (org.alfresco.service.cmr.repository.NodeRef)18 Node (org.alfresco.web.bean.repository.Node)12 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)10 UserTransaction (javax.transaction.UserTransaction)9 ArrayList (java.util.ArrayList)8 FacesContext (javax.faces.context.FacesContext)8 QName (org.alfresco.service.namespace.QName)8 AbortProcessingException (javax.faces.event.AbortProcessingException)5 Version (org.alfresco.service.cmr.version.Version)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 Map (java.util.Map)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)4 SearcherException (org.alfresco.repo.search.SearcherException)3 Serializable (java.io.Serializable)2 List (java.util.List)2 PagingRequest (org.alfresco.query.PagingRequest)2