Search in sources :

Example 6 with DataTypeDefinition

use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project records-management by Alfresco.

the class RecordsManagementTypeFormFilterUnitTest method mockPropertyDefintionMap.

/**
 * Helper method to createa a mock property definition map
 */
private Map<QName, PropertyDefinition> mockPropertyDefintionMap(int size) {
    Map<QName, PropertyDefinition> properties = new HashMap<QName, PropertyDefinition>(size);
    for (int i = 0; i < size; i++) {
        QName name = generateQName(RM_URI);
        PropertyDefinition propDef = mock(PropertyDefinition.class);
        when(propDef.getName()).thenReturn(name);
        DataTypeDefinition mockDataTypeDefinition = mock(DataTypeDefinition.class);
        when(mockDataTypeDefinition.getName()).thenReturn(DataTypeDefinition.TEXT);
        when(propDef.getDataType()).thenReturn(mockDataTypeDefinition);
        properties.put(name, propDef);
    }
    return properties;
}
Also used : HashMap(java.util.HashMap) AlfMock.generateQName(org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName) QName(org.alfresco.service.namespace.QName) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 7 with DataTypeDefinition

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

the class AlfrescoSolrDataModel method getAlfrescoPropertyFromSchemaField.

public String getAlfrescoPropertyFromSchemaField(String schemaField) {
    int index = schemaField.lastIndexOf("@{");
    if (index == -1) {
        return schemaField;
    }
    String alfrescoQueryField = schemaField.substring(index + 1);
    QName qName = QName.createQName(alfrescoQueryField);
    alfrescoQueryField = qName.toPrefixString(namespaceDAO);
    PropertyDefinition propertyDefinition = getPropertyDefinition(qName);
    if ((propertyDefinition == null)) {
        return alfrescoQueryField;
    }
    if (!propertyDefinition.isIndexed() && !propertyDefinition.isStoredInIndex()) {
        return alfrescoQueryField;
    }
    DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
    if (dataTypeDefinition.getName().equals(DataTypeDefinition.CONTENT)) {
        if (schemaField.contains("__size@")) {
            return alfrescoQueryField + ".size";
        } else if (schemaField.contains("__locale@")) {
            return alfrescoQueryField + ".locale";
        } else if (schemaField.contains("__mimetype@")) {
            return alfrescoQueryField + ".mimetype";
        } else if (schemaField.contains("__encoding@")) {
            return alfrescoQueryField + ".encoding";
        } else if (schemaField.contains("__docid@")) {
            return alfrescoQueryField + ".docid";
        } else if (schemaField.contains("__tr_ex@")) {
            return alfrescoQueryField + ".tr_ex";
        } else if (schemaField.contains("__tr_time@")) {
            return alfrescoQueryField + ".tr_time";
        } else if (schemaField.contains("__tr_status@")) {
            return alfrescoQueryField + ".tr_status";
        } else {
            return alfrescoQueryField;
        }
    } else {
        return alfrescoQueryField;
    }
}
Also used : QName(org.alfresco.service.namespace.QName) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) Constraint(org.alfresco.repo.search.impl.querymodel.Constraint)

Example 8 with DataTypeDefinition

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

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

the class UIProperty method generateControl.

/**
 * Generates an appropriate control for the given property
 *
 * @param context JSF context
 * @param propSheet The property sheet this property belongs to
 * @param propDef The definition of the property to create the control for
 */
@SuppressWarnings("unchecked")
private void generateControl(FacesContext context, UIPropertySheet propSheet, PropertyDefinition propDef) {
    UIComponent control = null;
    // get type info for the property
    DataTypeDefinition dataTypeDef = propDef.getDataType();
    QName typeName = dataTypeDef.getName();
    String componentGeneratorName = this.getComponentGenerator();
    // use the default component generator if there wasn't an overridden one
    if (componentGeneratorName == null) {
        // work out which generator to use by the type of the property
        if (typeName.equals(DataTypeDefinition.TEXT)) {
            componentGeneratorName = RepoConstants.GENERATOR_TEXT_FIELD;
        } else if (typeName.equals(DataTypeDefinition.MLTEXT)) {
            componentGeneratorName = RepoConstants.GENERATOR_MLTEXT_FIELD;
        } else if (typeName.equals(DataTypeDefinition.BOOLEAN)) {
            componentGeneratorName = RepoConstants.GENERATOR_CHECKBOX;
        } else if (typeName.equals(DataTypeDefinition.CATEGORY)) {
            componentGeneratorName = RepoConstants.GENERATOR_CATEGORY_SELECTOR;
        } else if (typeName.equals(DataTypeDefinition.DATETIME)) {
            componentGeneratorName = RepoConstants.GENERATOR_DATETIME_PICKER;
        } else if (typeName.equals(DataTypeDefinition.DATE)) {
            componentGeneratorName = RepoConstants.GENERATOR_DATE_PICKER;
        } else {
            // default to a text field
            componentGeneratorName = RepoConstants.GENERATOR_TEXT_FIELD;
        }
    }
    // retrieve the component generator and generate the control
    control = FacesHelper.getComponentGenerator(context, componentGeneratorName).generateAndAdd(context, propSheet, this);
    // if we're in edit mode ensure that we don't allow editing of system properties or scenarios we don't support
    if (propSheet.inEditMode()) {
        // properties that shouldn't be edited.
        if (!FacesHelper.getComponentGenerator(context, componentGeneratorName).isEnabledInEditMode(context, control, propDef)) {
            logger.warn("Setting property " + propDef.getName().toString() + " to read-only as it can not be edited");
            control.getAttributes().put("disabled", Boolean.TRUE);
        }
    }
    if (logger.isDebugEnabled())
        logger.debug("Created control " + control + "(" + control.getClientId(context) + ") for '" + propDef.getName().toString() + "' and added it to component " + this);
}
Also used : QName(org.alfresco.service.namespace.QName) UIComponent(javax.faces.component.UIComponent) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 10 with DataTypeDefinition

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

the class AdvancedSearchDialog method initialiseFromContext.

/**
 * Initialise the Advanced Search UI screen from a SearchContext
 *
 * @param search  the SearchContext to retrieve state from
 */
private void initialiseFromContext(SearchContext search) {
    resetFields();
    properties.setText(search.getText());
    switch(search.getMode()) {
        case SearchContext.SEARCH_ALL:
            properties.setMode(MODE_ALL);
            break;
        case SearchContext.SEARCH_FILE_NAMES_CONTENTS:
            properties.setMode(MODE_FILES_TEXT);
            break;
        case SearchContext.SEARCH_FILE_NAMES:
            properties.setMode(MODE_FILES);
            break;
        case SearchContext.SEARCH_SPACE_NAMES:
            properties.setMode(MODE_FOLDERS);
            break;
    }
    properties.getPanels().put(PANEL_RESTRICT, true);
    if (search.getLocation() != null) {
        properties.setLocationChildren(search.getLocation().endsWith("//*"));
        properties.setLocation(findNodeRefFromPath(search.getLocation()));
        properties.setLookin(LOOKIN_OTHER);
        properties.getPanels().put(PANEL_LOCATION, true);
    }
    String[] categories = search.getCategories();
    if (categories != null && categories.length != 0) {
        for (String category : categories) {
            NodeRef categoryRef = findNodeRefFromPath(category);
            if (categoryRef != null) {
                Node categoryNode = new MapNode(categoryRef);
                // add a value bound propery used to indicate if searching across children is selected
                categoryNode.getProperties().put(INCLUDE_CHILDREN, category.endsWith("//*"));
                properties.getCategories().add(categoryNode);
            }
        }
        properties.getPanels().put(PANEL_CATEGORIES, true);
    }
    properties.setContentType(search.getContentType());
    properties.setContentFormat(search.getMimeType());
    properties.setFolderType(search.getFolderType());
    properties.setDescription(search.getAttributeQuery(ContentModel.PROP_DESCRIPTION));
    properties.setTitle(search.getAttributeQuery(ContentModel.PROP_TITLE));
    properties.setAuthor(search.getAttributeQuery(ContentModel.PROP_AUTHOR));
    if (properties.getContentType() != null || properties.getContentFormat() != null || properties.getDescription() != null || properties.getTitle() != null || properties.getAuthor() != null) {
        properties.getPanels().put(PANEL_ATTRS, true);
    }
    RangeProperties createdDate = search.getRangeProperty(ContentModel.PROP_CREATED);
    if (createdDate != null) {
        properties.setCreatedDateFrom(Utils.parseXMLDateFormat(createdDate.lower));
        properties.setCreatedDateTo(Utils.parseXMLDateFormat(createdDate.upper));
        properties.setCreatedDateChecked(true);
        properties.getPanels().put(PANEL_ATTRS, true);
    }
    RangeProperties modifiedDate = search.getRangeProperty(ContentModel.PROP_MODIFIED);
    if (modifiedDate != null) {
        properties.setModifiedDateFrom(Utils.parseXMLDateFormat(modifiedDate.lower));
        properties.setModifiedDateTo(Utils.parseXMLDateFormat(modifiedDate.upper));
        properties.setModifiedDateChecked(true);
        properties.getPanels().put(PANEL_ATTRS, true);
    }
    // in case of dynamic config, only lookup once
    Map<String, DataTypeDefinition> customPropertyLookup = getCustomPropertyLookup();
    // custom fields - calculate which are required to set through the custom properties lookup table
    for (String qname : customPropertyLookup.keySet()) {
        DataTypeDefinition typeDef = customPropertyLookup.get(qname);
        if (typeDef != null) {
            QName typeName = typeDef.getName();
            if (DataTypeDefinition.DATE.equals(typeName) || DataTypeDefinition.DATETIME.equals(typeName)) {
                RangeProperties dateProps = search.getRangeProperty(QName.createQName(qname));
                if (dateProps != null) {
                    properties.getCustomProperties().put(UISearchCustomProperties.PREFIX_DATE_FROM + qname, Utils.parseXMLDateFormat(dateProps.lower));
                    properties.getCustomProperties().put(UISearchCustomProperties.PREFIX_DATE_TO + qname, Utils.parseXMLDateFormat(dateProps.upper));
                    properties.getCustomProperties().put(qname, true);
                    properties.getPanels().put(PANEL_CUSTOM, true);
                }
            } else if (DataTypeDefinition.BOOLEAN.equals(typeName)) {
                String strBool = search.getFixedValueQuery(QName.createQName(qname));
                if (strBool != null) {
                    properties.getCustomProperties().put(qname, Boolean.parseBoolean(strBool));
                    properties.getPanels().put(PANEL_CUSTOM, true);
                }
            } else if (DataTypeDefinition.NODE_REF.equals(typeName) || DataTypeDefinition.CATEGORY.equals(typeName)) {
                String strNodeRef = search.getFixedValueQuery(QName.createQName(qname));
                if (strNodeRef != null) {
                    properties.getCustomProperties().put(qname, new NodeRef(strNodeRef));
                    properties.getPanels().put(PANEL_CUSTOM, true);
                }
            } else if (DataTypeDefinition.INT.equals(typeName) || DataTypeDefinition.LONG.equals(typeName) || DataTypeDefinition.FLOAT.equals(typeName) || DataTypeDefinition.DOUBLE.equals(typeName)) {
                // currently numbers are rendered as text in UISearchCustomProperties component
                // this code will need updating if that changes!
                properties.getCustomProperties().put(qname, search.getFixedValueQuery(QName.createQName(qname)));
                properties.getPanels().put(PANEL_CUSTOM, true);
            } else {
                // a default datatype may indicate either an attribute query, or if a Fixed Value
                // is present then it's a LOV constraint with a value selected
                Object value = search.getFixedValueQuery(QName.createQName(qname));
                if (value != null) {
                    properties.getCustomProperties().put(UISearchCustomProperties.PREFIX_LOV_ITEM + qname, value);
                    properties.getCustomProperties().put(qname, Boolean.TRUE);
                } else {
                    properties.getCustomProperties().put(qname, search.getAttributeQuery(QName.createQName(qname)));
                }
                properties.getPanels().put(PANEL_CUSTOM, true);
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RangeProperties(org.alfresco.web.bean.search.SearchContext.RangeProperties) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Aggregations

DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)19 QName (org.alfresco.service.namespace.QName)15 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)9 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)4 HashMap (java.util.HashMap)3 StartFormData (org.activiti.engine.form.StartFormData)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 DictionaryException (org.alfresco.service.cmr.dictionary.DictionaryException)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 InvalidQNameException (org.alfresco.service.namespace.InvalidQNameException)3 JSONArray (org.json.JSONArray)3 UIComponent (javax.faces.component.UIComponent)2 UISelectBoolean (javax.faces.component.UISelectBoolean)2 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)2 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)2 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2