Search in sources :

Example 31 with PropertyDefinition

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

the class RecordsManagementAuditServiceImpl method getPropertyLabel.

/**
 * Returns the display label for a property QName
 *
 * @param property The property to get label for
 * @param ddService DictionaryService instance
 * @param namespaceService NamespaceService instance
 * @return The label
 */
private String getPropertyLabel(QName property) {
    String label = null;
    PropertyDefinition propDef = this.dictionaryService.getProperty(property);
    if (propDef != null) {
        label = propDef.getTitle(dictionaryService);
    }
    if (label == null) {
        label = property.getLocalName();
    }
    return label;
}
Also used : PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 32 with PropertyDefinition

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

the class CustomPropertyDefinitionDelete method getPropertyFromReq.

private QName getPropertyFromReq(WebScriptRequest req) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String propIdString = templateVars.get(PROP_ID);
    QName propQName = this.rmAdminService.getQNameForClientId(propIdString);
    Map<QName, PropertyDefinition> existingPropDefs = rmAdminService.getCustomPropertyDefinitions();
    if (!existingPropDefs.containsKey(propQName)) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Requested property definition (id:" + propIdString + ") does not exist");
    }
    return propQName;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 33 with PropertyDefinition

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

the class RmClassesGet method executeImpl.

/**
 * Execute custom Java logic
 *
 * @param req  Web Script request
 * @param isRM  indicates whether the request comes from an RM site or not
 * @return custom service model
 */
private Map<String, Object> executeImpl(WebScriptRequest req, boolean isRM) {
    String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
    String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
    String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
    String className = null;
    Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
    Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
    Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
    Map<String, Object> model = new HashMap<String, Object>();
    List<QName> qnames = new ArrayList<QName>();
    QName classQname = null;
    QName myModel = null;
    // if classfilter is not given, then it defaults to all
    if (classFilter == null) {
        classFilter = "all";
    }
    // validate classfilter
    if (!isValidClassFilter(classFilter)) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
    }
    // name alone has no meaning without namespaceprefix
    if (namespacePrefix == null && name != null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
    }
    // validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
    if (namespacePrefix != null) {
        // validate name parameter if present along with the namespaceprefix
        if (name != null) {
            className = namespacePrefix + "_" + name;
            if (!isValidClassname(className)) {
                throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
            }
            classQname = QName.createQName(getFullNamespaceURI(className));
            classdef.put(classQname, this.dictionaryservice.getClass(classQname));
            propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
            assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
        } else {
            // if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
            String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
            for (QName qnameObj : this.dictionaryservice.getAllModels()) {
                if (qnameObj.getNamespaceURI().equals(namespaceUri)) {
                    name = qnameObj.getLocalName();
                    myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
                    // check the classfilter to pull out either all or type or aspects
                    if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
                        qnames.addAll(this.dictionaryservice.getAspects(myModel));
                        qnames.addAll(this.dictionaryservice.getTypes(myModel));
                    } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
                        qnames.addAll(this.dictionaryservice.getTypes(myModel));
                    } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
                        qnames.addAll(this.dictionaryservice.getAspects(myModel));
                    }
                }
            }
        }
    }
    // if namespacePrefix is null, then check the class filter to pull out either all, type or aspects
    if (myModel == null) {
        if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
            qnames.addAll(getAspects(isRM));
            qnames.addAll(getTypes(isRM));
        } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
            qnames.addAll(getTypes(isRM));
        } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
            qnames.addAll(getAspects(isRM));
        }
    }
    if (classdef.isEmpty()) {
        for (QName qnameObj : qnames) {
            classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
            propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
            assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
        }
    }
    List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
    Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator(dictionaryservice));
    model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
    model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
    model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
    return model;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Collection(java.util.Collection)

Example 34 with PropertyDefinition

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

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

the class AlfrescoSolrDataModel method mapProperty.

public String mapProperty(String potentialProperty, FieldUse fieldUse, SolrQueryRequest req, int position) {
    if (potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_")) {
        return potentialProperty;
    }
    if (potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE")) {
        return "score";
    }
    if (req.getSchema().getFieldOrNull(potentialProperty) != null) {
        return mapNonPropertyFields(potentialProperty);
    }
    AlfrescoFunctionEvaluationContext functionContext = new AlfrescoSolr4FunctionEvaluationContext(getNamespaceDAO(), getDictionaryService(CMISStrictDictionaryService.DEFAULT), NamespaceService.CONTENT_MODEL_1_0_URI, req.getSchema());
    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(potentialProperty);
    String luceneField = functionContext.getLuceneFieldName(fieldNameAndEnding.getFirst());
    PropertyDefinition propertyDef = getPropertyDefinition(fieldNameAndEnding.getFirst());
    // Retry scan using luceneField.
    if (propertyDef == null) {
        if (luceneField.contains("@")) {
            int index = luceneField.lastIndexOf("@");
            propertyDef = getPropertyDefinition(luceneField.substring(index + 1));
        }
    }
    String solrSortField = null;
    if (propertyDef != null) {
        IndexedField fields = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), getTextField(fieldNameAndEnding.getSecond()), fieldUse);
        if (fields.getFields().size() > 0) {
            if (fields.getFields().size() > position) {
                solrSortField = fields.getFields().get(position).getField();
            } else {
                solrSortField = fields.getFields().get(0).getField();
            }
        } else {
            solrSortField = mapNonPropertyFields(luceneField);
        }
    } else {
        solrSortField = mapNonPropertyFields(luceneField);
    }
    return solrSortField;
}
Also used : AlfrescoFunctionEvaluationContext(org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) Constraint(org.alfresco.repo.search.impl.querymodel.Constraint)

Aggregations

PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)77 QName (org.alfresco.service.namespace.QName)51 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)24 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 Map (java.util.Map)15 Serializable (java.io.Serializable)14 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)9 Collection (java.util.Collection)7 List (java.util.List)7 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)7 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)7 Builder (org.apache.lucene.search.BooleanQuery.Builder)7 Constraint (org.alfresco.service.cmr.dictionary.Constraint)6 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)6 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)6