Search in sources :

Example 11 with CustomModelProperty

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

the class TestCustomConstraint method testCreateListConstraintInvalid.

@Test
public void testCreateListConstraintInvalid() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testModelConstraintInvalid" + 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:int");
    // Create LIST constraint
    String inlineListConstraintName = "testListConstraint" + System.currentTimeMillis();
    CustomModelConstraint inlineListConstraint = new CustomModelConstraint();
    inlineListConstraint.setName(inlineListConstraintName);
    inlineListConstraint.setType("LIST");
    inlineListConstraint.setTitle("test List title");
    inlineListConstraint.setDescription("test List desc");
    // Create the List constraint's parameters
    List<CustomModelNamedValue> parameters = new ArrayList<>(3);
    // text list value, but the the property data type is d:int
    parameters.add(buildNamedValue("allowedValues", null, "a", "b", "c"));
    parameters.add(buildNamedValue("sorted", "false"));
    // Add the parameters into the constraint
    inlineListConstraint.setParameters(parameters);
    // Add inline constraint
    aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
    List<CustomModelProperty> props = new ArrayList<>(1);
    props.add(aspectProp);
    aspectPayload.setProperties(props);
    // Try to create the property - Invalid LIST values
    put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
    // Test d:double LIST values with d:int property data type
    parameters = new ArrayList<>(3);
    // double list value, but the the property data type is d:int
    parameters.add(buildNamedValue("allowedValues", null, "1.0", "2.0", "3.0"));
    parameters.add(buildNamedValue("sorted", "false"));
    // Add the parameters into the constraint
    inlineListConstraint.setParameters(parameters);
    // Add inline constraint
    aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
    props = new ArrayList<>(1);
    props.add(aspectProp);
    aspectPayload.setProperties(props);
    // Try to create the property - Invalid LIST values
    put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
}
Also used : CustomModelNamedValue(org.alfresco.rest.api.model.CustomModelNamedValue) CustomAspect(org.alfresco.rest.api.model.CustomAspect) ArrayList(java.util.ArrayList) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) Test(org.junit.Test)

Example 12 with CustomModelProperty

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

the class TestCustomConstraint method testPropDefaultValueWithConstraintRef.

@Test
public void testPropDefaultValueWithConstraintRef() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testModelConstraintRef" + System.currentTimeMillis();
    final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
    {
        // Create List constraint
        String listConstraintName = "testListConstraint" + System.currentTimeMillis();
        CustomModelConstraint listConstraint = new CustomModelConstraint();
        listConstraint.setName(listConstraintName);
        listConstraint.setType("LIST");
        // Create the List constraint's parameters
        List<CustomModelNamedValue> parameters = new ArrayList<>(3);
        // list value
        parameters.add(buildNamedValue("allowedValues", null, "London", "Paris", "New York"));
        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);
        // 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 with LIST constraint ref");
        aspectProp.setDataType("d:text");
        // Not in the list
        aspectProp.setDefaultValue("Berlin");
        // constrain ref
        aspectProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(aspectProp);
        aspectPayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409);
    }
    {
        // Create MINMAX constraint
        String minMaxConstraintName = "testMinMaxConstraint" + System.currentTimeMillis();
        CustomModelConstraint minMaxConstraint = new CustomModelConstraint();
        minMaxConstraint.setName(minMaxConstraintName);
        minMaxConstraint.setType("MINMAX");
        // Create the MinMax constraint's parameters
        List<CustomModelNamedValue> parameters = new ArrayList<>(2);
        parameters.add(buildNamedValue("maxValue", "100"));
        parameters.add(buildNamedValue("minValue", "50"));
        // 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);
        // Create type
        String typeName = "testType1" + System.currentTimeMillis();
        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 with MINMAX constraint ref");
        typeProp.setDataType("d:int");
        // Not in the defined range [50,100]
        typeProp.setDefaultValue("35");
        // constrain ref
        typeProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(typeProp);
        typePayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409);
    }
}
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) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) Test(org.junit.Test)

Example 13 with CustomModelProperty

use of org.alfresco.rest.api.model.CustomModelProperty 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());
}
Also used : QName(org.alfresco.service.namespace.QName) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) NodeService(org.alfresco.service.cmr.repository.NodeService) ArrayList(java.util.ArrayList) CustomAspect(org.alfresco.rest.api.model.CustomAspect) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) CustomModel(org.alfresco.rest.api.model.CustomModel) ConstraintException(org.alfresco.service.cmr.dictionary.ConstraintException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CustomModelNamedValue(org.alfresco.rest.api.model.CustomModelNamedValue) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) Test(org.junit.Test)

Example 14 with CustomModelProperty

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

the class TestCustomConstraint method testPropDefaultValueWithInlineConstraint.

@Test
public void testPropDefaultValueWithInlineConstraint() 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);
    {
        // Create RegEx constraint
        String regExConstraintName = "testInlineFileNameRegEx" + System.currentTimeMillis();
        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 with REGEX constraint");
        aspectProp.setDataType("d:text");
        // invalid value
        aspectProp.setDefaultValue("invalid<defaultValue");
        // Add inline constraint
        aspectProp.setConstraints(Arrays.asList(inlineRegExConstraint));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(aspectProp);
        aspectPayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409);
    }
    {
        // Create inline anonymous LENGTH constraint
        CustomModelConstraint inlineAnonymousLengthConstraint = new CustomModelConstraint();
        inlineAnonymousLengthConstraint.setType("LENGTH");
        // Create the Length constraint's parameters
        List<CustomModelNamedValue> parameters = new ArrayList<>(2);
        parameters.add(buildNamedValue("maxLength", "4"));
        parameters.add(buildNamedValue("minLength", "0"));
        // Add the parameters into the constraint
        inlineAnonymousLengthConstraint.setParameters(parameters);
        // Create type
        String typeName = "testType1" + System.currentTimeMillis();
        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 with LENGTH constraint");
        typeProp.setDataType("d:text");
        // Invalid length
        typeProp.setDefaultValue("abcdef");
        // inline constraint
        typeProp.setConstraints(Arrays.asList(inlineAnonymousLengthConstraint));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(typeProp);
        typePayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409);
    }
    {
        // Create inline anonymous MINMAX constraint
        CustomModelConstraint inlineAnonymousMinMaxConstraint = new CustomModelConstraint();
        inlineAnonymousMinMaxConstraint.setType("MINMAX");
        // Create the MinMax constraint's parameters
        List<CustomModelNamedValue> parameters = new ArrayList<>(2);
        parameters.add(buildNamedValue("maxValue", "10"));
        parameters.add(buildNamedValue("minValue", "0"));
        // Add the parameters into the constraint
        inlineAnonymousMinMaxConstraint.setParameters(parameters);
        // Create type
        String typeName = "testType1" + System.currentTimeMillis();
        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 with MINMAX constraint");
        typeProp.setDataType("d:int");
        // Not in the defined range [0,10]
        typeProp.setDefaultValue("20");
        // inline constraint
        typeProp.setConstraints(Arrays.asList(inlineAnonymousMinMaxConstraint));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(typeProp);
        typePayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 409);
    }
    {
        // Create LIST constraint
        String listConstraintName = "testListConstraint" + System.currentTimeMillis();
        CustomModelConstraint inlineListConstraint = new CustomModelConstraint();
        inlineListConstraint.setName(listConstraintName);
        inlineListConstraint.setType("LIST");
        // Create the List constraint's parameters
        List<CustomModelNamedValue> parameters = new ArrayList<>(3);
        parameters.add(buildNamedValue("allowedValues", null, "one", "two", "three"));
        parameters.add(buildNamedValue("sorted", "false"));
        // Add the parameters into the constraint
        inlineListConstraint.setParameters(parameters);
        // 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 with LIST constraint");
        aspectProp.setDataType("d:text");
        // Not in the list
        aspectProp.setDefaultValue("four");
        // Add inline constraint
        aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(aspectProp);
        aspectPayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409);
    }
    {
        // Create Java Class constraint
        String inlineJavaClassConstraintName = "testJavaClassConstraint" + System.currentTimeMillis();
        CustomModelConstraint inlineListConstraint = new CustomModelConstraint();
        inlineListConstraint.setName(inlineJavaClassConstraintName);
        inlineListConstraint.setType("org.alfresco.rest.api.tests.TestCustomConstraint$DummyJavaClassConstraint");
        // 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 with Java Class constraint");
        aspectProp.setDataType("d:text");
        // Invalid default value
        aspectProp.setDefaultValue("invalid#value");
        // Add inline constraint
        aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
        List<CustomModelProperty> props = new ArrayList<>(1);
        props.add(aspectProp);
        aspectPayload.setProperties(props);
        // Try to create the property - constraint violation
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 409);
    }
}
Also used : CustomType(org.alfresco.rest.api.model.CustomType) CustomAspect(org.alfresco.rest.api.model.CustomAspect) ArrayList(java.util.ArrayList) List(java.util.List) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) Test(org.junit.Test)

Example 15 with CustomModelProperty

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

the class TestCustomProperty method testValidatePropertyDefaultValue.

@Test
public void testValidatePropertyDefaultValue() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testModelPropDefaultValue" + 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 a property
         */
    String aspectName = "testAspect1" + System.currentTimeMillis();
    createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
    // Update the Aspect by adding property
    CustomAspect aspectPayload = new CustomAspect();
    aspectPayload.setName(aspectName);
    String aspectPropName = "testAspectProp" + System.currentTimeMillis();
    final String updatePropAspectQS = getPropDeleteUpdateQS(aspectPropName, false);
    CustomModelProperty aspectProp = new CustomModelProperty();
    aspectProp.setName(aspectPropName);
    aspectProp.setTitle("aspect property title");
    List<CustomModelProperty> props = new ArrayList<>(1);
    props.add(aspectProp);
    aspectPayload.setProperties(props);
    // d:int tests
    {
        aspectProp.setDataType("d:int");
        // space
        aspectProp.setDefaultValue(" ");
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
        // text
        aspectProp.setDefaultValue("abc");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
        // double
        aspectProp.setDefaultValue("1.0");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
        // text
        aspectProp.setDefaultValue("1,2,3");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
    }
    // d:float tests
    {
        aspectProp.setDataType("d:float");
        // space
        aspectProp.setDefaultValue(" ");
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
        // text
        aspectProp.setDefaultValue("abc");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
        // text
        aspectProp.setDefaultValue("1,2,3");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
        // float
        aspectProp.setDefaultValue("1.0");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200);
        // float - update
        aspectProp.setDefaultValue("1.0f");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200);
        // double - update
        aspectProp.setDefaultValue("1.0d");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200);
    }
    // d:boolean tests
    {
        aspectProp.setDataType("d:boolean");
        // space
        aspectProp.setDefaultValue(" ");
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400);
        // text
        aspectProp.setDefaultValue("abc");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400);
        // number
        aspectProp.setDefaultValue("1");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 400);
        // valid value
        aspectProp.setDefaultValue("true");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200);
        // valid value
        aspectProp.setDefaultValue("false");
        // create property
        put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), updatePropAspectQS, 200);
    }
}
Also used : CustomAspect(org.alfresco.rest.api.model.CustomAspect) ArrayList(java.util.ArrayList) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) Test(org.junit.Test)

Aggregations

CustomModelProperty (org.alfresco.rest.api.model.CustomModelProperty)18 ArrayList (java.util.ArrayList)15 CustomAspect (org.alfresco.rest.api.model.CustomAspect)14 Test (org.junit.Test)13 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)10 CustomType (org.alfresco.rest.api.model.CustomType)9 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)9 List (java.util.List)7 CustomModel (org.alfresco.rest.api.model.CustomModel)6 CustomModelNamedValue (org.alfresco.rest.api.model.CustomModelNamedValue)5 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)2 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)1 M2Property (org.alfresco.repo.dictionary.M2Property)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 AbstractClassModel (org.alfresco.rest.api.model.AbstractClassModel)1 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1