use of org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method createCustomModelImpl.
private CustomModel createCustomModelImpl(CustomModel model, boolean basicModelOnly) {
M2Model m2Model = null;
if (basicModelOnly) {
m2Model = convertToM2Model(model, null, null, null);
} else {
m2Model = convertToM2Model(model, model.getTypes(), model.getAspects(), model.getConstraints());
}
boolean activate = ModelStatus.ACTIVE.equals(model.getStatus());
try {
CustomModelDefinition modelDefinition = customModelService.createCustomModel(m2Model, activate);
return new CustomModel(modelDefinition);
} catch (ModelExistsException me) {
throw new ConstraintViolatedException(me.getMessage());
} catch (CustomModelConstraintException ncx) {
throw new ConstraintViolatedException(ncx.getMessage());
} catch (InvalidCustomModelException iex) {
throw new InvalidArgumentException(iex.getMessage());
} catch (Exception e) {
throw new ApiException("cmm.rest_api.model_invalid", e);
}
}
use of org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method updateCustomModel.
@Override
public CustomModel updateCustomModel(String modelName, CustomModel model, Parameters parameters) {
// Check the current user is authorised to update the custom model
validateCurrentUser();
// Check to see if the model exists
ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
CustomModel existingModel = existingModelDetails.getModel();
// the other properties should be untouched)
if (hasSelectProperty(parameters, SELECT_STATUS)) {
ModelStatus status = model.getStatus();
if (status == null) {
throw new InvalidArgumentException("cmm.rest_api.model_status_null");
}
try {
if (ModelStatus.ACTIVE.equals(status)) {
customModelService.activateCustomModel(modelName);
} else {
customModelService.deactivateCustomModel(modelName);
}
// update the model's status
existingModel.setStatus(status);
return existingModel;
} catch (CustomModelConstraintException mce) {
throw new ConstraintViolatedException(mce.getMessage());
} catch (Exception ex) {
throw new ApiException(ex.getMessage(), ex);
}
} else {
if (model.getName() != null && !(existingModel.getName().equals(model.getName()))) {
throw new InvalidArgumentException("cmm.rest_api.model_name_cannot_update");
}
existingModel.setNamespaceUri(model.getNamespaceUri());
final boolean isNamespacePrefixChanged = !(existingModel.getNamespacePrefix().equals(model.getNamespacePrefix()));
if (isNamespacePrefixChanged) {
// Change types' and aspects' parents as well as the property constraint's Ref namespace prefix
replacePrefix(existingModelDetails.getTypes(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
replacePrefix(existingModelDetails.getAspects(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
}
existingModel.setNamespacePrefix(model.getNamespacePrefix());
existingModel.setAuthor(model.getAuthor());
existingModel.setDescription(model.getDescription());
CustomModelDefinition modelDef = updateModel(existingModelDetails, "cmm.rest_api.model_update_failure");
return new CustomModel(modelDef);
}
}
use of org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException 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);
}
Aggregations