Search in sources :

Example 21 with NodeService

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

the class DiscussionCutEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    boolean result = super.evaluate(node);
    // if the node in question is a forum...
    if (result && 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);
    }
    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)

Example 22 with NodeService

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

the class BaseMultiValueRenderer method encodeEnd.

/**
 * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    if (component instanceof UIMultiValueEditor) {
        ResponseWriter out = context.getResponseWriter();
        UIMultiValueEditor editor = (UIMultiValueEditor) component;
        // get hold of the node service
        NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
        // render the area between the component and current items list
        renderPostWrappedComponent(context, out, editor);
        // show the currently selected items
        out.write("<tr><td style='padding-top:8px'>");
        out.write(editor.getSelectedItemsMsg());
        out.write("</td></tr>");
        out.write("<tr><td><table cellspacing='0' cellpadding='2' border='0' class='selectedItems'>");
        out.write("<tr><td colspan='2' class='selectedItemsHeader'>");
        out.write(Application.getMessage(context, "name"));
        out.write("</td></tr>");
        List currentItems = (List) editor.getValue();
        ;
        if (currentItems != null && currentItems.size() > 0) {
            for (int x = 0; x < currentItems.size(); x++) {
                Object obj = currentItems.get(x);
                if (obj != null) {
                    if (obj instanceof NodeRef) {
                        if (nodeService.exists((NodeRef) obj)) {
                            renderExistingItem(context, component, out, nodeService, x, obj);
                        } else {
                            // remove invalid NodeRefs from the list
                            currentItems.remove(x);
                        }
                    } else {
                        renderExistingItem(context, component, out, nodeService, x, obj);
                    }
                }
            }
        } else {
            out.write("<tr><td class='selectedItemsRow'>");
            out.write(editor.getNoSelectedItemsMsg());
            out.write("</td></tr>");
        }
        // close tables
        out.write("</table></td></tr></table>\n");
        // output a hidden field containing the current value
        out.write("<input type='hidden' id='");
        out.write(component.getClientId(context));
        out.write("_current_value");
        out.write("' name='");
        out.write(component.getClientId(context));
        out.write("_current_value");
        out.write("' value='");
        if (currentItems != null && currentItems.size() > 0) {
            out.write(currentItems.toString());
        }
        out.write("' />");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) UIMultiValueEditor(org.alfresco.web.ui.repo.component.UIMultiValueEditor) ResponseWriter(javax.faces.context.ResponseWriter) NodeService(org.alfresco.service.cmr.repository.NodeService) List(java.util.List)

Example 23 with NodeService

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

the class NodeDescendantsLinkRenderer method encodeEnd.

/**
 * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    // always check for this flag - as per the spec
    if (component.isRendered() == true) {
        Writer out = context.getResponseWriter();
        UINodeDescendants control = (UINodeDescendants) component;
        // make sure we have a NodeRef from the 'value' property ValueBinding
        Object val = control.getValue();
        if (val instanceof NodeRef == false) {
            throw new IllegalArgumentException("UINodeDescendants component 'value' property must resolve to a NodeRef!");
        }
        NodeRef parentRef = (NodeRef) val;
        // use Spring JSF integration to get the node service bean
        NodeService service = getNodeService(context);
        DictionaryService dd = getDictionaryService(context);
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
            tx.begin();
            // TODO: need a comparator to sort node refs (based on childref qname)
            // as currently the list is returned in a random order per request!
            String separator = (String) component.getAttributes().get("separator");
            if (separator == null) {
                separator = DEFAULT_SEPARATOR;
            }
            // calculate the number of displayed child refs
            if (service.exists(parentRef) == true) {
                List<ChildAssociationRef> childRefs = service.getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
                List<Node> nodes = new ArrayList<Node>(childRefs.size());
                for (int index = 0; index < childRefs.size(); index++) {
                    ChildAssociationRef ref = childRefs.get(index);
                    QName type = service.getType(ref.getChildRef());
                    TypeDefinition typeDef = dd.getType(type);
                    if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        nodes.add(new Node(ref.getChildRef()));
                    }
                }
                QuickSort sorter = new QuickSort(nodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
                // walk each child ref and output a descendant link control for each item
                int total = 0;
                int maximum = nodes.size() > control.getMaxChildren() ? control.getMaxChildren() : nodes.size();
                for (int index = 0; index < maximum; index++) {
                    Node node = nodes.get(index);
                    QName type = service.getType(node.getNodeRef());
                    TypeDefinition typeDef = dd.getType(type);
                    if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        // output separator if appropriate
                        if (total > 0) {
                            out.write(separator);
                        }
                        out.write(renderDescendant(context, control, node.getNodeRef(), false));
                        total++;
                    }
                }
                // do we need to render ellipses to indicate more items than the maximum
                if (control.getShowEllipses() == true && nodes.size() > maximum) {
                    out.write(separator);
                    // TODO: is this the correct way to get the information we need?
                    // e.g. primary parent may not be the correct path? how do we make sure we find
                    // the correct parent and more importantly the correct Display Name value!
                    out.write(renderDescendant(context, control, service.getPrimaryParent(parentRef).getChildRef(), true));
                }
            }
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            throw new RuntimeException(err);
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) Node(org.alfresco.web.bean.repository.Node) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) UINodeDescendants(org.alfresco.web.ui.repo.component.UINodeDescendants) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) Writer(java.io.Writer)

Example 24 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project records-management by Alfresco.

the class RequestInfoUtils method getRecordName.

/**
 * Helper method to extract the record name from the task
 *
 * @param delegateTask  The delegate task
 * @return Returns the name of the record or an empty string if the record name could not be found
 *               (may be because the record has been deleted in the mean time)
 */
public static String getRecordName(DelegateTask delegateTask) {
    ParameterCheck.mandatory("delegateTask", delegateTask);
    String recordName = StringUtils.EMPTY;
    NodeService nodeService = getServiceRegistry().getNodeService();
    ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");
    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(scriptNode.getNodeRef());
    if (childAssocs.size() > 0) {
        NodeRef docRef = childAssocs.get(0).getChildRef();
        recordName = (String) nodeService.getProperty(docRef, ContentModel.PROP_NAME);
    }
    return recordName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 25 with NodeService

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

the class SimpleWorkflowHandler method generateSummary.

public String generateSummary(FacesContext context, IWizardBean wizard, Map<String, Serializable> actionProps) {
    NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
    String approveStepName = (String) actionProps.get(PROP_APPROVE_STEP_NAME);
    String approveAction = (String) actionProps.get(PROP_APPROVE_ACTION);
    NodeRef approveFolder = (NodeRef) actionProps.get(PROP_APPROVE_FOLDER);
    String approveFolderName = Repository.getNameForNode(nodeService, approveFolder);
    String approveMsg = MessageFormat.format(Application.getMessage(context, "action_simple_workflow"), new Object[] { Application.getMessage(context, approveAction), approveFolderName, approveStepName });
    String rejectMsg = null;
    String rejectStep = (String) actionProps.get(PROP_REJECT_STEP_PRESENT);
    if (rejectStep != null && "yes".equals(rejectStep)) {
        String rejectStepName = (String) actionProps.get(PROP_REJECT_STEP_NAME);
        String rejectAction = (String) actionProps.get(PROP_REJECT_ACTION);
        NodeRef rejectFolder = (NodeRef) actionProps.get(PROP_REJECT_FOLDER);
        String rejectFolderName = Repository.getNameForNode(nodeService, rejectFolder);
        rejectMsg = MessageFormat.format(Application.getMessage(context, "action_simple_workflow"), new Object[] { Application.getMessage(context, rejectAction), rejectFolderName, rejectStepName });
    }
    StringBuilder builder = new StringBuilder(approveMsg);
    if (rejectMsg != null) {
        builder.append(" ");
        builder.append(rejectMsg);
    }
    return builder.toString();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService)

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