Search in sources :

Example 1 with CustomProperty

use of org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getCustomPropertyLookup.

/**
 * Helper map to lookup custom property QName strings against a DataTypeDefinition
 *
 * @return custom property lookup Map
 */
private Map<String, DataTypeDefinition> getCustomPropertyLookup() {
    if ((properties.getCustomPropertyLookup() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        properties.setCustomPropertyLookup(new HashMap<String, DataTypeDefinition>(7, 1.0f));
        List<CustomProperty> customProps = getSearchConfig().getCustomProperties();
        if (customProps != null) {
            DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
            for (CustomProperty customProp : customProps) {
                PropertyDefinition propDef = null;
                QName propQName = Repository.resolveToQName(customProp.Property);
                if (customProp.Type != null) {
                    QName type = Repository.resolveToQName(customProp.Type);
                    TypeDefinition typeDef = dd.getType(type);
                    propDef = typeDef.getProperties().get(propQName);
                } else if (customProp.Aspect != null) {
                    QName aspect = Repository.resolveToQName(customProp.Aspect);
                    AspectDefinition aspectDef = dd.getAspect(aspect);
                    propDef = aspectDef.getProperties().get(propQName);
                }
                if (propQName != null && propDef != null) {
                    properties.getCustomPropertyLookup().put(propQName.toString(), propDef.getDataType());
                }
            }
        }
    }
    return properties.getCustomPropertyLookup();
}
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) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 2 with CustomProperty

use of org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty 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)

Example 3 with CustomProperty

use of org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty in project acs-community-packaging by Alfresco.

the class AdvancedSearchElementReader method parse.

/**
 * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
 */
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
    AdvancedSearchConfigElement configElement = null;
    if (element != null) {
        String name = element.getName();
        if (name.equals(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID) == false) {
            throw new ConfigException("AdvancedSearchElementReader can only parse " + AdvancedSearchConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + name + "'");
        }
        configElement = new AdvancedSearchConfigElement();
        // get the list of content types
        Element contentTypes = element.element(ELEMENT_CONTENTTYPES);
        if (contentTypes != null) {
            Iterator<Element> typesItr = contentTypes.elementIterator(ELEMENT_TYPE);
            List<String> types = new ArrayList<String>(5);
            while (typesItr.hasNext()) {
                Element contentType = typesItr.next();
                String type = contentType.attributeValue(ATTRIBUTE_NAME);
                if (type != null) {
                    types.add(type);
                }
            }
            configElement.setContentTypes(types);
        }
        // get the list of folder types
        Element folderTypes = element.element(ELEMENT_FOLDERTYPES);
        if (folderTypes != null) {
            Iterator<Element> typesItr = folderTypes.elementIterator(ELEMENT_TYPE);
            List<String> types = new ArrayList<String>(5);
            while (typesItr.hasNext()) {
                Element folderType = typesItr.next();
                String type = folderType.attributeValue(ATTRIBUTE_NAME);
                if (type != null) {
                    types.add(type);
                }
            }
            configElement.setFolderTypes(types);
        }
        // get the list of custom properties to display
        Element customProps = element.element(ELEMENT_CUSTOMPROPS);
        if (customProps != null) {
            Iterator<Element> propsItr = customProps.elementIterator(ELEMENT_METADATA);
            List<CustomProperty> props = new ArrayList<CustomProperty>(5);
            while (propsItr.hasNext()) {
                Element propElement = propsItr.next();
                String type = propElement.attributeValue(ATTRIBUTE_TYPE);
                String aspect = propElement.attributeValue(ATTRIBUTE_ASPECT);
                String prop = propElement.attributeValue(ATTRIBUTE_PROPERTY);
                String labelId = propElement.attributeValue(ATTRIBUTE_DISPLAYLABEL);
                props.add(new AdvancedSearchConfigElement.CustomProperty(type, aspect, prop, labelId));
            }
            configElement.setCustomProperties(props);
        }
    }
    return configElement;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) ArrayList(java.util.ArrayList) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) ConfigException(org.springframework.extensions.config.ConfigException)

Aggregations

CustomProperty (org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty)3 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)2 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2 QName (org.alfresco.service.namespace.QName)2 ArrayList (java.util.ArrayList)1 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)1 DictionaryException (org.alfresco.service.cmr.dictionary.DictionaryException)1 AdvancedSearchConfigElement (org.alfresco.web.config.AdvancedSearchConfigElement)1 Element (org.dom4j.Element)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1 ConfigException (org.springframework.extensions.config.ConfigException)1