Search in sources :

Example 51 with InvalidArgumentException

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

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

the class CustomModelsImpl method setM2Properties.

private void setM2Properties(M2Class m2Class, List<CustomModelProperty> properties, String namespacePrefix, Set<Pair<String, String>> namespacesToImport) {
    if (properties != null) {
        for (CustomModelProperty prop : properties) {
            validateName(prop.getName(), "cmm.rest_api.property_name_null");
            M2Property m2Property = m2Class.createProperty(constructName(prop.getName(), namespacePrefix));
            m2Property.setTitle(prop.getTitle());
            m2Property.setDescription(prop.getDescription());
            m2Property.setMandatory(prop.isMandatory());
            m2Property.setMandatoryEnforced(prop.isMandatoryEnforced());
            m2Property.setMultiValued(prop.isMultiValued());
            String dataType = prop.getDataType();
            // Default type is d:text
            if (StringUtils.isBlank(dataType)) {
                dataType = DEFAULT_DATA_TYPE;
            } else {
                if (!dataType.contains(":")) {
                    throw new InvalidArgumentException("cmm.rest_api.property_datatype_invalid", new Object[] { dataType });
                }
            }
            namespacesToImport.add(resolveToUriAndPrefix(dataType));
            try {
                // validate default values
                this.valueDataTypeValidator.validateValue(dataType, prop.getDefaultValue());
            } catch (Exception ex) {
                throw new InvalidArgumentException(ex.getMessage());
            }
            m2Property.setType(dataType);
            m2Property.setDefaultValue(prop.getDefaultValue());
            // Set indexing options
            m2Property.setIndexed(prop.isIndexed());
            // so it can support boolean data type.
            if (!BOOLEAN_DATA_TYPE.equals(dataType)) {
                if (Facetable.TRUE == prop.getFacetable()) {
                    m2Property.setFacetable(true);
                } else if (Facetable.FALSE == prop.getFacetable()) {
                    m2Property.setFacetable(false);
                }
            }
            m2Property.setIndexTokenisationMode(prop.getIndexTokenisationMode());
            // Check for constraints
            List<String> constraintRefs = prop.getConstraintRefs();
            List<CustomModelConstraint> constraints = prop.getConstraints();
            if (constraintRefs.size() > 0) {
                for (String ref : constraintRefs) {
                    Pair<String, String> prefixLocalName = splitPrefixedQName(ref);
                    if (!namespacePrefix.equals(prefixLocalName.getFirst())) {
                        throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.constraint_ref_not_defined", ref));
                    }
                    m2Property.addConstraintRef(ref);
                }
            }
            if (constraints.size() > 0) {
                for (CustomModelConstraint modelConstraint : constraints) {
                    String constraintName = null;
                    if (modelConstraint.getName() != null) {
                        validateName(modelConstraint.getName(), CONSTRAINT_NAME_NULL_ERR);
                        constraintName = constructName(modelConstraint.getName(), namespacePrefix);
                    }
                    M2Constraint m2Constraint = m2Property.addConstraint(constraintName, modelConstraint.getType());
                    // Set title, desc and parameters
                    setConstraintOtherData(modelConstraint, m2Constraint, dataType);
                }
            }
        }
    }
}
Also used : M2Constraint(org.alfresco.repo.dictionary.M2Constraint) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) M2Property(org.alfresco.repo.dictionary.M2Property) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) 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)

Example 53 with InvalidArgumentException

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

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

the class CustomModelsImpl method getCustomModelConstraint.

@Override
public CustomModelConstraint getCustomModelConstraint(String modelName, String constraintName, Parameters parameters) {
    if (constraintName == null) {
        throw new InvalidArgumentException(CONSTRAINT_NAME_NULL_ERR);
    }
    final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    QName constraintQname = QName.createQName(modelDef.getName().getNamespaceURI(), constraintName);
    ConstraintDefinition constraintDef = customModelService.getCustomConstraint(constraintQname);
    if (constraintDef == null) {
        throw new EntityNotFoundException(constraintName);
    }
    return new CustomModelConstraint(constraintDef, dictionaryService);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 55 with InvalidArgumentException

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

the class CustomModelsImpl method getCustomAspect.

@Override
public CustomAspect getCustomAspect(String modelName, String aspectName, Parameters parameters) {
    if (aspectName == null) {
        throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
    }
    final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    QName aspectQname = QName.createQName(modelDef.getName().getNamespaceURI(), aspectName);
    AspectDefinition customAspectDef = customModelService.getCustomAspect(aspectQname);
    if (customAspectDef == null) {
        throw new EntityNotFoundException(aspectName);
    }
    // Check if inherited properties have been requested
    boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
    return convertToCustomAspect(customAspectDef, includeInheritedProps);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Aggregations

InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)132 NodeRef (org.alfresco.service.cmr.repository.NodeRef)39 QName (org.alfresco.service.namespace.QName)37 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)31 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)24 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)20 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)17 Serializable (java.io.Serializable)12 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)12 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 Paging (org.alfresco.rest.framework.resource.parameters.Paging)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)9 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)9 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)9 Pair (org.alfresco.util.Pair)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Params (org.alfresco.rest.framework.resource.parameters.Params)8 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)7