use of org.alfresco.service.cmr.dictionary.ModelDefinition in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method createCustomModel.
@Override
public CustomModel createCustomModel(M2Model m2Model) {
// Check the current user is authorised to import the custom model
validateCurrentUser();
validateImportedM2Model(m2Model);
CompiledModel compiledModel = null;
try {
compiledModel = customModelService.compileModel(m2Model);
} catch (CustomModelConstraintException mce) {
throw new ConstraintViolatedException(mce.getMessage());
} catch (InvalidCustomModelException iex) {
throw new InvalidArgumentException(iex.getMessage());
}
ModelDefinition modelDefinition = compiledModel.getModelDefinition();
CustomModel customModel = new CustomModel();
customModel.setName(modelDefinition.getName().getLocalName());
customModel.setAuthor(modelDefinition.getAuthor());
customModel.setDescription(modelDefinition.getDescription(dictionaryService));
customModel.setStatus(ModelStatus.DRAFT);
NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next();
customModel.setNamespaceUri(nsd.getUri());
customModel.setNamespacePrefix(nsd.getPrefix());
List<CustomType> customTypes = convertToCustomTypes(compiledModel.getTypes(), false);
List<CustomAspect> customAspects = convertToCustomAspects(compiledModel.getAspects(), false);
List<ConstraintDefinition> constraintDefinitions = CustomModelDefinitionImpl.removeInlineConstraints(compiledModel);
List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions);
customModel.setTypes(customTypes);
customModel.setAspects(customAspects);
customModel.setConstraints(customModelConstraints);
return createCustomModelImpl(customModel, false);
}
use of org.alfresco.service.cmr.dictionary.ModelDefinition 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