Search in sources :

Example 6 with CustomModelNamedValue

use of org.alfresco.rest.api.model.CustomModelNamedValue 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 7 with CustomModelNamedValue

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

the class BaseCustomModelApiTest method buildNamedValue.

protected CustomModelNamedValue buildNamedValue(String name, String simpleValue, String... listValue) {
    CustomModelNamedValue namedValue = new CustomModelNamedValue();
    namedValue.setName(name);
    namedValue.setSimpleValue(simpleValue);
    if (listValue.length > 0) {
        namedValue.setListValue(Arrays.asList(listValue));
    }
    return namedValue;
}
Also used : CustomModelNamedValue(org.alfresco.rest.api.model.CustomModelNamedValue)

Aggregations

CustomModelNamedValue (org.alfresco.rest.api.model.CustomModelNamedValue)7 ArrayList (java.util.ArrayList)5 CustomAspect (org.alfresco.rest.api.model.CustomAspect)5 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)5 CustomModelProperty (org.alfresco.rest.api.model.CustomModelProperty)5 Test (org.junit.Test)5 CustomModel (org.alfresco.rest.api.model.CustomModel)3 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)3 CustomType (org.alfresco.rest.api.model.CustomType)2 List (java.util.List)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)1 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)1 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 ConstraintException (org.alfresco.service.cmr.dictionary.ConstraintException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1