use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testCreateMinMaxConstraintInvalid.
@Test
public void testCreateMinMaxConstraintInvalid() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelMinMaxInvalid" + 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:text");
String minMaxConstraintName = "testMinMaxConstraint" + System.currentTimeMillis();
CustomModelConstraint minMaxConstraint = new CustomModelConstraint();
minMaxConstraint.setType("MINMAX");
minMaxConstraint.setName(minMaxConstraintName);
minMaxConstraint.setTitle("test MinMax title");
minMaxConstraint.setDescription("test MinMax desc");
// Create the MinMax constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("maxValue", "100.0"));
parameters.add(buildNamedValue("minValue", "0.0"));
// Add the parameters into the constraint
minMaxConstraint.setParameters(parameters);
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(minMaxConstraint));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Try to create constraint as a Model Administrator
// MINMAX constraint can only be used with numeric data type.
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
// Change type
aspectProp.setDataType("d:datetime");
// MINMAX constraint can only be used with numeric data type.
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
// SHA-1126
{
// Change type
aspectProp.setDataType("d:double");
parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("maxValue", "0.0"));
parameters.add(buildNamedValue("minValue", "-5.0"));
// Add the parameters into the constraint
minMaxConstraint.setParameters(parameters);
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(minMaxConstraint));
props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Maximum value of the MINMAX constraint must be a positive nonzero value.
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 testCreateInlineConstraint.
@Test
public void testCreateInlineConstraint() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelInlineConstraint" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
String regExConstraintName = "testInlineFileNameRegEx" + System.currentTimeMillis();
{
// Create RegEx constraint
CustomModelConstraint inlineRegExConstraint = new CustomModelConstraint();
inlineRegExConstraint.setName(regExConstraintName);
inlineRegExConstraint.setType("REGEX");
// Create the inline RegEx constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("expression", "(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)"));
parameters.add(buildNamedValue("requiresMatch", "false"));
// Add the parameters into the constraint
inlineRegExConstraint.setParameters(parameters);
// Create aspect
String aspectName = "testAspect1" + 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 = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setDataType("d:text");
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(inlineRegExConstraint));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Create the property
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200);
// Retrieve all the model's constraints
Paging paging = getPaging(0, Integer.MAX_VALUE);
HttpResponse response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals("Inline constraints should not be included with the model defined constraints.", 0, constraints.size());
// Retrieve the updated aspect
response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
// Check the aspect's added property
assertEquals(1, returnedAspect.getProperties().size());
CustomModelProperty customModelProperty = returnedAspect.getProperties().get(0);
assertEquals(aspectPropName, customModelProperty.getName());
assertEquals(0, customModelProperty.getConstraintRefs().size());
List<CustomModelConstraint> inlineConstraints = customModelProperty.getConstraints();
assertEquals(1, inlineConstraints.size());
compareCustomModelConstraints(inlineRegExConstraint, inlineConstraints.get(0), "prefixedName");
}
// Create inline and referenced constraint
{
// Create RegEx constraint
CustomModelConstraint regExConstraint = new CustomModelConstraint();
// duplicate name
regExConstraint.setName(regExConstraintName);
regExConstraint.setType("REGEX");
regExConstraint.setTitle("test RegEx title");
// Create the RegEx constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("expression", "(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)"));
parameters.add(buildNamedValue("requiresMatch", "false"));
// Add the parameters into the constraint
regExConstraint.setParameters(parameters);
// Try to create constraint as a Model Administrator
// duplicate name
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 409);
String newRegExConstraintName = "testFileNameRegEx" + System.currentTimeMillis();
regExConstraint.setName(newRegExConstraintName);
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201);
// Retrieve the created RegEx constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", newRegExConstraintName, 200);
CustomModelConstraint returnedRegExConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
// Create inline anonymous LENGTH constraint
CustomModelConstraint inlineAnonymousLengthConstraint = new CustomModelConstraint();
inlineAnonymousLengthConstraint.setType("LENGTH");
inlineAnonymousLengthConstraint.setTitle("test Length title");
// Create the Length constraint's parameters
parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("maxLength", "256"));
parameters.add(buildNamedValue("minLength", "0"));
// Add the parameters into the constraint
inlineAnonymousLengthConstraint.setParameters(parameters);
// Create type
String typeName = "testType1" + System.currentTimeMillis();
CustomType type = 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 title");
typeProp.setDataType("d:int");
// Constraint Ref
typeProp.setConstraintRefs(Arrays.asList(returnedRegExConstraint.getPrefixedName()));
// inline constraint
typeProp.setConstraints(Arrays.asList(inlineAnonymousLengthConstraint));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
typePayload.setProperties(props);
// Try to create the property - LENGTH constraint can only be used with textual data type
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 400);
typeProp.setDataType("d:double");
// CTry to create the property - LENGTH constraint can only be used with textual data type
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 400);
typeProp.setDataType("d:text");
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added property
assertEquals(1, returnedType.getProperties().size());
CustomModelProperty customModelProperty = returnedType.getProperties().get(0);
assertEquals(typePropName, customModelProperty.getName());
assertEquals(1, customModelProperty.getConstraintRefs().size());
assertEquals(returnedRegExConstraint.getPrefixedName(), customModelProperty.getConstraintRefs().get(0));
assertEquals(1, customModelProperty.getConstraints().size());
// M2PropertyDefinition will add a name
assertNotNull(customModelProperty.getConstraints().get(0).getName());
compareCustomModelConstraints(inlineAnonymousLengthConstraint, customModelProperty.getConstraints().get(0), "prefixedName", "name");
}
}
use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class TestCustomModel method testUpdateModel_WithAspectsAndTypes.
@Test
public // SHA-726
void testUpdateModel_WithAspectsAndTypes() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Add type
String typeBaseName = "testTypeBase" + System.currentTimeMillis();
final String typeBaseNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeBaseName;
createTypeAspect(CustomType.class, modelName, typeBaseName, "test typeBase title", null, "cm:content");
// Add aspect
final String aspectName = "testAspect" + System.currentTimeMillis();
final String aspectNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectName;
createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Activate the model
CustomModel modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
// Add another type with 'typeBaseName' as its parent
String childTypeName = "testTypeChild" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, childTypeName, "test typeChild title", "test typeChild Desc", typeBaseNameWithPrefix);
// Add another aspect with 'aspectName' as its parent
final String childAspectName = "testChildAspect" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, childAspectName, "test child aspect title", null, aspectNameWithPrefix);
// Deactivate the model
modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
// Test update the namespace prefix
CustomModel updatePayload = new CustomModel();
String modifiedPrefix = namespacePair.getSecond() + "Modified";
updatePayload.setNamespacePrefix(modifiedPrefix);
updatePayload.setNamespaceUri(namespacePair.getFirst());
HttpResponse response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200);
CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix());
assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri());
// Test update the namespace URI
updatePayload = new CustomModel();
updatePayload.setNamespacePrefix(modifiedPrefix);
String modifiedURI = namespacePair.getFirst() + "Modified";
updatePayload.setNamespaceUri(modifiedURI);
response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200);
returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedURI, returnedModel.getNamespaceUri());
assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix());
// Retrieve the child type
response = getSingle("cmm/" + modelName + "/types", childTypeName, 200);
CustomType returnedChildType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
final String newTypeParentName = modifiedPrefix + QName.NAMESPACE_PREFIX + typeBaseName;
assertEquals("The parent name prefix should have been updated.", newTypeParentName, returnedChildType.getParentName());
// Retrieve the child aspect
response = getSingle("cmm/" + modelName + "/aspects", childAspectName, 200);
CustomAspect returnedChildAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
final String newAspectParentName = modifiedPrefix + QName.NAMESPACE_PREFIX + aspectName;
assertEquals("The parent name prefix should have been updated.", newAspectParentName, returnedChildAspect.getParentName());
}
use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class TestCustomProperty method testCreateProperties.
@Test
public void testCreateProperties() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
{
// Create aspect
String aspectName = "testAspect1" + System.currentTimeMillis();
CustomAspect aspect = createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Update the Aspect by adding property
CustomAspect payload = new CustomAspect();
String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setMultiValued(true);
aspectProp.setIndexed(true);
aspectProp.setFacetable(Facetable.TRUE);
aspectProp.setIndexTokenisationMode(IndexTokenisationMode.BOTH);
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
payload.setProperties(props);
setRequestContext(nonAdminUserName);
// Try to update the aspect as a non Admin user
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403);
setRequestContext(customModelAdmin);
// Try to update the aspect as a Model Administrator
// Type name is mandatory
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400);
// Add the mandatory aspect name to the payload
payload.setName(aspectName);
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Retrieve the updated aspect
HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
// Check the aspect's added property
assertEquals(1, returnedAspect.getProperties().size());
CustomModelProperty customModelProperty = returnedAspect.getProperties().get(0);
assertEquals(aspectPropName, customModelProperty.getName());
assertEquals("property title", customModelProperty.getTitle());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectPropName, customModelProperty.getPrefixedName());
assertEquals("Default data type is 'd:text'.", "d:text", customModelProperty.getDataType());
assertNull(customModelProperty.getDescription());
assertTrue(customModelProperty.isMultiValued());
assertFalse(customModelProperty.isMandatory());
assertFalse(customModelProperty.isMandatoryEnforced());
assertNull(customModelProperty.getDefaultValue());
assertTrue(customModelProperty.isIndexed());
assertEquals(Facetable.TRUE, customModelProperty.getFacetable());
assertEquals(IndexTokenisationMode.BOTH, customModelProperty.getIndexTokenisationMode());
// Test duplicate property name
aspectProp = new CustomModelProperty();
// Existing name
aspectProp.setName(aspectPropName);
aspectProp.setTitle("new property title");
props = new ArrayList<>(1);
props.add(aspectProp);
payload.setProperties(props);
// Try to update the aspect as a Model Administrator
// property name already exists
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409);
}
{
// Create type
String typeName = "testType1" + System.currentTimeMillis();
CustomType type = createTypeAspect(CustomType.class, modelName, typeName, "test type1 title", "test type1 Desc", "cm:content");
// Update the Type by adding property
CustomType payload = new CustomType();
String typePropName = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typeProp = new CustomModelProperty();
typeProp.setName(typePropName);
typeProp.setTitle("property title");
typeProp.setDataType("d:int");
typeProp.setIndexed(false);
typeProp.setFacetable(Facetable.FALSE);
typeProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
setRequestContext(nonAdminUserName);
// Try to update the type as a non Admin user
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403);
setRequestContext(customModelAdmin);
// Try to update the type as a Model Administrator
// Type name is mandatory
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400);
// Add the mandatory type name to the payload
payload.setName(typeName);
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added property
assertEquals(1, returnedType.getProperties().size());
CustomModelProperty customModelProperty = returnedType.getProperties().get(0);
assertEquals(typePropName, customModelProperty.getName());
assertEquals("property title", customModelProperty.getTitle());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typePropName, customModelProperty.getPrefixedName());
assertEquals("d:int", customModelProperty.getDataType());
assertNull(customModelProperty.getDescription());
assertFalse(customModelProperty.isMultiValued());
assertFalse(customModelProperty.isMandatory());
assertFalse(customModelProperty.isMandatoryEnforced());
assertNull(customModelProperty.getDefaultValue());
assertFalse(customModelProperty.isIndexed());
assertEquals(Facetable.FALSE, customModelProperty.getFacetable());
assertEquals(IndexTokenisationMode.FALSE, customModelProperty.getIndexTokenisationMode());
// Retrieve the updated type with all the properties (include inherited)
response = getSingle("cmm/" + modelName + "/types", type.getName() + SELECT_ALL_PROPS, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals(3, returnedType.getProperties().size());
// Check for the inherited properties
// cm:content
assertNotNull(getProperty(returnedType.getProperties(), "content"));
// cm:name
assertNotNull(getProperty(returnedType.getProperties(), "name"));
// Create another property and set all of its attributes
payload = new CustomType();
payload.setName(typeName);
String typePropName2 = "testType1Prop2" + System.currentTimeMillis();
typeProp = new CustomModelProperty();
typeProp.setName(typePropName2);
typeProp.setTitle("property2 title");
typeProp.setDescription("property2 desciption");
typeProp.setDataType("d:int");
typeProp.setDefaultValue("0");
typeProp.setMultiValued(false);
typeProp.setMandatory(true);
typeProp.setMandatoryEnforced(true);
props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added property
assertEquals(2, returnedType.getProperties().size());
customModelProperty = getProperty(returnedType.getProperties(), typePropName2);
assertNotNull(customModelProperty);
assertEquals(typePropName2, customModelProperty.getName());
assertEquals("property2 title", customModelProperty.getTitle());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typePropName2, customModelProperty.getPrefixedName());
assertEquals("d:int", customModelProperty.getDataType());
assertEquals("property2 desciption", customModelProperty.getDescription());
assertFalse(customModelProperty.isMultiValued());
assertTrue(customModelProperty.isMandatory());
assertTrue(customModelProperty.isMandatoryEnforced());
assertEquals("0", customModelProperty.getDefaultValue());
// Test duplicate property name
typeProp = new CustomModelProperty();
// Existing name
typeProp.setName(typePropName2);
typeProp.setTitle("new property title");
typeProp.setDataType("d:text");
props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
// property name already exists
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409);
}
}
use of org.alfresco.rest.api.model.CustomAspect in project alfresco-remote-api by Alfresco.
the class TestCustomProperty method testDeleteProperty.
@Test
public void testDeleteProperty() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelDeleteProp" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
/*
* Create aspect and update it by adding two properties
*/
String aspectName = "testAspect1" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Update the Aspect by adding property - property one
CustomAspect aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
String aspectPropNameOne = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectPropOne = new CustomModelProperty();
aspectPropOne.setName(aspectPropNameOne);
aspectPropOne.setTitle("aspect property one title");
aspectPropOne.setMultiValued(true);
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectPropOne);
aspectPayload.setProperties(props);
// create property one
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200);
// Update the Aspect by adding another property - property two
aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
String aspectPropNameTwo = "testAspect1Prop2" + System.currentTimeMillis();
CustomModelProperty aspectPropTwo = new CustomModelProperty();
aspectPropTwo.setName(aspectPropNameTwo);
aspectPropTwo.setTitle("aspect property two title");
aspectPropTwo.setMandatory(true);
aspectPropTwo.setDataType("d:int");
aspectPropTwo.setDefaultValue("1");
props = new ArrayList<>(1);
props.add(aspectPropTwo);
aspectPayload.setProperties(props);
// create property two
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200);
// Retrieve the updated aspect
HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
// Check the aspect's added properties
assertEquals(2, returnedAspect.getProperties().size());
/*
* Create type and update it by adding two properties
*/
String typeName = "testType1" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, typeName, "test type1 title", null, "cm:content");
// Update the Type by adding property - property one
CustomType typePayload = new CustomType();
typePayload.setName(typeName);
String typePropNameOne = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typePropOne = new CustomModelProperty();
typePropOne.setName(typePropNameOne);
typePropOne.setTitle("type property one title");
props = new ArrayList<>(1);
props.add(typePropOne);
typePayload.setProperties(props);
// create property one
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200);
// Update the Type by adding another property - property two
typePayload = new CustomType();
typePayload.setName(typeName);
// Create inline MINMAX constraint
CustomModelConstraint inlineMinMaxConstraint = new CustomModelConstraint();
inlineMinMaxConstraint.setType("MINMAX");
inlineMinMaxConstraint.setTitle("test MINMAX title");
// Create the MinMax constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("maxValue", "100.0"));
parameters.add(buildNamedValue("minValue", "0.0"));
// Add the parameters into the constraint
inlineMinMaxConstraint.setParameters(parameters);
String typePropNameTwo = "testType1Prop2" + System.currentTimeMillis();
CustomModelProperty typePropTwo = new CustomModelProperty();
typePropTwo.setName(typePropNameTwo);
typePropTwo.setTitle("type property two title");
typePropTwo.setDataType("d:int");
// add the inline constraint
typePropTwo.setConstraints(Arrays.asList(inlineMinMaxConstraint));
props = new ArrayList<>(1);
props.add(typePropTwo);
typePayload.setProperties(props);
// create property one
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
response = getSingle("cmm/" + modelName + "/types", typeName, 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added properties
assertEquals(2, returnedType.getProperties().size());
// Delete aspect's property one - model is inactive
{
final String deletePropOneAspectQS = getPropDeleteUpdateQS(aspectPropNameOne, true);
// Try to delete propertyOne from aspect
// missing payload
put("cmm/" + modelName + "/aspects", aspectName, null, deletePropOneAspectQS, 400);
CustomAspect deletePropAspectPayload = new CustomAspect();
// missing aspect name
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 400);
setRequestContext(nonAdminUserName);
deletePropAspectPayload.setName(aspectName);
// unauthorised
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 403);
setRequestContext(customModelAdmin);
// Delete as a Model Administrator
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
assertEquals(1, returnedAspect.getProperties().size());
assertFalse("Property one should have been deleted.", aspectPropNameOne.equals(returnedAspect.getProperties().get(0).getName()));
// Not found
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 404);
}
// Delete type's property two - model is inactive
{
final String deletePropTwoTypeQS = getPropDeleteUpdateQS(typePropNameTwo, true);
// Try to delete propertyOne from type
// missing payload
put("cmm/" + modelName + "/types", typeName, null, deletePropTwoTypeQS, 400);
CustomType deletePropTypePayload = new CustomType();
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, // missing type name
400);
setRequestContext(nonAdminUserName);
deletePropTypePayload.setName(typeName);
// unauthorised
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 403);
setRequestContext(customModelAdmin);
// Delete as a Model Administrator
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/types", typeName, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals(1, returnedType.getProperties().size());
assertFalse("Property two should have been deleted.", typePropNameTwo.equals(returnedType.getProperties().get(0).getName()));
// Not found
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 404);
}
/*
* APPSREPO-59: delete the last property of a Type / Aspect for an active model
*/
// Activate the model
CustomModel statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// Delete aspect's property two - model is active
{
setRequestContext(customModelAdmin);
final String deletePropTwoAspectQS = getPropDeleteUpdateQS(aspectPropNameTwo, true);
CustomAspect deletePropAspectPayload = new CustomAspect();
deletePropAspectPayload.setName(aspectName);
// Delete as a Model Administrator
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropTwoAspectQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
assertEquals("Property two should have been deleted.", 0, returnedAspect.getProperties().size());
// Not found
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropTwoAspectQS, 404);
}
// Delete type's property one - model is active
{
final String deletePropOneTypeQS = getPropDeleteUpdateQS(typePropNameOne, true);
CustomType deletePropTypePayload = new CustomType();
deletePropTypePayload.setName(typeName);
// Delete as a Model Administrator
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropOneTypeQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/types", typeName, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals("Property one should have been deleted.", 0, returnedType.getProperties().size());
// Not found
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropOneTypeQS, 404);
}
}
Aggregations