Search in sources :

Example 11 with DataTypeDefinition

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

the class AdvancedSearchDialog method search.

/**
 * Handler to perform a search based on the current criteria
 */
public String search() {
    // construct the Search Context and set on the navigation bean
    // then simply navigating to the browse screen will cause it pickup the Search Context
    SearchContext search = new SearchContext();
    // set the full-text/name field value
    search.setText(properties.getText());
    // set whether to force AND operation on text terms
    search.setForceAndTerms(Application.getClientConfig(FacesContext.getCurrentInstance()).getForceAndTerms());
    if (properties.getMode().equals(MODE_ALL)) {
        search.setMode(SearchContext.SEARCH_ALL);
    } else if (properties.getMode().equals(MODE_FILES_TEXT)) {
        search.setMode(SearchContext.SEARCH_FILE_NAMES_CONTENTS);
    } else if (properties.getMode().equals(MODE_FILES)) {
        search.setMode(SearchContext.SEARCH_FILE_NAMES);
    } else if (properties.getMode().equals(MODE_FOLDERS)) {
        search.setMode(SearchContext.SEARCH_SPACE_NAMES);
    }
    // additional attributes search
    if (properties.getDescription() != null && properties.getDescription().length() != 0) {
        search.addAttributeQuery(ContentModel.PROP_DESCRIPTION, properties.getDescription());
    }
    if (properties.getTitle() != null && properties.getTitle().length() != 0) {
        search.addAttributeQuery(ContentModel.PROP_TITLE, properties.getTitle());
    }
    if (properties.getAuthor() != null && properties.getAuthor().length() != 0) {
        search.addAttributeQuery(ContentModel.PROP_AUTHOR, properties.getAuthor());
    }
    if (properties.getContentFormat() != null && properties.getContentFormat().length() != 0) {
        search.setMimeType(properties.getContentFormat());
    }
    if (properties.isCreatedDateChecked()) {
        SimpleDateFormat df = CachingDateFormat.getDateFormat();
        Calendar cal = Calendar.getInstance();
        cal.setTime(properties.getCreatedDateFrom());
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        String strCreatedDate = df.format(cal.getTime());
        cal.setTime(properties.getCreatedDateTo());
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        cal.add(Calendar.DAY_OF_YEAR, 1);
        cal.add(Calendar.MILLISECOND, -1);
        String strCreatedDateTo = df.format(cal.getTime());
        search.addRangeQuery(ContentModel.PROP_CREATED, strCreatedDate, strCreatedDateTo, true);
    }
    if (properties.isModifiedDateChecked()) {
        SimpleDateFormat df = CachingDateFormat.getDateFormat();
        Calendar cal = Calendar.getInstance();
        cal.setTime(properties.getModifiedDateFrom());
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        String strModifiedDate = df.format(cal.getTime());
        cal.setTime(properties.getModifiedDateTo());
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        cal.add(Calendar.DAY_OF_YEAR, 1);
        cal.add(Calendar.MILLISECOND, -1);
        String strModifiedDateTo = df.format(cal.getTime());
        search.addRangeQuery(ContentModel.PROP_MODIFIED, strModifiedDate, strModifiedDateTo, true);
    }
    // in case of dynamic config, only lookup once
    Map<String, DataTypeDefinition> customPropertyLookup = getCustomPropertyLookup();
    // walk each of the custom properties add add them as additional attributes
    for (String qname : properties.getCustomProperties().keySet()) {
        Object value = properties.getCustomProperties().get(qname);
        DataTypeDefinition typeDef = customPropertyLookup.get(qname);
        if (typeDef != null) {
            QName typeName = typeDef.getName();
            if (DataTypeDefinition.DATE.equals(typeName) || DataTypeDefinition.DATETIME.equals(typeName)) {
                // only apply date to search if the user has checked the enable checkbox
                if (value != null && Boolean.valueOf(value.toString()) == true) {
                    SimpleDateFormat df = CachingDateFormat.getDateFormat();
                    String strDateFrom = df.format(properties.getCustomProperties().get(UISearchCustomProperties.PREFIX_DATE_FROM + qname));
                    String strDateTo = df.format(properties.getCustomProperties().get(UISearchCustomProperties.PREFIX_DATE_TO + qname));
                    search.addRangeQuery(QName.createQName(qname), strDateFrom, strDateTo, true);
                }
            } else if (DataTypeDefinition.BOOLEAN.equals(typeName)) {
                if (((Boolean) value) == true) {
                    search.addFixedValueQuery(QName.createQName(qname), value.toString());
                }
            } else if (DataTypeDefinition.NODE_REF.equals(typeName) || DataTypeDefinition.CATEGORY.equals(typeName)) {
                if (value != null) {
                    search.addFixedValueQuery(QName.createQName(qname), value.toString());
                }
            } else if (value != null) {
                // is the value from a list?
                String strVal = value.toString();
                Object item = properties.getCustomProperties().get(UISearchCustomProperties.PREFIX_LOV_ITEM + qname);
                if (item != null) {
                    // ListOfValues custom property - use a fixed value query if set
                    if (((Boolean) value) == true) {
                        search.addFixedValueQuery(QName.createQName(qname), item.toString());
                    }
                } else if (strVal != null && strVal.length() != 0) {
                    if (DataTypeDefinition.INT.equals(typeName) || DataTypeDefinition.LONG.equals(typeName) || DataTypeDefinition.FLOAT.equals(typeName) || DataTypeDefinition.DOUBLE.equals(typeName)) {
                        search.addFixedValueQuery(QName.createQName(qname), strVal);
                    } else {
                        // by default use toString() value - this is for text fields and unknown types
                        search.addAttributeQuery(QName.createQName(qname), strVal);
                    }
                }
            }
        }
    }
    // location path search
    if (properties.getLookin().equals(LOOKIN_OTHER) && properties.getLocation() != null) {
        search.setLocation(SearchContext.getPathFromSpaceRef(properties.getLocation(), properties.isLocationChildren()));
    }
    // category path search
    if (properties.getCategories().size() != 0) {
        String[] paths = new String[properties.getCategories().size()];
        for (int i = 0; i < paths.length; i++) {
            Node category = properties.getCategories().get(i);
            boolean includeChildren = (Boolean) category.getProperties().get(INCLUDE_CHILDREN);
            paths[i] = SearchContext.getPathFromSpaceRef(category.getNodeRef(), includeChildren);
        }
        search.setCategories(paths);
    }
    // content type restriction
    if (properties.getContentType() != null) {
        search.setContentType(properties.getContentType());
    }
    // folder type restriction
    if (properties.getFolderType() != null) {
        search.setFolderType(properties.getFolderType());
    }
    // set the Search Context onto the top-level navigator bean
    // this causes the browse screen to switch into search results view
    this.navigator.setSearchContext(search);
    return OUTCOME_BROWSE;
}
Also used : QName(org.alfresco.service.namespace.QName) Calendar(java.util.Calendar) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) UISelectBoolean(javax.faces.component.UISelectBoolean) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with DataTypeDefinition

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

the class AlfrescoSolrDataModel method getIndexedFieldNamesForProperty.

/**
 * Get all the field names into which we must copy the source data
 *
 * @param propertyQName QName
 * @return IndexedField
 */
public IndexedField getIndexedFieldNamesForProperty(QName propertyQName) {
    // TODO: Cache and throw on model refresh
    IndexedField indexedField = new IndexedField();
    PropertyDefinition propertyDefinition = getPropertyDefinition(propertyQName);
    if ((propertyDefinition == null)) {
        return indexedField;
    }
    if (!propertyDefinition.isIndexed() && !propertyDefinition.isStoredInIndex()) {
        return indexedField;
    }
    DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
    if (isTextField(propertyDefinition)) {
        if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.TRUE) || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH)) {
            indexedField.addField(getFieldForText(true, true, false, propertyDefinition), true, false);
            if (crossLocaleSearchDataTypes.contains(propertyDefinition.getDataType().getName()) || crossLocaleSearchProperties.contains(propertyDefinition.getName())) {
                indexedField.addField(getFieldForText(false, true, false, propertyDefinition), false, false);
            }
        }
        if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE) || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH || isIdentifierTextProperty(propertyDefinition.getName()))) {
            indexedField.addField(getFieldForText(true, false, false, propertyDefinition), true, false);
            indexedField.addField(getFieldForText(false, false, false, propertyDefinition), false, false);
        }
        if (dataTypeDefinition.getName().equals(DataTypeDefinition.TEXT)) {
            if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE) || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH)) {
                if (propertyDefinition.isMultiValued() == false) {
                    indexedField.addField(getFieldForText(false, false, true, propertyDefinition), false, true);
                }
            } else if (!isIdentifierTextProperty(propertyDefinition.getName())) {
                if (propertyDefinition.getFacetable() == Facetable.TRUE) {
                    indexedField.addField(getFieldForText(false, false, false, propertyDefinition), false, false);
                }
            }
        }
        if (dataTypeDefinition.getName().equals(DataTypeDefinition.MLTEXT)) {
            if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE) || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH)) {
                if (propertyDefinition.isMultiValued() == false) {
                    indexedField.addField(getFieldForText(true, false, true, propertyDefinition), true, true);
                }
            }
        }
        if (isSuggestable(propertyQName)) {
            indexedField.addField("suggest_@" + propertyDefinition.getName().toString(), false, false);
        }
    } else {
        indexedField.addField(getFieldForNonText(propertyDefinition), false, false);
    }
    return indexedField;
}
Also used : DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 13 with DataTypeDefinition

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

the class AlfrescoSolrDataModel method getIndexedFieldForContentPropertyMetadata.

public IndexedField getIndexedFieldForContentPropertyMetadata(QName propertyQName, ContentFieldType type) {
    IndexedField indexedField = new IndexedField();
    PropertyDefinition propertyDefinition = getPropertyDefinition(propertyQName);
    if ((propertyDefinition == null)) {
        return indexedField;
    }
    if (!propertyDefinition.isIndexed() && !propertyDefinition.isStoredInIndex()) {
        return indexedField;
    }
    DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
    if (dataTypeDefinition.getName().equals(DataTypeDefinition.CONTENT)) {
        StringBuilder builder = new StringBuilder();
        builder.append(dataTypeDefinition.getName().getLocalName());
        builder.append('@');
        // TODO wher we support multi value propertis correctly .... builder.append(propertyDefinition.isMultiValued() ? "m" : "s");
        builder.append('s');
        builder.append("_");
        builder.append('_');
        switch(type) {
            case DOCID:
                builder.append("docid");
                break;
            case ENCODING:
                builder.append("encoding");
                break;
            case LOCALE:
                builder.append("locale");
                break;
            case MIMETYPE:
                builder.append("mimetype");
                break;
            case SIZE:
                builder.append("size");
                break;
            case TRANSFORMATION_EXCEPTION:
                builder.append("tr_ex");
                break;
            case TRANSFORMATION_STATUS:
                builder.append("tr_status");
                break;
            case TRANSFORMATION_TIME:
                builder.append("tr_time");
                break;
            default:
                break;
        }
        builder.append('@');
        builder.append(propertyQName);
        indexedField.addField(builder.toString(), false, false);
    }
    return indexedField;
}
Also used : DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 14 with DataTypeDefinition

use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project alfresco-remote-api by Alfresco.

the class ActionsImpl method convertValue.

private Serializable convertValue(QName typeQName, Object propertyValue) throws JSONException {
    Serializable value;
    DataTypeDefinition typeDef = dictionaryService.getDataType(typeQName);
    if (typeDef == null) {
        throw new AlfrescoRuntimeException("Action property type definition " + typeQName.toPrefixString() + " is unknown.");
    }
    if (propertyValue instanceof JSONArray) {
        // Convert property type to java class
        String javaClassName = typeDef.getJavaClassName();
        try {
            Class.forName(javaClassName);
        } catch (ClassNotFoundException e) {
            throw new DictionaryException("Java class " + javaClassName + " of property type " + typeDef.getName() + " is invalid", e);
        }
        int length = ((JSONArray) propertyValue).length();
        List<Serializable> list = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            list.add(convertValue(typeQName, ((JSONArray) propertyValue).get(i)));
        }
        value = (Serializable) list;
    } else {
        if (typeQName.equals(DataTypeDefinition.QNAME) && typeQName.toString().contains(":")) {
            value = QName.createQName(propertyValue.toString(), namespaceService);
        } else {
            value = (Serializable) DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(typeQName), propertyValue);
        }
    }
    return value;
}
Also used : Serializable(java.io.Serializable) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 15 with DataTypeDefinition

use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project alfresco-remote-api by Alfresco.

the class SOLRSerializer method serialize.

@SuppressWarnings("unchecked")
public PropertyValue serialize(QName propName, Serializable value) throws IOException, JSONException {
    if (value == null) {
        return new PropertyValue(false, "null");
    }
    PropertyDefinition propertyDef = dictionaryService.getProperty(propName);
    if (propertyDef == null) {
        // Treat it as text
        return new PropertyValue(true, serializeToJSONString(value));
    }
    DataTypeDefinition dataType = propertyDef.getDataType();
    QName dataTypeName = dataType.getName();
    if (propertyDef.isMultiValued()) {
        if (!(value instanceof Collection)) {
            throw new IllegalArgumentException("Multi value: expected a collection, got " + value.getClass().getName());
        }
        Collection<Serializable> c = (Collection<Serializable>) value;
        JSONArray body = new JSONArray();
        for (Serializable o : c) {
            if (dataTypeName.equals(DataTypeDefinition.MLTEXT)) {
                MLText source = (MLText) o;
                JSONArray array = new JSONArray();
                for (Locale locale : source.getLocales()) {
                    JSONObject json = new JSONObject();
                    json.put("locale", DefaultTypeConverter.INSTANCE.convert(String.class, locale));
                    json.put("value", source.getValue(locale));
                    array.put(json);
                }
                body.put(array);
            } else if (dataTypeName.equals(DataTypeDefinition.CONTENT)) {
                throw new RuntimeException("Multi-valued content properties are not supported");
            } else {
                body.put(serializeToJSONString(o));
            }
        }
        return new PropertyValue(false, body.toString());
    } else {
        boolean encodeString = true;
        if (dataTypeName.equals(DataTypeDefinition.MLTEXT)) {
            encodeString = false;
        } else if (dataTypeName.equals(DataTypeDefinition.CONTENT)) {
            encodeString = false;
        } else {
            encodeString = true;
        }
        String sValue = null;
        if (value instanceof String && encodeString) {
            sValue = (String) jsonUtils.encodeJSONString(value);
        } else {
            sValue = serializeToJSONString(value);
        }
        return new PropertyValue(encodeString, sValue);
    }
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) PlatformRuntimeException(org.springframework.extensions.surf.exception.PlatformRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject) MLText(org.alfresco.service.cmr.repository.MLText) Collection(java.util.Collection)

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