use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testCustomModelTypesAspectsDependencies.
@Test
public // SHA-679
void testCustomModelTypesAspectsDependencies() throws Exception {
setRequestContext(customModelAdmin);
String modelNameOne = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelNameOne, namespacePair, ModelStatus.DRAFT, null, "Mark Moe");
// Add type
String typeBaseName = "testTypeBase" + System.currentTimeMillis();
final String typeBaseNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeBaseName;
createTypeAspect(CustomType.class, modelNameOne, typeBaseName, "test typeBase title", "test typeBase Desc", "cm:content");
// Activate the model
CustomModel modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
HttpResponse response = getSingle("cmm", modelNameOne, 200);
CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(ModelStatus.ACTIVE, returnedModel.getStatus());
// Add another type with 'typeBaseName' as its parent
String typeName2 = "testTypeChild" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelNameOne, typeName2, "test typeChild title", "test typeChild Desc", typeBaseNameWithPrefix);
Paging paging = getPaging(0, Integer.MAX_VALUE);
response = getAll("cmm/" + modelNameOne + "/types", paging, 200);
List<CustomType> returnedTypes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomType.class);
assertEquals(2, returnedTypes.size());
// Create another model
String modelNameTwo = "testModelTwo" + System.currentTimeMillis();
Pair<String, String> modelTwoNamespacePair = getTestNamespaceUriPrefixPair();
createCustomModel(modelNameTwo, modelTwoNamespacePair, ModelStatus.DRAFT, null, "Admin");
// Add a type with 'typeBaseName' from the modelOne as its parent
String modelTwoTypeName = "testModelTwoChild" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelNameTwo, modelTwoTypeName, "test model two type child title", null, typeBaseNameWithPrefix);
// Try to deactivate modelOne
modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.DRAFT);
// ModelTwo depends on ModelOne
put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 409);
// Activate modelTwo
CustomModel modelTwoStatusPayload = new CustomModel();
modelTwoStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200);
// Try to deactivate modelOne again. The dependent model is Active now, however, the result should be the same.
// ModelTwo depends on ModelOne
put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 409);
// Deactivate modelTwo
modelTwoStatusPayload = new CustomModel();
modelTwoStatusPayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200);
// Delete the modelTwo's type as a Model Administrator
delete("cmm/" + modelNameTwo + "/types", modelTwoTypeName, 204);
// Try to deactivate modelOne again. There is no dependency
put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
}
use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testCreateAspectsAndTypesWithProperties.
@Test
public void testCreateAspectsAndTypesWithProperties() 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 aspect with property
String aspectName = "testAspect1" + System.currentTimeMillis();
CustomAspect aspect = new CustomAspect();
aspect.setName(aspectName);
String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
aspect.setProperties(props);
// Create aspect as a Model Administrator
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201);
// Retrieve the created aspect
HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
compareCustomTypesAspects(aspect, returnedAspect, "prefixedName", "dataType", "indexTokenisationMode");
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());
// Test default indexing options
assertTrue(customModelProperty.isIndexed());
assertEquals(Facetable.UNSET, customModelProperty.getFacetable());
assertEquals(IndexTokenisationMode.TRUE, customModelProperty.getIndexTokenisationMode());
}
{
// Add type with properties
String typeName = "testType1" + System.currentTimeMillis();
CustomType type = new CustomType();
type.setName(typeName);
type.setDescription("test type1 Desc");
type.setTitle("test type1 title");
type.setParentName("cm:content");
String typePropName = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typeProp = new CustomModelProperty();
typeProp.setName(typePropName);
// data type without dictionary prefix
typeProp.setDataType("int");
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
type.setProperties(props);
// Create type as a Model Administrator
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 400);
typeProp.setDataType("d:int");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201);
// Retrieve the created type
HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
compareCustomTypesAspects(type, returnedType, "prefixedName", "indexTokenisationMode");
assertEquals("Shouldn't list the inherited properties from 'cm:content'.", 1, returnedType.getProperties().size());
CustomModelProperty customModelProperty = returnedType.getProperties().get(0);
assertEquals(typePropName, customModelProperty.getName());
assertEquals("d:int", customModelProperty.getDataType());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typePropName, customModelProperty.getPrefixedName());
// Test default indexing options
assertTrue(customModelProperty.isIndexed());
assertEquals(Facetable.UNSET, customModelProperty.getFacetable());
assertEquals(IndexTokenisationMode.TRUE, customModelProperty.getIndexTokenisationMode());
}
{
// Add more types with the same parent
// Test to make sure the inherited properties are excluded properly.
// As without parent’s property exclusion, we won’t be able to
// create multiple types|aspects with the same parent.
String typeName2 = "testType2" + System.currentTimeMillis();
CustomType type2 = new CustomType();
type2.setName(typeName2);
type2.setDescription("test type2 Desc");
type2.setTitle("test type2 title");
type2.setParentName("cm:content");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type2), 201);
String typeName3 = "testType3" + System.currentTimeMillis();
CustomType type3 = new CustomType();
type3.setName(typeName3);
type3.setDescription("test type3 Desc");
type3.setTitle("test type3 title");
type3.setParentName("cm:content");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type3), 201);
}
{
// Retrieve the created model
HttpResponse response = getSingle("cmm", modelName, 200);
CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertNull(returnedModel.getTypes());
assertNull(returnedModel.getAspects());
// Retrieve the created model with its types and aspects
response = getSingle("cmm", modelName + SELECT_ALL, 200);
returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertNotNull(returnedModel.getTypes());
assertEquals(3, returnedModel.getTypes().size());
assertNotNull(returnedModel.getAspects());
assertEquals(1, returnedModel.getAspects().size());
}
}
use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testDeleteTypeAspect.
@Test
public void testDeleteTypeAspect() throws Exception {
setRequestContext(customModelAdmin);
final String modelName = "testDeleteTypeModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT, null, "Joe Bloggs");
// Add type
final String typeName = "testType" + System.currentTimeMillis();
final String typeNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName;
CustomType type = createTypeAspect(CustomType.class, modelName, typeName, "test type title", "test type Desc", "cm:content");
// Add aspect
final String aspectName = "testAspect" + System.currentTimeMillis();
final String aspectNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectName;
CustomAspect aspect = createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Delete type
{
setRequestContext(nonAdminUserName);
// Try to delete the model's type as a non Admin user
delete("cmm/" + modelName + "/types", typeName, 403);
setRequestContext(customModelAdmin);
// Delete the model's type as a Model Administrator
delete("cmm/" + modelName + "/types", typeName, 204);
// Try to retrieve the deleted type
getSingle("cmm/" + modelName + "/types", typeName, 404);
}
// Delete Aspect
{
setRequestContext(nonAdminUserName);
// Try to delete the model's aspect as a non Admin user
delete("cmm/" + modelName + "/aspects", aspectName, 403);
setRequestContext(customModelAdmin);
// Delete the model's aspect as a Model Administrator
delete("cmm/" + modelName + "/aspects", aspectName, 204);
// Try to retrieve the deleted aspect
getSingle("cmm/" + modelName + "/aspects", aspectName, 404);
}
setRequestContext(customModelAdmin);
// Create the type again
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201);
// Retrieve the created type
HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
compareCustomTypesAspects(type, returnedType, "prefixedName");
// Create the aspect again
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201);
// Retrieve the created aspect
response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
compareCustomTypesAspects(aspect, returnedAspect, "prefixedName");
// Update the Type by adding property
CustomType payload = new CustomType();
payload.setName(typeName);
String typePropName = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typeProp = new CustomModelProperty();
typeProp.setName(typePropName);
typeProp.setTitle("property title");
typeProp.setDataType("d:int");
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Activate the model
CustomModel statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.ACTIVE);
// Activate the model as a Model Administrator
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// Test for SHA-703
// Add another type with 'typeName' as its parent
final String childTypeName = "testChildType" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, childTypeName, "test child type title", null, typeNameWithPrefix);
// 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);
// Delete the model's type as a Model Administrator
// Cannot delete a type of an active model
delete("cmm/" + modelName + "/types", typeName, 409);
// Delete the model's aspect as a Model Administrator
// Cannot delete an aspect of an active model
delete("cmm/" + modelName + "/aspects", childAspectName, 409);
// Deactivate the model
statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.DRAFT);
// Deactivate the model as a Model Administrator
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// Delete type
{
// Try to delete the model's type (parent) as a Model Administrator
// conflict: childTypeName depends on typeName
delete("cmm/" + modelName + "/types", typeName, 409);
// Delete the child type first
delete("cmm/" + modelName + "/types", childTypeName, 204);
// Try to retrieve the deleted child type
getSingle("cmm/" + modelName + "/types", childTypeName, 404);
// Now delete the parent type
delete("cmm/" + modelName + "/types", typeName, 204);
// Try to retrieve the deleted parent type
getSingle("cmm/" + modelName + "/types", typeName, 404);
}
// Delete Aspect
{
// Try to delete the model's aspect (parent) as a Model Administrator
// conflict: childAspectName depends on aspectName
delete("cmm/" + modelName + "/aspects", aspectName, 409);
// Delete the child aspect first
delete("cmm/" + modelName + "/aspects", childAspectName, 204);
// Try to retrieve the deleted child aspect
getSingle("cmm/" + modelName + "/aspects", childAspectName, 404);
// Now delete the parent aspect
delete("cmm/" + modelName + "/aspects", aspectName, 204);
// Try to retrieve the deleted parent aspect
getSingle("cmm/" + modelName + "/aspects", aspectName, 404);
}
}
Aggregations