Search in sources :

Example 16 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class Repository method setupBreadcrumbLocation.

/**
 * Sets up the breadcrumb location representation for the given node in
 * the given list.
 *
 * @param context FacesContext
 * @param navBean NavigationBean instance
 * @param location The location list to setup
 * @param node The Node being navigated to
 */
public static void setupBreadcrumbLocation(FacesContext context, NavigationBean navBean, List<IBreadcrumbHandler> location, NodeRef node) {
    // make the sure the given list is empty
    location.clear();
    // get required services
    NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
    DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
    PermissionService permsService = Repository.getServiceRegistry(context).getPermissionService();
    // add the given node to start
    String nodeName = Repository.getNameForNode(nodeService, node);
    location.add(navBean.new NavigationBreadcrumbHandler(node, nodeName));
    // get the given node's parent node
    NodeRef parent = nodeService.getPrimaryParent(node).getParentRef();
    while (parent != null) {
        // check the user can read the parent node
        if (permsService.hasPermission(parent, PermissionService.READ) == AccessStatus.ALLOWED) {
            // get the grand parent so we can check for the root node
            NodeRef grandParent = nodeService.getPrimaryParent(parent).getParentRef();
            if (grandParent != null) {
                // check that the node is actually a folder type, content can have children!
                QName parentType = nodeService.getType(parent);
                if (dictionaryService.isSubClass(parentType, ContentModel.TYPE_FOLDER)) {
                    // if it's a folder add the location to the breadcrumb
                    String parentName = Repository.getNameForNode(nodeService, parent);
                    location.add(0, navBean.new NavigationBreadcrumbHandler(parent, parentName));
                }
            }
            parent = grandParent;
        } else {
            // the user does not have Read permission above this point so stop!
            break;
        }
    }
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService)

Example 17 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class MultilingualUtils method canAddChildrenToPivotSpace.

/**
 * Returns true if the current user has enough right to add a content to the space
 * where the pivot translation is located in.
 *
 * @param multlingualDocument Node
 * @param fc FacesContext
 * @return boolean
 */
public static boolean canAddChildrenToPivotSpace(Node multlingualDocument, FacesContext fc) {
    MultilingualContentService mlservice = getMultilingualContentService(fc);
    NodeService nodeService = getNodeService(fc);
    // get the pivot translation and get the space where it's located
    NodeRef pivot = mlservice.getPivotTranslation(multlingualDocument.getNodeRef());
    NodeRef space = nodeService.getPrimaryParent(pivot).getParentRef();
    // return if the current user can add a content to the space of the pivot
    return new Node(space).hasPermission(PermissionService.ADD_CHILDREN);
}
Also used : MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) Node(org.alfresco.web.bean.repository.Node)

Example 18 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class GuestTemplateContentServlet method buildModel.

@Override
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef) {
    // setup the guest user to pass to the build model helper method
    AuthenticationService auth = (AuthenticationService) services.getAuthenticationService();
    PersonService personService = (PersonService) services.getPersonService();
    NodeService nodeService = (NodeService) services.getNodeService();
    NodeRef guestRef = personService.getPerson(AuthenticationUtil.getGuestUserName());
    User guestUser = new User(AuthenticationUtil.getGuestUserName(), auth.getCurrentTicket(), guestRef);
    NodeRef guestHomeRef = (NodeRef) nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER);
    if (nodeService.exists(guestHomeRef) == false) {
        throw new InvalidNodeRefException(guestHomeRef);
    }
    guestUser.setHomeSpaceId(guestHomeRef.getId());
    // build the default model
    return DefaultModelHelper.buildDefaultModel(services, guestUser, templateRef, this.imageResolver);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) User(org.alfresco.web.bean.repository.User) PersonService(org.alfresco.service.cmr.security.PersonService) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 19 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class DiscussNodeEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    boolean result = false;
    if (node.hasAspect(ForumModel.ASPECT_DISCUSSABLE)) {
        NodeService nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
        List<ChildAssociationRef> children = nodeService.getChildAssocs(node.getNodeRef(), ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
        // make sure there is one visible child association for the node
        if (children.size() == 1) {
            result = true;
        }
    }
    return result;
}
Also used : NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 20 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.

the class DiscussionCopyEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    boolean result = true;
    // if the node in question is a forum...
    if (node.getType().equals(ForumModel.TYPE_FORUM)) {
        // get the association type
        FacesContext context = FacesContext.getCurrentInstance();
        NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
        ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(node.getNodeRef());
        QName assocType = parentAssoc.getTypeQName();
        // only allow the action if the association type is not the discussion assoc
        result = (assocType.equals(ForumModel.ASSOC_DISCUSSION) == false);
    }
    // impossible to copy a translation without content.
    if (result && node.getAspects().contains(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
        result = false;
    }
    if (!node.hasPermission(PermissionService.READ)) {
        result = false;
    }
    return result;
}
Also used : FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

NodeService (org.alfresco.service.cmr.repository.NodeService)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)15 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)11 ResponseWriter (javax.faces.context.ResponseWriter)10 IOException (java.io.IOException)8 UserTransaction (javax.transaction.UserTransaction)8 ServiceRegistry (org.alfresco.service.ServiceRegistry)8 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 PermissionService (org.alfresco.service.cmr.security.PermissionService)7 PersonService (org.alfresco.service.cmr.security.PersonService)7 SearchService (org.alfresco.service.cmr.search.SearchService)6 ArrayList (java.util.ArrayList)5 ResourceBundle (java.util.ResourceBundle)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 Path (org.alfresco.service.cmr.repository.Path)5 TransactionService (org.alfresco.service.transaction.TransactionService)5