Search in sources :

Example 1 with ModelDefinition

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);
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) CustomAspect(org.alfresco.rest.api.model.CustomAspect) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) CustomModel(org.alfresco.rest.api.model.CustomModel) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) CompiledModel(org.alfresco.repo.dictionary.CompiledModel) ModelDefinition(org.alfresco.service.cmr.dictionary.ModelDefinition) CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) NamespaceDefinition(org.alfresco.service.cmr.dictionary.NamespaceDefinition) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint)

Example 2 with ModelDefinition

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;
}
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

ModelDefinition (org.alfresco.service.cmr.dictionary.ModelDefinition)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CompiledModel (org.alfresco.repo.dictionary.CompiledModel)1 CustomAspect (org.alfresco.rest.api.model.CustomAspect)1 CustomModel (org.alfresco.rest.api.model.CustomModel)1 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)1 CustomType (org.alfresco.rest.api.model.CustomType)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)1 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)1 ConstraintDefinition (org.alfresco.service.cmr.dictionary.ConstraintDefinition)1 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)1 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)1 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)1 NamespaceDefinition (org.alfresco.service.cmr.dictionary.NamespaceDefinition)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1