Search in sources :

Example 1 with CompiledModel

use of org.alfresco.repo.dictionary.CompiledModel 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)

Aggregations

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 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 ModelDefinition (org.alfresco.service.cmr.dictionary.ModelDefinition)1 NamespaceDefinition (org.alfresco.service.cmr.dictionary.NamespaceDefinition)1