Search in sources :

Example 16 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.

the class EditDocWebDavEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    FacesContext fc = FacesContext.getCurrentInstance();
    DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
    boolean result = false;
    // if the node is inline editable, the default http behaviour should always be used
    if (dd.isSubClass(node.getType(), ContentModel.TYPE_CONTENT)) {
        if (node.hasAspect(ApplicationModel.ASPECT_INLINEEDITABLE) == false && "webdav".equals(Application.getClientConfig(fc).getEditLinkType())) {
            if ((node.isWorkingCopyOwner() == true && node.getProperties().get(ContentModel.PROP_WORKING_COPY_MODE).equals(EditOnlineDialog.ONLINE_EDITING)) || (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) && node.hasPermission(PermissionService.WRITE)) || (node.isLocked() == false && node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false)) {
                result = true;
            }
        }
    }
    return result;
}
Also used : FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService)

Example 17 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService 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 18 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project SearchServices by Alfresco.

the class MetadataTracker method getShardProperty.

public static QName getShardProperty(String field) {
    AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance();
    NamespaceDAO namespaceDAO = dataModel.getNamespaceDAO();
    DictionaryService dictionaryService = dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT);
    PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition("http://www.alfresco.org/model/content/1.0", namespaceDAO, dictionaryService, field);
    return propertyDef.getName();
}
Also used : NamespaceDAO(org.alfresco.repo.dictionary.NamespaceDAO) CMISStrictDictionaryService(org.alfresco.opencmis.dictionary.CMISStrictDictionaryService) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) AlfrescoSolrDataModel(org.alfresco.solr.AlfrescoSolrDataModel) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 19 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.

the class PickerBean method getFileFolderNodes.

/**
 * Return the JSON objects representing a list of cm:folder and cm:content nodes.
 *
 * IN: "parent" - noderef (can be null) of the parent to retrieve the child nodes for. Null is valid
 *        and specifies the Company Home root as the parent.
 * IN: "child" - non-null value of the child noderef to retrieve the siblings for - the parent value returned
 *        in the JSON response will be the parent of the specified child.
 * IN: "mimetypes" (optional) - if set, a comma separated list of mimetypes to restrict the file list.
 *
 * It is assumed that only files should be selectable, all cm:folder nodes will be marked with the
 * 'selectable:false' property. Therefore the parent (which is a folder) is not selectable.
 *
 * The 16x16 pixel node icon path is output as the 'icon' property for each child, in addition each
 * cm:content node has an property of 'url' for content download.
 */
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void getFileFolderNodes() throws Exception {
    FacesContext fc = FacesContext.getCurrentInstance();
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
        ContentService cs = Repository.getServiceRegistry(fc).getContentService();
        List<ChildAssociationRef> childRefs;
        NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
        NodeRef parentRef = null;
        Map params = fc.getExternalContext().getRequestParameterMap();
        String strChildRef = Utils.encode((String) params.get(PARAM_CHILD));
        if (strChildRef != null && strChildRef.length() != 0) {
            // TODO: check permission on the parent
            NodeRef childRef = new NodeRef(strChildRef);
            parentRef = this.getNodeService().getPrimaryParent(childRef).getParentRef();
        } else {
            // TODO: check permission on the parent
            String strParentRef = Utils.encode((String) params.get(PARAM_PARENT));
            if (strParentRef == null || strParentRef.length() == 0) {
                parentRef = companyHomeRef;
                strParentRef = parentRef.toString();
            } else {
                parentRef = new NodeRef(strParentRef);
            }
        }
        // look for mimetype restriction parameter
        Set<String> mimetypes = null;
        String mimetypeParam = (String) params.get(PARAM_MIMETYPES);
        if (mimetypeParam != null && mimetypeParam.length() != 0) {
            // convert to a set of mimetypes to test each file against
            mimetypes = new HashSet<String>();
            for (StringTokenizer t = new StringTokenizer(mimetypeParam, ","); t.hasMoreTokens(); ) /**/
            {
                mimetypes.add(t.nextToken());
            }
        }
        List<FileInfo> items = this.getFileFolderService().list(parentRef);
        JSONWriter out = new JSONWriter(fc.getResponseWriter());
        out.startObject();
        out.startValue(ID_PARENT);
        out.startObject();
        out.writeValue(ID_ID, parentRef.toString());
        out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), parentRef));
        if (parentRef.equals(companyHomeRef)) {
            out.writeValue(ID_ISROOT, true);
        }
        out.writeValue(ID_SELECTABLE, false);
        out.endObject();
        out.endValue();
        out.startValue(ID_CHILDREN);
        out.startArray();
        for (FileInfo item : items) {
            if (dd.isSubClass(this.getInternalNodeService().getType(item.getNodeRef()), ContentModel.TYPE_FOLDER)) {
                // found a folder
                out.startObject();
                out.writeValue(ID_ID, item.getNodeRef().toString());
                String name = (String) item.getProperties().get(ContentModel.PROP_NAME);
                out.writeValue(ID_NAME, name);
                String icon = (String) item.getProperties().get(ApplicationModel.PROP_ICON);
                out.writeValue(ID_ICON, FOLDER_IMAGE_PREFIX + (icon != null ? icon + "-16.gif" : BrowseBean.SPACE_SMALL_DEFAULT + ".gif"));
                out.writeValue(ID_SELECTABLE, false);
                out.endObject();
            } else {
                // must be a file
                boolean validFile = true;
                if (mimetypes != null) {
                    validFile = false;
                    ContentReader reader = cs.getReader(item.getNodeRef(), ContentModel.PROP_CONTENT);
                    if (reader != null) {
                        String mimetype = reader.getMimetype();
                        validFile = (mimetype != null && mimetypes.contains(mimetype));
                    }
                }
                if (validFile) {
                    out.startObject();
                    out.writeValue(ID_ID, item.getNodeRef().toString());
                    String name = (String) item.getProperties().get(ContentModel.PROP_NAME);
                    out.writeValue(ID_NAME, name);
                    String icon = FileTypeImageUtils.getFileTypeImage(fc, name, FileTypeImageSize.Small);
                    out.writeValue(ID_ICON, icon);
                    out.writeValue(ID_URL, DownloadContentServlet.generateBrowserURL(item.getNodeRef(), name));
                    out.endObject();
                }
            }
        }
        out.endArray();
        out.endValue();
        out.endObject();
        tx.commit();
    } catch (Throwable err) {
        Utils.addErrorMessage("PickerBean exception in getFileFolderNodes()", err);
        fc.getResponseWriter().write("ERROR: " + err.getMessage());
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) JSONWriter(org.springframework.extensions.webscripts.json.JSONWriter) FacesContext(javax.faces.context.FacesContext) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentService(org.alfresco.service.cmr.repository.ContentService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) StringTokenizer(java.util.StringTokenizer) FileInfo(org.alfresco.service.cmr.model.FileInfo) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap)

Example 20 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.

the class UISearchCustomProperties method createComponentsFromConfig.

/**
 * Build the components from the Advanced Search config entries
 *
 * @param context FacesContext
 */
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context) {
    DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
    AdvancedSearchConfigElement config = (AdvancedSearchConfigElement) Application.getConfigService(context).getConfig("Advanced Search").getConfigElement(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID);
    // create an appropriate component for each custom property
    // using the DataDictionary to look-up labels and value types
    String beanBinding = (String) getAttributes().get("bean") + '.' + (String) getAttributes().get("var");
    List<CustomProperty> props = config.getCustomProperties();
    if (props != null) {
        for (CustomProperty property : props) {
            try {
                // try to find the Property definition for the specified Type or Aspect
                PropertyDefinition propDef = null;
                if (property.Type != null) {
                    QName type = Repository.resolveToQName(property.Type);
                    TypeDefinition typeDef = dd.getType(type);
                    if (typeDef == null) {
                        logger.warn("No Type Definition found for: " + property.Type + " - Was an Aspect expected?");
                        continue;
                    }
                    propDef = typeDef.getProperties().get(Repository.resolveToQName(property.Property));
                } else if (property.Aspect != null) {
                    QName aspect = Repository.resolveToQName(property.Aspect);
                    AspectDefinition aspectDef = dd.getAspect(aspect);
                    if (aspectDef == null) {
                        logger.warn("No Aspect Definition found for: " + property.Aspect + " - Was a Type expected?");
                        continue;
                    }
                    propDef = aspectDef.getProperties().get(Repository.resolveToQName(property.Property));
                }
                // if we found a def, then we can build components to represent it
                if (propDef != null) {
                    // resolve display label I18N message
                    String label;
                    if (property.LabelId != null && property.LabelId.length() != 0) {
                        label = Application.getMessage(context, property.LabelId);
                    } else {
                        // or use dictionary label or QName as last resort
                        label = propDef.getTitle(dd) != null ? propDef.getTitle(dd) : propDef.getName().getLocalName();
                    }
                    // special handling for Date and DateTime
                    DataTypeDefinition dataTypeDef = propDef.getDataType();
                    if (DataTypeDefinition.DATE.equals(dataTypeDef.getName()) || DataTypeDefinition.DATETIME.equals(dataTypeDef.getName())) {
                        getChildren().add(generateControl(context, propDef, label, beanBinding));
                    } else {
                        // add ListOfValues constraint components
                        ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
                        if (constraint != null && propDef != null && propDef.isProtected() == false) {
                            getChildren().add(generateCheck(context, propDef, beanBinding));
                            getChildren().add(generateLabel(context, label + ": "));
                        } else {
                            getChildren().add(generateLabel(context, ""));
                            getChildren().add(generateLabel(context, label + ": "));
                        }
                        getChildren().add(generateControl(context, propDef, null, beanBinding));
                    }
                }
            } catch (DictionaryException ddErr) {
                logger.warn("Error building custom properties for Advanced Search: " + ddErr.getMessage());
            }
        }
    }
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QName(org.alfresco.service.namespace.QName) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) AdvancedSearchConfigElement(org.alfresco.web.config.AdvancedSearchConfigElement) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Aggregations

DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)29 FacesContext (javax.faces.context.FacesContext)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 QName (org.alfresco.service.namespace.QName)11 NodeService (org.alfresco.service.cmr.repository.NodeService)8 Node (org.alfresco.web.bean.repository.Node)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)7 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)6 SelectItem (javax.faces.model.SelectItem)5 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)4 QuickSort (org.alfresco.web.data.QuickSort)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ResponseWriter (javax.faces.context.ResponseWriter)3 UserTransaction (javax.transaction.UserTransaction)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3