use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method validateTypeAspectParent.
private void validateTypeAspectParent(AbstractClassModel typeAspect, CustomModel existingModel) {
String parentPrefixedName = typeAspect.getParentName();
if (StringUtils.isBlank(parentPrefixedName)) {
return;
}
Pair<String, String> prefixLocaNamePair = splitPrefixedQName(parentPrefixedName);
String parentPrefix = prefixLocaNamePair.getFirst();
String parentLocalName = prefixLocaNamePair.getSecond();
// Validate parent prefix and localName
// We know that the values are not null, we just check against the defined RegEx
validateName(parentPrefix, null);
validateName(parentLocalName, null);
final boolean isAspect = (typeAspect instanceof CustomAspect);
ClassDefinition classDefinition = null;
QName qname = null;
if (existingModel.getNamespacePrefix().equals(parentPrefix)) {
// Check for types/aspects within the model
qname = QName.createQName(existingModel.getNamespaceUri(), parentLocalName);
classDefinition = (isAspect) ? customModelService.getCustomAspect(qname) : customModelService.getCustomType(qname);
} else {
// Make sure the namespace URI and Prefix are registered
Pair<String, String> uriPrefixPair = resolveToUriAndPrefix(parentPrefixedName);
qname = QName.createQName(uriPrefixPair.getFirst(), parentLocalName);
classDefinition = (isAspect) ? dictionaryService.getAspect(qname) : dictionaryService.getType(qname);
}
if (classDefinition == null) {
String msgId = (isAspect) ? "cmm.rest_api.aspect_parent_not_exist" : "cmm.rest_api.type_parent_not_exist";
throw new ConstraintViolatedException(I18NUtil.getMessage(msgId, parentPrefixedName));
} else {
checkCircularDependency(classDefinition.getModel(), existingModel, parentPrefixedName);
}
}
use of org.alfresco.rest.api.model.CustomAspect 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);
}
use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class BaseCustomModelApiTest method createTypeAspect.
protected <T extends AbstractClassModel> T createTypeAspect(Class<T> glazz, String modelName, String typeAspectName, String title, String desc, String parent) throws Exception {
AbstractClassModel classModel = null;
String uri = "cmm/" + modelName;
if (glazz.equals(CustomType.class)) {
classModel = new CustomType();
uri += "/types";
} else {
classModel = new CustomAspect();
uri += "/aspects";
}
classModel.setName(typeAspectName);
classModel.setDescription(desc);
classModel.setTitle(title);
classModel.setParentName(parent);
// Create type as a Model Administrator
HttpResponse response = post(uri, RestApiUtil.toJsonAsString(classModel), 201);
T returnedClassModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), glazz);
compareCustomTypesAspects(classModel, returnedClassModel, "prefixedName");
return returnedClassModel;
}
use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testCreateListConstraintInvalid.
@Test
public void testCreateListConstraintInvalid() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelConstraintInvalid" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Create aspect
String aspectName = "testAspect" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
// Update the Aspect by adding property
CustomAspect aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
final String aspectPropName = "testAspect1Prop" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setDataType("d:int");
// Create LIST constraint
String inlineListConstraintName = "testListConstraint" + System.currentTimeMillis();
CustomModelConstraint inlineListConstraint = new CustomModelConstraint();
inlineListConstraint.setName(inlineListConstraintName);
inlineListConstraint.setType("LIST");
inlineListConstraint.setTitle("test List title");
inlineListConstraint.setDescription("test List desc");
// Create the List constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(3);
// text list value, but the the property data type is d:int
parameters.add(buildNamedValue("allowedValues", null, "a", "b", "c"));
parameters.add(buildNamedValue("sorted", "false"));
// Add the parameters into the constraint
inlineListConstraint.setParameters(parameters);
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Try to create the property - Invalid LIST values
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
// Test d:double LIST values with d:int property data type
parameters = new ArrayList<>(3);
// double list value, but the the property data type is d:int
parameters.add(buildNamedValue("allowedValues", null, "1.0", "2.0", "3.0"));
parameters.add(buildNamedValue("sorted", "false"));
// Add the parameters into the constraint
inlineListConstraint.setParameters(parameters);
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Try to create the property - Invalid LIST values
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
}
use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testPropDefaultValueWithConstraintRef.
@Test
public void testPropDefaultValueWithConstraintRef() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelConstraintRef" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
{
// Create List constraint
String listConstraintName = "testListConstraint" + System.currentTimeMillis();
CustomModelConstraint listConstraint = new CustomModelConstraint();
listConstraint.setName(listConstraintName);
listConstraint.setType("LIST");
// Create the List constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(3);
// list value
parameters.add(buildNamedValue("allowedValues", null, "London", "Paris", "New York"));
parameters.add(buildNamedValue("sorted", "false"));
// Add the parameters into the constraint
listConstraint.setParameters(parameters);
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(listConstraint), 201);
// Retrieve the created List constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", listConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
// Create aspect
String aspectName = "testAspect" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
// Update the Aspect by adding property
CustomAspect aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
final String aspectPropName = "testAspect1Prop" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property with LIST constraint ref");
aspectProp.setDataType("d:text");
// Not in the list
aspectProp.setDefaultValue("Berlin");
// constrain ref
aspectProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Try to create the property - constraint violation
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409);
}
{
// Create MINMAX constraint
String minMaxConstraintName = "testMinMaxConstraint" + System.currentTimeMillis();
CustomModelConstraint minMaxConstraint = new CustomModelConstraint();
minMaxConstraint.setName(minMaxConstraintName);
minMaxConstraint.setType("MINMAX");
// Create the MinMax constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("maxValue", "100"));
parameters.add(buildNamedValue("minValue", "50"));
// Add the parameters into the constraint
minMaxConstraint.setParameters(parameters);
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 201);
// Retrieve the created MinMax constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", minMaxConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
// Create type
String typeName = "testType1" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, typeName, "test type1 title", "test type1 Desc", "cm:content");
// Update the Type by adding property
CustomType typePayload = new CustomType();
typePayload.setName(typeName);
String typePropName = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typeProp = new CustomModelProperty();
typeProp.setName(typePropName);
typeProp.setTitle("property with MINMAX constraint ref");
typeProp.setDataType("d:int");
// Not in the defined range [50,100]
typeProp.setDefaultValue("35");
// constrain ref
typeProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
typePayload.setProperties(props);
// Try to create the property - constraint violation
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409);
}
}
Aggregations