Search in sources :

Example 1 with CustomModel

use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.

the class TestCustomModel method testDeleteCustomModel.

@Test
public void testDeleteCustomModel() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testDeleteModel" + System.currentTimeMillis();
    Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    CustomModel customModel = createCustomModel(modelName, namespacePair, ModelStatus.DRAFT, null, "Joe Bloggs");
    // Retrieve the created model
    HttpResponse response = getSingle("cmm", modelName, 200);
    CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
    compareCustomModels(customModel, returnedModel);
    setRequestContext(nonAdminUserName);
    // Try to delete the model as a non Admin user
    delete("cmm", modelName, 403);
    setRequestContext(customModelAdmin);
    // Delete the model as a Model Administrator
    delete("cmm", modelName, 204);
    // Create the model again
    post("cmm", RestApiUtil.toJsonAsString(customModel), 201);
    // Activated the model
    CustomModel updatePayload = new CustomModel();
    updatePayload.setStatus(ModelStatus.ACTIVE);
    put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
    // Try to delete the active model
    delete("cmm", modelName, 409);
    // Deactivate and then delete the model
    updatePayload = new CustomModel();
    updatePayload.setStatus(ModelStatus.DRAFT);
    put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
    delete("cmm", modelName, 204);
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModel(org.alfresco.rest.api.model.CustomModel) Test(org.junit.Test)

Example 2 with CustomModel

use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.

the class TestCustomModel method testListBasicModels.

@Test
public void testListBasicModels() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName_1 = "testModel1" + System.currentTimeMillis();
    // Create the model as a Model Administrator
    CustomModel customModel_1 = createCustomModel(modelName_1, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT);
    String modelName_2 = "testModel2" + System.currentTimeMillis();
    CustomModel customModel_2 = createCustomModel(modelName_2, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT);
    String modelName_3 = "testModel3" + System.currentTimeMillis();
    CustomModel customModel_3 = createCustomModel(modelName_3, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT);
    Paging paging = getPaging(0, Integer.MAX_VALUE);
    HttpResponse response = getAll("cmm", paging, 200);
    List<CustomModel> models = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModel.class);
    assertTrue(models.size() >= 3);
    assertTrue(models.contains(customModel_1));
    assertTrue(models.contains(customModel_2));
    assertTrue(models.contains(customModel_3));
}
Also used : Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModel(org.alfresco.rest.api.model.CustomModel) Test(org.junit.Test)

Example 3 with CustomModel

use of org.alfresco.rest.api.model.CustomModel 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());
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) CustomAspect(org.alfresco.rest.api.model.CustomAspect) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModel(org.alfresco.rest.api.model.CustomModel) Test(org.junit.Test)

Example 4 with CustomModel

use of org.alfresco.rest.api.model.CustomModel 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);
    }
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) CustomAspect(org.alfresco.rest.api.model.CustomAspect) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) CustomModel(org.alfresco.rest.api.model.CustomModel) CustomModelNamedValue(org.alfresco.rest.api.model.CustomModelNamedValue) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) Test(org.junit.Test)

Example 5 with CustomModel

use of org.alfresco.rest.api.model.CustomModel in project alfresco-remote-api by Alfresco.

the class TestCustomTypeAspect method testUpdateAspectsTypes.

@Test
public void testUpdateAspectsTypes() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testModeEditAspectType" + System.currentTimeMillis();
    final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
    // Test update aspect
    {
        // Create aspect
        String aspectName = "testAspect" + System.currentTimeMillis();
        createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
        // Update the aspect
        CustomAspect aspectPayload = new CustomAspect();
        aspectPayload.setDescription(null);
        aspectPayload.setTitle("title modified");
        aspectPayload.setParentName("cm:titled");
        setRequestContext(nonAdminUserName);
        // Try to update the aspect as a non Admin user
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 403);
        setRequestContext(customModelAdmin);
        // Modify the name
        aspectPayload.setName(aspectName + "Modified");
        // Try to update the aspect as a Model Administrator
        // Note: aspect/type name cannot be modified
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 404);
        aspectPayload.setName(aspectName);
        // Update the aspect as a Model Administrator
        HttpResponse response = put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200);
        CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
        compareCustomTypesAspects(aspectPayload, returnedAspect, "prefixedName");
        // Update the aspect with an invalid parent
        aspectPayload.setParentName("cm:titled" + System.currentTimeMillis());
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409);
        // Activate the model
        CustomModel statusPayload = new CustomModel();
        statusPayload.setStatus(ModelStatus.ACTIVE);
        put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
        // Remove the aspect's parent
        // Note: cannot update the parent of an ACTIVE type/aspect.
        aspectPayload.setParentName(null);
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409);
        statusPayload = new CustomModel();
        statusPayload.setStatus(ModelStatus.DRAFT);
        put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
        // now update the aspect's parent - model is inactive
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200);
    }
    // Test update type
    {
        // Create type
        String typeName = "testType" + System.currentTimeMillis();
        createTypeAspect(CustomType.class, modelName, typeName, "title", "desc", "cm:content");
        // Add property
        CustomType addPropertyPayload = new CustomType();
        addPropertyPayload.setName(typeName);
        String typePropName = "testTypeProp1" + System.currentTimeMillis();
        CustomModelProperty typeProp = new CustomModelProperty();
        typeProp.setName(typePropName);
        typeProp.setTitle("property title");
        typeProp.setDataType("d:text");
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(typeProp);
        addPropertyPayload.setProperties(props);
        // Create the property
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(addPropertyPayload), SELECT_PROPS_QS, 200);
        // Update the type
        CustomType typePayload = new CustomType();
        typePayload.setDescription("desc modified");
        typePayload.setTitle("title modified");
        setRequestContext(nonAdminUserName);
        // Try to update the type as a non Admin user
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 403);
        setRequestContext(customModelAdmin);
        // Modify the name
        typePayload.setName(typeName + "Modified");
        // Try to update the type as a Model Administrator
        // Note: type/type name cannot be modified
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 404);
        typePayload.setName(typeName);
        // Update the type as a Model Administrator
        HttpResponse response = put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 200);
        CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
        assertEquals(typePayload.getDescription(), returnedType.getDescription());
        assertEquals(typePayload.getTitle(), returnedType.getTitle());
        // Check that properties are unmodified
        assertNotNull(returnedType.getProperties());
        assertEquals(1, returnedType.getProperties().size());
        assertEquals(typePropName, returnedType.getProperties().iterator().next().getName());
        // Update the type with an invalid parent
        typePayload.setParentName("cm:folder" + System.currentTimeMillis());
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 409);
        // Activate the model
        CustomModel statusPayload = new CustomModel();
        statusPayload.setStatus(ModelStatus.ACTIVE);
        put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
        // Remove the type's parent
        // Note: cannot update the parent of an ACTIVE type/type.
        typePayload.setParentName("cm:folder");
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 409);
        statusPayload = new CustomModel();
        statusPayload.setStatus(ModelStatus.DRAFT);
        put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
        // now update the type's parent - model is inactive
        response = put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 200);
        returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
        assertEquals(typePayload.getParentName(), returnedType.getParentName());
    }
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) CustomAspect(org.alfresco.rest.api.model.CustomAspect) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) ArrayList(java.util.ArrayList) List(java.util.List) CustomModel(org.alfresco.rest.api.model.CustomModel) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) Test(org.junit.Test)

Aggregations

CustomModel (org.alfresco.rest.api.model.CustomModel)23 Test (org.junit.Test)17 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)16 CustomAspect (org.alfresco.rest.api.model.CustomAspect)9 CustomType (org.alfresco.rest.api.model.CustomType)9 ArrayList (java.util.ArrayList)8 CustomModelProperty (org.alfresco.rest.api.model.CustomModelProperty)6 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)5 List (java.util.List)4 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)4 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)4 CustomModelNamedValue (org.alfresco.rest.api.model.CustomModelNamedValue)3 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)3 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)3 M2Model (org.alfresco.repo.dictionary.M2Model)2 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2