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);
}
}
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);
}
}
}
}
}
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);
}
}
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);
}
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);
}
Aggregations