Search in sources :

Example 1 with ApiException

use of org.alfresco.rest.framework.core.exceptions.ApiException in project alfresco-remote-api by Alfresco.

the class MapBasedQueryWalker method processVariable.

protected void processVariable(String propertyName, String propertyValue, int type) {
    String localPropertyName = propertyName.replaceFirst("variables/", "");
    Object actualValue = null;
    DataTypeDefinition dataTypeDefinition = null;
    // variable scope global is default
    String scopeDef = "global";
    // look for variable scope
    if (localPropertyName.contains("local/")) {
        scopeDef = "local";
        localPropertyName = localPropertyName.replaceFirst("local/", "");
    }
    if (localPropertyName.contains("global/")) {
        localPropertyName = localPropertyName.replaceFirst("global/", "");
    }
    // look for variable type definition
    if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" ")) {
        int indexOfSpace = propertyValue.indexOf(' ');
        if ((propertyValue.contains("_") && indexOfSpace > propertyValue.indexOf("_")) || (propertyValue.contains(":") && indexOfSpace > propertyValue.indexOf(":"))) {
            String typeDef = propertyValue.substring(0, indexOfSpace);
            try {
                QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
                dataTypeDefinition = dictionaryService.getDataType(dataType);
                propertyValue = propertyValue.substring(indexOfSpace + 1);
            } catch (Exception e) {
                throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
            }
        }
    }
    if (dataTypeDefinition != null && "java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName())) {
        // fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
        actualValue = ISO8601DateFormat.parse(propertyValue);
    } else if (dataTypeDefinition != null) {
        actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, propertyValue);
    } else {
        actualValue = propertyValue;
    }
    variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue, scopeDef));
}
Also used : QName(org.alfresco.service.namespace.QName) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) ConversionException(org.apache.commons.beanutils.ConversionException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 2 with ApiException

use of org.alfresco.rest.framework.core.exceptions.ApiException 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);
    }
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) M2Model(org.alfresco.repo.dictionary.M2Model) 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)

Example 3 with ApiException

use of org.alfresco.rest.framework.core.exceptions.ApiException in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method createDownload.

@Override
public CustomModelDownload createDownload(String modelName, Parameters parameters) {
    // Check the current user is authorised to export the model
    validateCurrentUser();
    if (modelName == null) {
        throw new InvalidArgumentException(MODEL_NAME_NULL_ERR);
    }
    String propName = parameters.getParameter(PARAM_WITH_EXT_MODULE);
    boolean withForm = Boolean.valueOf(propName);
    try {
        NodeRef nodeRef = customModelService.createDownloadNode(modelName, withForm);
        return new CustomModelDownload(nodeRef);
    } catch (Exception ex) {
        String errorMsg = "cmm.rest_api.model_download_failure";
        if (ex.getMessage() != null) {
            errorMsg = ex.getMessage();
        }
        throw new ApiException(errorMsg, ex);
    }
}
Also used : CustomModelDownload(org.alfresco.rest.api.model.CustomModelDownload) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) 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)

Example 4 with ApiException

use of org.alfresco.rest.framework.core.exceptions.ApiException in project alfresco-remote-api by Alfresco.

the class DeletedNodesImpl method restoreArchivedNode.

@Override
public Node restoreArchivedNode(String archivedId, NodeTargetAssoc nodeTargetAssoc) {
    // First check the node is valid and has been archived.
    NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
    RestoreNodeReport restored = null;
    if (nodeTargetAssoc != null) {
        NodeRef targetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeTargetAssoc.getTargetParentId());
        QName assocType = nodes.getAssocType(nodeTargetAssoc.getAssocType());
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef, targetNodeRef, assocType, null);
    } else {
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
    }
    switch(restored.getStatus()) {
        case SUCCESS:
            return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
        case FAILURE_PERMISSION:
            throw new PermissionDeniedException();
        case FAILURE_INTEGRITY:
            throw new IntegrityException("Restore failed due to an integrity error", null);
        case FAILURE_DUPLICATE_CHILD_NODE_NAME:
            throw new ConstraintViolatedException("Name already exists in target");
        case FAILURE_INVALID_ARCHIVE_NODE:
            throw new EntityNotFoundException(archivedId);
        case FAILURE_INVALID_PARENT:
            throw new NotFoundException("Invalid parent id " + restored.getTargetParentNodeRef());
        default:
            throw new ApiException("Unable to restore node " + archivedId);
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 5 with ApiException

use of org.alfresco.rest.framework.core.exceptions.ApiException 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

ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)15 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)11 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)9 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)6 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)6 IOException (java.io.IOException)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 QName (org.alfresco.service.namespace.QName)5 FileBinaryResource (org.alfresco.rest.framework.resource.content.FileBinaryResource)4 File (java.io.File)3 InputStream (java.io.InputStream)3 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FileOutputStream (java.io.FileOutputStream)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2