Search in sources :

Example 1 with ModelStatus

use of org.alfresco.rest.api.model.CustomModel.ModelStatus 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);
    }
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModelStatus(org.alfresco.rest.api.model.CustomModel.ModelStatus) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModel(org.alfresco.rest.api.model.CustomModel) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActiveModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException) ModelDoesNotExistException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) CustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Aggregations

CustomModel (org.alfresco.rest.api.model.CustomModel)1 ModelStatus (org.alfresco.rest.api.model.CustomModel.ModelStatus)1 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)1 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)1 CustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException)1 ActiveModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException)1 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)1 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)1 ModelDoesNotExistException (org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException)1 ModelExistsException (org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException)1