Search in sources :

Example 16 with MapNode

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

the class DeleteUserDialog method search.

public String search() {
    if (this.searchCriteria == null || this.searchCriteria.length() == 0) {
        this.users = Collections.<Node>emptyList();
    } else {
        FacesContext context = FacesContext.getCurrentInstance();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // define the query to find people by their first or last name
            String search = ISO9075.encode(this.searchCriteria);
            List<Pair<QName, String>> filter = Utils.generatePersonFilter(search);
            if (logger.isDebugEnabled()) {
                logger.debug("Query filter: " + filter);
            }
            List<PersonInfo> persons = getPersonService().getPeople(filter, true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)).getPage();
            if (logger.isDebugEnabled()) {
                logger.debug("Found " + persons.size() + " users");
            }
            this.users = new ArrayList<Node>(persons.size());
            for (PersonInfo person : persons) {
                // create our Node representation
                MapNode node = new MapNode(person.getNodeRef());
                // set data binding properties
                // this will also force initialisation of the props now during the UserTransaction
                // it is much better for performance to do this now rather than during page bind
                Map<String, Object> props = node.getProperties();
                props.put("fullName", ((String) props.get("firstName")) + ' ' + ((String) props.get("lastName")));
                NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
                if (homeFolderNodeRef != null) {
                    props.put("homeSpace", homeFolderNodeRef);
                }
                this.users.add(node);
            }
            // commit the transaction
            tx.commit();
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { "root" }));
            this.users = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (Exception err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
            this.users = Collections.<Node>emptyList();
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    // return null to stay on the same page
    return null;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) PersonInfo(org.alfresco.service.cmr.security.PersonService.PersonInfo) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) PagingRequest(org.alfresco.query.PagingRequest) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ReportedException(org.alfresco.web.ui.common.ReportedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Pair(org.alfresco.util.Pair)

Example 17 with MapNode

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

the class EmailSpaceUsersDialog method buildAuthorityMap.

// ------------------------------------------------------------------------------
// Private helpers
/**
 * Build a Map representing a user/group with a set of useful property values required
 * by the UIUserGroupPicker UI component.
 *
 * @param authority     User/Group authority
 * @param roles         Role text for the authority
 *
 * @return Map
 */
private Map buildAuthorityMap(String authority, String roles) {
    Map node = null;
    if (AuthorityType.getAuthorityType(authority) == AuthorityType.GUEST || this.getPersonService().personExists(authority)) {
        NodeRef nodeRef = this.getPersonService().getPerson(authority);
        if (nodeRef != null) {
            // create our Node representation
            node = new MapNode(nodeRef);
            // set data binding properties
            // this will also force initialisation of the props now during the UserTransaction
            // it is much better for performance to do this now rather than during page bind
            Map<String, Object> props = ((MapNode) node).getProperties();
            props.put(PROP_FULLNAME, ((String) props.get("firstName")) + ' ' + ((String) props.get("lastName")));
            props.put(PROP_ICON, WebResources.IMAGE_PERSON);
            props.put(PROP_ISGROUP, false);
        }
    } else if (AuthorityType.getAuthorityType(authority) == AuthorityType.GROUP) {
        // need a map (dummy node) to represent props for this Group Authority
        node = new HashMap<String, Object>(8, 1.0f);
        String groupDisplayName = this.authorityService.getAuthorityDisplayName(authority);
        if (groupDisplayName == null || groupDisplayName.length() == 0) {
            if (authority.startsWith(PermissionService.GROUP_PREFIX) == true) {
                groupDisplayName = authority.substring(PermissionService.GROUP_PREFIX.length());
            } else {
                groupDisplayName = authority;
            }
        }
        node.put(PROP_FULLNAME, groupDisplayName);
        node.put(PROP_USERNAME, authority);
        node.put(PROP_ID, authority);
        node.put(PROP_ICON, WebResources.IMAGE_GROUP);
        node.put(PROP_ISGROUP, true);
    }
    if (node != null) {
        // add the common properties
        node.put(PROP_ROLES, roles);
        node.put(PROP_PARENT, null);
        node.put(PROP_EXPANDED, false);
        if (this.userGroupLookup.get(authority) != null) {
            // this authority already exists in the list somewhere else - mark as duplicate
            node.put(PROP_DUPLICATE, true);
            node.put(PROP_SELECTED, false);
        } else {
            // add to table for the first time, not a duplicate
            this.userGroupLookup.put(authority, node);
            node.put(PROP_DUPLICATE, false);
            node.put(PROP_SELECTED, true);
        }
    }
    return node;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) MapNode(org.alfresco.web.bean.repository.MapNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with MapNode

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

the class TrashcanDialog method getItems.

/**
 * @return the list of deleted items to display
 */
public List<Node> getItems() {
    // to get deleted items from deleted items store
    // use a search to find the items - also filters by name/username
    List<Node> itemNodes = null;
    UserTransaction tx = null;
    ResultSet results = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        // get the root node to the deleted items store
        if (getArchiveRootRef() != null && property.isShowItems()) {
            String query = buildSearchQuery();
            SearchParameters sp = new SearchParameters();
            sp.setLanguage(SearchService.LANGUAGE_LUCENE);
            sp.setQuery(query);
            // the Archived Node store
            sp.addStore(getArchiveRootRef().getStoreRef());
            results = getSearchService().query(sp);
            itemNodes = new ArrayList<Node>(results.length());
        }
        if (results != null && results.length() != 0) {
            for (ResultSetRow row : results) {
                NodeRef nodeRef = row.getNodeRef();
                if (getNodeService().exists(nodeRef)) {
                    QName type = getNodeService().getType(nodeRef);
                    MapNode node = new MapNode(nodeRef, getNodeService(), false);
                    node.addPropertyResolver("locationPath", resolverLocationPath);
                    node.addPropertyResolver("displayPath", resolverDisplayPath);
                    node.addPropertyResolver("deletedDate", resolverDeletedDate);
                    node.addPropertyResolver("deletedBy", resolverDeletedBy);
                    node.addPropertyResolver("isFolder", resolverIsFolder);
                    if (getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        node.addPropertyResolver("typeIcon", this.resolverSmallIcon);
                    } else {
                        node.addPropertyResolver("typeIcon", this.resolverFileType16);
                    }
                    itemNodes.add(node);
                }
            }
        }
        tx.commit();
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), new Object[] { err.getMessage() }), err);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    property.setListedItems((itemNodes != null ? itemNodes : Collections.<Node>emptyList()));
    return property.getListedItems();
}
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) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 19 with MapNode

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

the class VersionedDocumentDetailsDialog 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>();
    for (Version version : this.versionHistory.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 (getFrozenStateDocument().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)

Example 20 with MapNode

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

the class VersionedDocumentDetailsDialog method getTranslations.

/**
 * Returns a list of objects representing the translations of the given version of the mlContainer
 *
 * @return List of translations
 */
@SuppressWarnings("unchecked")
public List getTranslations() {
    // get the version of the mlContainer and its translations
    List<VersionHistory> translationsList = getEditionService().getVersionedTranslations(this.documentEdition);
    Map<Locale, NodeRef> translationNodeRef;
    // if translation size == 0, the edition is the current edition and the translations are not yet attached.
    if (translationsList.size() == 0) {
        // the selection edition is the current: use the multilingual content service
        translationNodeRef = getMultilingualContentService().getTranslations(this.documentEdition.getVersionedNodeRef());
    } else {
        translationNodeRef = new HashMap<Locale, NodeRef>(translationsList.size());
        // get the last (most recent) version of the translation in the given lang of the edition
        for (VersionHistory history : translationsList) {
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(history.getAllVersions());
            // the last (most recent) version is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            // fill the list of translation
            if (lastVersion != null) {
                NodeRef versionNodeRef = lastVersion.getFrozenStateNodeRef();
                Locale locale = (Locale) getNodeService().getProperty(versionNodeRef, ContentModel.PROP_LOCALE);
                translationNodeRef.put(locale, versionNodeRef);
            }
        }
    }
    // the list of client-side translation to return
    List<MapNode> translations = new ArrayList<MapNode>(translationNodeRef.size());
    for (Map.Entry<Locale, NodeRef> entry : translationNodeRef.entrySet()) {
        Locale locale = entry.getKey();
        NodeRef nodeRef = entry.getValue();
        // create a map node representation of the translation
        MapNode mapNode = new MapNode(nodeRef);
        String lgge = (locale != null) ? // convert the locale into new ISO codes
        getContentFilterLanguagesService().convertToNewISOCode(locale.getLanguage()).toUpperCase() : null;
        mapNode.put("name", getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME));
        mapNode.put("language", lgge);
        mapNode.put("url", DownloadContentServlet.generateBrowserURL(nodeRef, mapNode.getName()));
        mapNode.put("notEmpty", new Boolean(!getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)));
        // add the client side version to the list
        translations.add(mapNode);
    }
    return translations;
}
Also used : Locale(java.util.Locale) 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) HashMap(java.util.HashMap) Map(java.util.Map)

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