use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class CustomModelUploadPost method processUpload.
protected ImportResult processUpload(ZipFile zipFile, String filename) throws IOException {
if (zipFile.size() > 2) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_package");
}
CustomModel customModel = null;
String shareExtModule = null;
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
final String entryName = entry.getName();
try (InputStream input = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE)) {
if (!(entryName.endsWith(CustomModelServiceImpl.SHARE_EXT_MODULE_SUFFIX)) && customModel == null) {
try {
M2Model m2Model = M2Model.createModel(input);
customModel = importModel(m2Model);
} catch (DictionaryException ex) {
if (shareExtModule == null) {
// Get the input stream again, as the zip file doesn't support reset.
try (InputStream moduleInputStream = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE)) {
shareExtModule = getExtensionModule(moduleInputStream, entryName);
}
if (shareExtModule == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_entry_format", new Object[] { entryName });
}
} else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_model_entry", new Object[] { entryName });
}
}
} else {
shareExtModule = getExtensionModule(input, entryName);
if (shareExtModule == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { entryName });
}
}
}
}
}
return new ImportResult(customModel, shareExtModule);
}
use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testCreateConstraintAndAddToProperty.
@Test
public void testCreateConstraintAndAddToProperty() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelConstraint" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Create RegEx constraint
String regExConstraintName = "testFileNameRegEx" + System.currentTimeMillis();
CustomModelConstraint regExConstraint = new CustomModelConstraint();
regExConstraint.setName(regExConstraintName);
regExConstraint.setType("REGEX");
regExConstraint.setTitle("test RegEx title");
regExConstraint.setDescription("test RegEx desc");
// 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);
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201);
// Retrieve the created constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", regExConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
// Retrieve all the model's constraints
Paging paging = getPaging(0, Integer.MAX_VALUE);
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(1, constraints.size());
// Create aspect
String aspectName = "testAspect1" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
// Update the Aspect by adding property
CustomAspect payload = new CustomAspect();
payload.setName(aspectName);
final String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setDataType("d:text");
// Add the constraint ref
aspectProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
payload.setProperties(props);
// Create the property
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Activate the model
CustomModel updatePayload = new CustomModel();
updatePayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
// Retrieve all the model's constraints
// Test to see if the API took care of duplicate constraints when referencing a constraint within a property.
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(1, constraints.size());
// Test RegEx constrain enforcement
{
final NodeService nodeService = repoService.getNodeService();
final QName aspectQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectName);
TestNetwork testNetwork = getTestFixture().getRandomNetwork();
TestPerson person = testNetwork.createUser();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
nodeService.addAspect(nodeRef, aspectQName, null);
assertTrue(nodeService.hasAspect(nodeRef, aspectQName));
try {
QName propQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectPropName);
nodeService.setProperty(nodeRef, propQName, "Invalid$Char.");
fail("Invalid property value. Should have caused integrity violations.");
} catch (Exception e) {
// Expected
}
// Permanently remove model from repository
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
nodeService.deleteNode(nodeRef);
return null;
}
}, person.getId(), testNetwork.getId());
}
setRequestContext(customModelAdmin);
// Deactivate the model
updatePayload = new CustomModel();
updatePayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
// Test update the namespace prefix (test to see if the API updates the constraints refs with this new prefix)
CustomModel updateModelPayload = new CustomModel();
String modifiedPrefix = namespacePair.getSecond() + "Modified";
updateModelPayload.setNamespacePrefix(modifiedPrefix);
updateModelPayload.setNamespaceUri(namespacePair.getFirst());
response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), 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
updateModelPayload = new CustomModel();
updateModelPayload.setNamespacePrefix(modifiedPrefix);
String modifiedURI = namespacePair.getFirst() + "Modified";
updateModelPayload.setNamespaceUri(modifiedURI);
response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedURI, returnedModel.getNamespaceUri());
assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix());
}
use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testCreateConstraints.
@Test
public void testCreateConstraints() throws Exception {
setRequestContext(customModelAdmin);
final Paging paging = getPaging(0, Integer.MAX_VALUE);
String modelName = "testModelConstraint" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Create RegEx constraint
{
String regExConstraintName = "testFileNameRegEx" + System.currentTimeMillis();
CustomModelConstraint regExConstraint = new CustomModelConstraint();
regExConstraint.setName(regExConstraintName);
regExConstraint.setType("REGEX");
regExConstraint.setTitle("test RegEx title");
regExConstraint.setDescription("test RegEx desc");
// 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);
setRequestContext(nonAdminUserName);
// Try to create constraint as a non Admin user
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 403);
setRequestContext(customModelAdmin);
// 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", regExConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
compareCustomModelConstraints(regExConstraint, returnedConstraint, "prefixedName");
// Try to create a duplicate constraint
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 409);
// Retrieve all the model's constraints
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(1, constraints.size());
}
setRequestContext(customModelAdmin);
// Try to create invalid RegEx constraint
{
String regExConstraintName = "testFileNameInvalidRegEx" + System.currentTimeMillis();
CustomModelConstraint regExConstraint = new CustomModelConstraint();
regExConstraint.setName(regExConstraintName);
regExConstraint.setType("REGEX");
// 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
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 400);
}
// Create MINMAX constraint
{
String minMaxConstraintName = "testMinMaxConstraint" + System.currentTimeMillis();
CustomModelConstraint minMaxConstraint = new CustomModelConstraint();
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);
// Try to create constraint as a Model Administrator
// constraint's type is mandatory
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 400);
minMaxConstraint.setType("MINMAX");
parameters.clear();
// invalid number
parameters.add(buildNamedValue("maxValue", "abc"));
parameters.add(buildNamedValue("minValue", "0.0"));
// Add the parameters into the constraint
minMaxConstraint.setParameters(parameters);
// Try to create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 400);
parameters.clear();
parameters.add(buildNamedValue("maxValue", "100"));
// invalid number
parameters.add(buildNamedValue("minValue", "text"));
// Add the parameters into the constraint
minMaxConstraint.setParameters(parameters);
// Try to create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(minMaxConstraint), 400);
parameters.clear();
parameters.add(buildNamedValue("maxValue", "100.0"));
parameters.add(buildNamedValue("minValue", "0.0"));
// 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);
compareCustomModelConstraints(minMaxConstraint, returnedConstraint, "prefixedName");
// Retrieve all the model's constraints
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(2, constraints.size());
}
// Create LENGTH constraint
{
String lengthConstraintName = "testLengthConstraint" + System.currentTimeMillis();
CustomModelConstraint lengthConstraint = new CustomModelConstraint();
lengthConstraint.setName(lengthConstraintName);
lengthConstraint.setType("LENGTH");
lengthConstraint.setTitle("test Length title");
lengthConstraint.setDescription("test Length desc");
// Create the Length constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
// invalid number
parameters.add(buildNamedValue("maxLength", "text"));
parameters.add(buildNamedValue("minLength", "0"));
// Add the parameters into the constraint
lengthConstraint.setParameters(parameters);
// Try to create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(lengthConstraint), 400);
parameters.clear();
parameters.add(buildNamedValue("maxLength", "256"));
// double number
parameters.add(buildNamedValue("minLength", "1.0"));
// Add the parameters into the constraint
lengthConstraint.setParameters(parameters);
// Try to create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(lengthConstraint), 400);
parameters.clear();
parameters.add(buildNamedValue("maxLength", "256"));
parameters.add(buildNamedValue("minLength", "0"));
// Add the parameters into the constraint
lengthConstraint.setParameters(parameters);
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(lengthConstraint), 201);
// Retrieve the created LENGTH constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", lengthConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
compareCustomModelConstraints(lengthConstraint, returnedConstraint, "prefixedName");
// Retrieve all the model's constraints
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(3, constraints.size());
}
// Create LIST constraint
{
String listConstraintName = "testListConstraint" + System.currentTimeMillis();
CustomModelConstraint listConstraint = new CustomModelConstraint();
listConstraint.setName(listConstraintName);
listConstraint.setType("LIST");
listConstraint.setTitle("test List title");
listConstraint.setDescription("test List desc");
// Create the List constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(3);
// list value
parameters.add(buildNamedValue("allowedValues", null, "High", "Normal", "Low"));
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);
compareCustomModelConstraints(listConstraint, returnedConstraint, "prefixedName", "parameters");
String sorted = getParameterSimpleValue(returnedConstraint.getParameters(), "sorted");
assertEquals("false", sorted);
List<String> listValues = getParameterListValue(returnedConstraint.getParameters(), "allowedValues");
assertNotNull(listValues);
assertEquals(3, listValues.size());
assertEquals("High", listValues.get(0));
assertEquals("Normal", listValues.get(1));
assertEquals("Low", listValues.get(2));
// Retrieve all the model's constraints
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(4, constraints.size());
}
// Create authorityName constraint
{
String authorityNameConstraintName = "authorityNameConstraint" + System.currentTimeMillis();
CustomModelConstraint authorityNameConstraint = new CustomModelConstraint();
authorityNameConstraint.setName(authorityNameConstraintName);
authorityNameConstraint.setType("org.alfresco.repo.dictionary.constraint.AuthorityNameConstraint");
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(authorityNameConstraint), 201);
// Retrieve the created authorityName constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", authorityNameConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
compareCustomModelConstraints(authorityNameConstraint, returnedConstraint, "prefixedName");
// Retrieve all the model's constraints
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(5, constraints.size());
}
// Create Invalid constraint
{
String invalidConstraintName = "testInvalidConstraint" + System.currentTimeMillis();
CustomModelConstraint invalidConstraint = new CustomModelConstraint();
invalidConstraint.setName(invalidConstraintName);
invalidConstraint.setType("InvalidConstraintType" + System.currentTimeMillis());
invalidConstraint.setTitle("test Invalid title");
invalidConstraint.setDescription("test Invalid 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
invalidConstraint.setParameters(parameters);
// Try to create an invalid constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(invalidConstraint), 400);
// Retrieve all the model's constraints
HttpResponse response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(5, constraints.size());
}
// Activate the model
CustomModel updatePayload = new CustomModel();
updatePayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
// Retrieve all the model's constraints
HttpResponse response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(5, constraints.size());
// Deactivate the model
updatePayload = new CustomModel();
updatePayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
// Retrieve all the model's constraints
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(5, constraints.size());
}
use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomModel method testModelsCircularDependency.
// SHA-808
@Test
public void testModelsCircularDependency() throws Exception {
setRequestContext(customModelAdmin);
// Model One
String modelNameOne = "testModelOne" + System.currentTimeMillis();
Pair<String, String> namespacePairOne = getTestNamespaceUriPrefixPair();
// Create the modelOne as a Model Administrator
createCustomModel(modelNameOne, namespacePairOne, ModelStatus.DRAFT);
// Add typeA_M1 into modelOne
String typeA_M1 = "testTypeA_M1" + System.currentTimeMillis();
final String typeA_M1_WithPrefix = namespacePairOne.getSecond() + QName.NAMESPACE_PREFIX + typeA_M1;
createTypeAspect(CustomType.class, modelNameOne, typeA_M1, "test typeA_M1 title", null, "cm:content");
// Activate modelOne
CustomModel modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelNameOne, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
// Add another type into modelOne with 'typeA_M1' as its parent
String typeB_M1 = "testTypeB_M1" + System.currentTimeMillis();
final String typeB_M1_WithPrefix = namespacePairOne.getSecond() + QName.NAMESPACE_PREFIX + typeB_M1;
createTypeAspect(CustomType.class, modelNameOne, typeB_M1, "test typeB_M1 title", "test typeB_M1 Desc", typeA_M1_WithPrefix);
// Model Two
String modelNameTwo = "testModelTwo" + System.currentTimeMillis();
Pair<String, String> namespacePairTwo = getTestNamespaceUriPrefixPair();
// Create the modelTwo as a Model Administrator
createCustomModel(modelNameTwo, namespacePairTwo, ModelStatus.DRAFT);
// Add type1_M2 into modelTwo with 'typeB_M1' (from modelOne) as its parent
String type1_M2 = "testType1_M2" + System.currentTimeMillis();
final String type1_M2_WithPrefix = namespacePairTwo.getSecond() + QName.NAMESPACE_PREFIX + type1_M2;
createTypeAspect(CustomType.class, modelNameTwo, type1_M2, "test type1_M2 title", null, typeB_M1_WithPrefix);
// Activate modelTwo
CustomModel modelTwoStatusPayload = new CustomModel();
modelTwoStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelNameTwo, RestApiUtil.toJsonAsString(modelTwoStatusPayload), SELECT_STATUS_QS, 200);
// Test that the API can handle "circular dependency" - (modelOne depends on modelTwo)
{
// Add another type into modelOne with 'type1_M2' (from modelTwo) as its parent
String typeC_M1 = "testTypeC_M1" + System.currentTimeMillis();
CustomType typeC_M1_Payload = new CustomType();
typeC_M1_Payload.setName(typeC_M1);
typeC_M1_Payload.setTitle("test typeC_M1 title");
// => 'type1_M2' (from modelTwo)
typeC_M1_Payload.setParentName(type1_M2_WithPrefix);
// Try to create typeC_M1 which has 'circular dependency'
// Constraint violation
post("cmm/" + modelNameOne + "/types", RestApiUtil.toJsonAsString(typeC_M1_Payload), 409);
}
// Model Three
String modelNameThree = "testModelThree" + System.currentTimeMillis();
Pair<String, String> namespacePairThree = getTestNamespaceUriPrefixPair();
// Create the modelThree as a Model Administrator
createCustomModel(modelNameThree, namespacePairThree, ModelStatus.DRAFT);
// Add type1_M3 into modelThree with 'type1_M2' (from modelTwo) as its parent
String type1_M3 = "testType1_M3" + System.currentTimeMillis();
final String type1_M3_WithPrefix = namespacePairThree.getSecond() + QName.NAMESPACE_PREFIX + type1_M3;
createTypeAspect(CustomType.class, modelNameThree, type1_M3, "test type1_M3 title", null, type1_M2_WithPrefix);
// Activate modelThree
CustomModel modelThreeStatusPayload = new CustomModel();
modelThreeStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelNameThree, RestApiUtil.toJsonAsString(modelThreeStatusPayload), SELECT_STATUS_QS, 200);
// Test that the API can handle "circular dependency" - (modelOne depends on modelThree)
{
// Add another type into modelOne with 'type1_M3' (from modelThree) as its parent
String typeC_M1 = "testTypeC_M1" + System.currentTimeMillis();
CustomType typeC_M1_Payload = new CustomType();
typeC_M1_Payload.setName(typeC_M1);
typeC_M1_Payload.setTitle("test typeC_M1 title");
// => 'type1_M3' (from modelThree)
typeC_M1_Payload.setParentName(type1_M3_WithPrefix);
// Try to create typeC_M1 which has 'circular dependency'
// Constraint violation
post("cmm/" + modelNameOne + "/types", RestApiUtil.toJsonAsString(typeC_M1_Payload), 409);
}
// Model Three
String modelNameFour = "testModelFour" + System.currentTimeMillis();
Pair<String, String> namespacePairFour = getTestNamespaceUriPrefixPair();
// Create the modelFour as a Model Administrator
createCustomModel(modelNameFour, namespacePairFour, ModelStatus.DRAFT);
// Add type1_M4 into modelFour with 'type1_M3' (from modelThree) as its parent
String type1_M4 = "testType1_M4" + System.currentTimeMillis();
final String type1_M4_WithPrefix = namespacePairFour.getSecond() + QName.NAMESPACE_PREFIX + type1_M4;
createTypeAspect(CustomType.class, modelNameFour, type1_M4, "test type1_M4 title", null, type1_M3_WithPrefix);
// Activate modelFour
CustomModel modelFourStatusPayload = new CustomModel();
modelFourStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelNameFour, RestApiUtil.toJsonAsString(modelFourStatusPayload), SELECT_STATUS_QS, 200);
// Test that the API can handle "circular dependency" - (modelOne depends on modelFour)
{
// Add another type into modelOne with 'type1_M4' (from modelFour) as its parent
String typeC_M1 = "testTypeC_M1" + System.currentTimeMillis();
CustomType typeC_M1_Payload = new CustomType();
typeC_M1_Payload.setName(typeC_M1);
typeC_M1_Payload.setTitle("test typeC_M1 title");
// => 'type1_M4' (from modelFour)
typeC_M1_Payload.setParentName(type1_M4_WithPrefix);
// Try to create typeC_M1 which has 'circular dependency'
// Constraint violation
post("cmm/" + modelNameOne + "/types", RestApiUtil.toJsonAsString(typeC_M1_Payload), 409);
}
// Test that the API can handle "circular dependency" - (modelTwo depends on modelFour)
{
// Add another type into modelTwo with 'type1_M4' (from modelFour) as its parent
String type2_M2 = "testType2_M2" + System.currentTimeMillis();
CustomType type2_M2_Payload = new CustomType();
type2_M2_Payload.setName(type2_M2);
type2_M2_Payload.setTitle("test type2_M2 title");
// => 'type1_M4' (from modelFour)
type2_M2_Payload.setParentName(type1_M4_WithPrefix);
// Try to create type2_M2 which has 'circular dependency'
// Constraint violation
post("cmm/" + modelNameTwo + "/types", RestApiUtil.toJsonAsString(type2_M2_Payload), 409);
}
}
use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.
the class TestCustomModel method testCreateBasicModel.
@Test
public void testCreateBasicModel() throws Exception {
String modelName = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
CustomModel customModel = new CustomModel();
customModel.setName(modelName);
customModel.setNamespaceUri(namespacePair.getFirst());
customModel.setNamespacePrefix(namespacePair.getSecond());
customModel.setDescription("Test model description");
customModel.setStatus(CustomModel.ModelStatus.DRAFT);
setRequestContext(nonAdminUserName);
// Try to create the model as a non Admin user
post("cmm", RestApiUtil.toJsonAsString(customModel), 403);
setRequestContext(customModelAdmin);
// Create the model as a Model Administrator
post("cmm", RestApiUtil.toJsonAsString(customModel), 201);
// Retrieve the created model
HttpResponse response = getSingle("cmm", modelName, 200);
CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
// Check the retrieved model is the expected model.
// Note: since we didn't specify the Author when created the Model,
// we have to exclude it from the objects comparison. Because,
// the system will add the current authenticated user as the author
// of the model, if the Author hasn't been set.
compareCustomModels(customModel, returnedModel, "author");
}
Aggregations