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);
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations