Search in sources :

Example 1 with RangeProperties

use of org.alfresco.web.bean.search.SearchContext.RangeProperties 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)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 QName (org.alfresco.service.namespace.QName)1 MapNode (org.alfresco.web.bean.repository.MapNode)1 Node (org.alfresco.web.bean.repository.Node)1 RangeProperties (org.alfresco.web.bean.search.SearchContext.RangeProperties)1