use of org.alfresco.rest.api.model.CustomType in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testCreateModel_WithAspectsAndTypes_Invalid.
@Test
public void testCreateModel_WithAspectsAndTypes_Invalid() 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
{
final String typeURL = "cmm/" + modelName + "/types";
CustomType type = new CustomType();
type.setName(null);
type.setDescription("test type Desc");
// Try to create a model with an invalid type name (null)
post(typeURL, RestApiUtil.toJsonAsString(type), 400);
// Try to create a model with an invalid type name (name contains ':')
type.setName("prefix:someTypename");
post(typeURL, RestApiUtil.toJsonAsString(type), 400);
// Try to create a model with an invalid type name (name is empty)
type.setName("");
post(typeURL, RestApiUtil.toJsonAsString(type), 400);
// Try to create a model with an invalid type name (name contains '<')
type.setName("testType<name");
post(typeURL, RestApiUtil.toJsonAsString(type), 400);
}
// Add aspect
{
final String aspectURL = "cmm/" + modelName + "/aspects";
CustomAspect aspect = new CustomAspect();
aspect.setName(null);
aspect.setTitle("test aspect title");
// Try to create a model with an invalid aspect name (null)
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
// Try to create a model with an invalid aspect name (name contains ':')
aspect.setName("prefix:someAspectname");
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
// Try to create a model with an invalid aspect name (name is empty)
aspect.setName("");
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
// Try to create a model with an invalid aspect name (name contains '>')
aspect.setName("testType>name");
post(aspectURL, RestApiUtil.toJsonAsString(aspect), 400);
}
}
use of org.alfresco.rest.api.model.CustomType 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.CustomType 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);
}
}
use of org.alfresco.rest.api.model.CustomType in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testCreateAspectsAndTypes_ExistingModel.
@Test
public void testCreateAspectsAndTypes_ExistingModel() 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);
final String aspectName = "testAspect1" + System.currentTimeMillis();
{
// Add aspect
CustomAspect aspect = new CustomAspect();
aspect.setName(aspectName);
setRequestContext(nonAdminUserName);
// Try to create aspect as a non Admin user
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 403);
setRequestContext(customModelAdmin);
// Set the aspect's parent with a type name!
aspect.setParentName("cm:content");
// Try to create an invalid aspect as a Model Administrator
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409);
// Create aspect as a Model Administrator
aspect.setParentName(null);
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 201);
// Create the aspect again - duplicate name
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409);
// 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");
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectName, returnedAspect.getPrefixedName());
}
String typeName = "testType" + System.currentTimeMillis();
{
// Add type
CustomType type = new CustomType();
type.setName(typeName);
type.setDescription("test type Desc");
type.setTitle("test type title");
type.setParentName("cm:content");
setRequestContext(nonAdminUserName);
// Try to create type as a non Admin user
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 403);
setRequestContext(customModelAdmin);
// Set the type's parent with an aspect name!
type.setParentName("cm:titled");
// Try to create an invalid type as a Model Administrator
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409);
// Create type as a Model Administrator
type.setParentName("cm:content");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 201);
// Create the type again - duplicate name
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409);
// 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");
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName, returnedType.getPrefixedName());
// for now this is the simplest way to check for the imported namespaces
CustomModelDefinition modelDef = getModelDefinition(modelName);
assertNotNull(modelDef);
Collection<NamespaceDefinition> importedNamespaces = modelDef.getImportedNamespaces();
assertTrue(hasNamespaceUri(importedNamespaces, "http://www.alfresco.org/model/content/1.0"));
assertTrue(hasNamespacePrefix(importedNamespaces, "cm"));
}
// Existing name
{
// Add aspect
CustomAspect aspect = new CustomAspect();
// Set the aspect name with an existing type name. The model
// cannot have a type and an aspect with the same name.
aspect.setName(typeName);
post("cmm/" + modelName + "/aspects", RestApiUtil.toJsonAsString(aspect), 409);
CustomType type = new CustomType();
// Set the type name with an existing aspect name
type.setName(aspectName);
type.setParentName("cm:content");
post("cmm/" + modelName + "/types", RestApiUtil.toJsonAsString(type), 409);
}
}
Aggregations