Search in sources :

Example 11 with ClassDefinition

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

the class TransientNode method createNew.

/**
 * Construct a transient node for an item yet to be created in the Repository.
 *
 * This will apply any one-time initialisation required upon creation of the node
 * e.g. assignment of default values.
 *
 * @param dictionaryService dictionary service
 * @param typeDef The type definition this node will represent
 * @param name The name of the node
 * @param data The properties and associations this node will have
 * @return  transient node
 */
public static TransientNode createNew(DictionaryService dictionaryService, TypeDefinition typeDef, String name, Map<QName, Serializable> data) {
    // build a complete anonymous type for the start task
    List<AspectDefinition> aspects = typeDef.getDefaultAspects();
    List<QName> aspectNames = new ArrayList<QName>(aspects.size());
    getMandatoryAspects(typeDef, aspectNames);
    ClassDefinition startTaskDef = dictionaryService.getAnonymousType(typeDef.getName(), aspectNames);
    // initialise start task values
    Map<QName, Serializable> startValues = new HashMap<QName, Serializable>();
    if (data != null) {
        startValues.putAll(data);
    }
    // apply default values
    Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties();
    for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet()) {
        String defaultValue = entry.getValue().getDefaultValue();
        if (defaultValue != null) {
            if (startValues.get(entry.getKey()) == null) {
                startValues.put(entry.getKey(), (Serializable) DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), defaultValue));
            }
        }
    }
    return new TransientNode(typeDef.getName(), name, startValues);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with ClassDefinition

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

the class Solr4QueryParser method createIsUnsetQuery.

protected Query createIsUnsetQuery(String queryText, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
    PropertyDefinition pd = QueryParserUtils.matchPropertyDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, queryText);
    if (pd != null) {
        ClassDefinition containerClass = pd.getContainerClass();
        QName container = containerClass.getName();
        String classType = containerClass.isAspect() ? FIELD_ASPECT : FIELD_TYPE;
        Query typeQuery = getFieldQuery(classType, container.toString(), analysisMode, luceneFunction);
        BooleanQuery.Builder query = new BooleanQuery.Builder();
        Query presenceQuery = createTermQuery(FIELD_PROPERTIES, pd.getName().toString());
        if (presenceQuery != null) {
            query.add(typeQuery, Occur.MUST);
            query.add(presenceQuery, Occur.MUST_NOT);
        }
        return query.build();
    } else {
        BooleanQuery.Builder query = new BooleanQuery.Builder();
        Query presenceQuery = getWildcardQuery(queryText, "*");
        if (presenceQuery != null) {
            query.add(presenceQuery, Occur.MUST_NOT);
        }
        return query.build();
    }
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) QName(org.alfresco.service.namespace.QName) Builder(org.apache.lucene.search.BooleanQuery.Builder) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) Builder(org.apache.lucene.search.BooleanQuery.Builder)

Example 13 with ClassDefinition

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

the class CustomModelsImpl method convertToCustomModelProperty.

private List<CustomModelProperty> convertToCustomModelProperty(ClassDefinition classDefinition, boolean includeInherited) {
    Collection<PropertyDefinition> ownProperties = null;
    ClassDefinition parentDef = classDefinition.getParentClassDefinition();
    if (!includeInherited && parentDef != null) {
        // Remove inherited properties
        ownProperties = removeRightEntries(classDefinition.getProperties(), parentDef.getProperties()).values();
    } else {
        ownProperties = classDefinition.getProperties().values();
    }
    List<CustomModelProperty> customProperties = new ArrayList<>(ownProperties.size());
    for (PropertyDefinition propDef : ownProperties) {
        customProperties.add(new CustomModelProperty(propDef, dictionaryService));
    }
    return customProperties;
}
Also used : ArrayList(java.util.ArrayList) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty)

Example 14 with ClassDefinition

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

the class AbstractSubClassesGet method executeImpl.

/**
 * Override method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
    String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
    String recursiveValue = getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN));
    boolean recursive = true;
    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>();
    String namespaceUri = null;
    Collection<QName> qname = null;
    boolean ignoreCheck = false;
    // validate recursive parameter => can be either true or false or null
    if (recursiveValue == null) {
        recursive = true;
    } else if (recursiveValue.equalsIgnoreCase("true")) {
        recursive = true;
    } else if (recursiveValue.equalsIgnoreCase("false")) {
        recursive = false;
    } else {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursiveValue + "  can only be either true or false");
    }
    qname = getQNameCollection(req, recursive);
    // validate the name parameter
    if (name != null) {
        if (isValidModelName(name) == false) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL");
        }
    }
    // validate the name parameter
    if (namespacePrefix == null && name != null) {
        namespaceUri = namespaceService.getNamespaceURI(getPrefixFromModelName(name));
    }
    if (namespacePrefix != null && name == null) {
        namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
    }
    if (namespacePrefix == null && name == null) {
        namespaceUri = null;
        ignoreCheck = true;
    }
    if (namespacePrefix != null && name != null) {
        validateClassname(namespacePrefix, name);
        namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
    }
    for (QName qnameObj : qname) {
        if ((ignoreCheck == true) || (qnameObj.getNamespaceURI().equals(namespaceUri))) {
            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, reorderedValues(classDefinitions, propdef));
    model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, reorderedValues(classDefinitions, assocdef));
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.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 15 with ClassDefinition

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

the class DictionaryGet method executeImpl.

/**
 * Execute the webscript
 *
 * @param req       WebScriptRequest
 * @param status    Status
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    List<QName> qnames = new ArrayList<QName>(256);
    Set<String> namespaces = new HashSet<String>();
    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>>();
    // check configured list of model namespaces to ignore when retrieving all models
    for (String ns : this.namespaceService.getURIs()) {
        if (!ignoreNamespaces.contains(ns)) {
            namespaces.add(ns);
        }
    }
    // specific model qname provided or will process all available models
    String strModel = req.getParameter("model");
    if (strModel != null && strModel.length() != 0) {
        // handle full QName and prefixed shortname of a model
        QName modelQName = (strModel.charAt(0) == QName.NAMESPACE_BEGIN ? QName.createQName(strModel) : QName.createQName(strModel, this.namespaceService));
        ModelDefinition modelDef = this.dictionaryservice.getModel(modelQName);
        if (modelDef != null) {
            qnames.addAll(this.dictionaryservice.getAspects(modelQName));
            qnames.addAll(this.dictionaryservice.getTypes(modelQName));
        }
    } else {
        // walk all models and extract the aspects and types
        for (QName qname : this.dictionaryservice.getAllModels()) {
            if (namespaces.contains(qname.getNamespaceURI())) {
                qnames.addAll(this.dictionaryservice.getAspects(qname));
                qnames.addAll(this.dictionaryservice.getTypes(qname));
            }
        }
    }
    // get the class definitions and the properties and associations
    for (QName qname : qnames) {
        ClassDefinition classDef = this.dictionaryservice.getClass(qname);
        classdef.put(qname, classDef);
        propdef.put(qname, classDef.getProperties().values());
        assocdef.put(qname, classDef.getAssociations().values());
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MODEL_CLASS_DEFS, classdef.values());
    model.put(MODEL_PROPERTY_DEFS, propdef.values());
    model.put(MODEL_ASSOCIATION_DEFS, assocdef.values());
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.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) ModelDefinition(org.alfresco.service.cmr.dictionary.ModelDefinition) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)17 QName (org.alfresco.service.namespace.QName)12 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)11 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Collection (java.util.Collection)6 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)5 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 HashSet (java.util.HashSet)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)2 Query (org.apache.lucene.search.Query)2 RegexpQuery (org.apache.lucene.search.RegexpQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)2 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)2 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)2 SpanQuery (org.apache.lucene.search.spans.SpanQuery)2