Thursday 18 April 2019

cmis: Applying constraints on properties


CMIS specification applies constraints at property level. For examples, a property can have values in given range like 10 to 500, and a property must have value to be set etc.,

CMIS defined two types of constraints on properties.
a.   Generic constraints
b.   Constraints specific to property type

Generic Constraints
Following three are the generic constraints.
Constraint
Description
defaultValue
The value that the repository MUST set for the property if a value is not provided by an application when the object is created. If no default value is specified and an application creates an object of this type without setting a value for the property, the repository MUST attempt to store a "not set" property value.
openChoice
This attribute is only applicable to properties that provide a value for the "Choices" attribute. If FALSE, then the data value for the property MUST only be one of the values specified in the "Choices" attribute. If TRUE, then values other than those included in the "Choices" attribute may be set for the property.
choices
If the cardinatity of the property definition is "single" and the "openChoice" attribute is FALSE, then the property value MUST be at most one of the values listed in this attribute.

If the cardinatity of the property definition is "single" and the "openChoice" attribute is TRUE, then the property value MAY be one of the values listed in this attribute.

If the cardinatity of the property definition is "multi" and the "openChoice" attribute is FALSE, then the property value MUST be zero, one or more than one of the values listed in this attribute.

If the cardinatity of the property definition is "multi" and the "openChoice" attribute is TRUE,then the property value MAY be zero, one, or more than one of the values listed in this attribute.
If this attribute is "not set", then any valid value for this property based on its type may be used.

TestCmis.java
package com.sample.util;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

public class TestCmis {

 private static String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser";
 private static String repositoryId = "A1";

 public static Session getSession() {
  Map<String, String> parameters = new HashMap<>();
  parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());

  parameters.put(SessionParameter.USER, "");
  parameters.put(SessionParameter.PASSWORD, "");

  parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
  parameters.put(SessionParameter.BROWSER_URL, serverURL);

  SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
  return sessionFactory.createSession(parameters);
 }

 public static void printPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {

  for (String key : propertyDefinitions.keySet()) {
   System.out.println("\n\nGeneric Constraints for the property : " + key);
   System.out.println("************************************************");

   PropertyDefinition<?> propertyDefinition = propertyDefinitions.get(key);

   boolean isRequired = propertyDefinition.isRequired();
   List<?> choices = propertyDefinition.getChoices();

   System.out.println("isRequired : " + isRequired);
   System.out.println("isOpenChoice : " + propertyDefinition.isOpenChoice());
   System.out.println("choices : " + choices);
  }
 }

 public static void main(String args[]) throws IOException {
  Session session = getSession();

  Folder folder = session.getRootFolder();
  ObjectType objectType = folder.getType();
  Map<String, PropertyDefinition<?>> propertyDefinitions = objectType.getPropertyDefinitions();

  printPropertyDefinitions(propertyDefinitions);
 }
}


Output
Generic Constraints for the property : cmis:name
************************************************
isRequired : true
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:description
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:objectId
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:baseTypeId
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:objectTypeId
************************************************
isRequired : true
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:secondaryObjectTypeIds
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:createdBy
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:creationDate
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:lastModifiedBy
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:lastModificationDate
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:changeToken
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:parentId
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:path
************************************************
isRequired : false
isOpenChoice : null
choices : []


Generic Constraints for the property : cmis:allowedChildObjectTypeIds
************************************************
isRequired : false
isOpenChoice : null
choices : []

Constraints specific to property type
There are constraints specific to property type.

Constraints specific to Integer object type property defintions
Constraint
Description
minValue
Minimum value allowed for this property. If an application tries to set the value of this property to a value lower than minValue, the repository MUST throw a constraint exception.
maxValue
The maximum value allowed for this property. If an application tries to set the value of this property to a value higher than maxValue, the repository MUST throw a constraint exception.

Constraints specific to DateTime Object-Type Property Definitions
Constraint
Description
resolution
This is enum type. This is the resolution supported for values of this property. Valid values for this attribute are:
Year : Year resolution is persisted. Date and time portion of the value should be ignored.

date : Date resolution is persisted. Time portion of the value should be ignored.

time : Time resolution is persisted.

Constraints specific Decmial Object-Type Property Definitions
Constraint
Description
precision
This is the precision in bits supported for values of this property. Valid values for this attribute
are: 32 (or) 64
minValue
Minimum value allowed for this property. If an application tries to set the value of this property to a value lower than minValue, the repository MUST throw a constraint exception.
maxValue
The maximum value allowed for this property. If an application tries to set the value of this property to a value higher than maxValue, the repository MUST throw a constraint exception.

Constraints specific to String Object-Type Property Definitions
Constraint
Description
maxlength
Maximum length allowed for the value of this property. If an application attempts to set the value of this property to a string longer than the specified maximum length, the repository MUST throw a constraint exception.





Previous                                                 Next                                                 Home

No comments:

Post a Comment