use of org.apache.chemistry.opencmis.commons.enums.PropertyType in project copper-cms by PogeyanOSS.
the class CreateAndDeleteTypeTest method createTypeWithProperties.
private void createTypeWithProperties(Session session, ObjectType parentType) {
CmisTestResult failure = null;
CreatablePropertyTypes cpt = session.getRepositoryInfo().getCapabilities().getCreatablePropertyTypes();
if (cpt == null || cpt.canCreate() == null || cpt.canCreate().isEmpty()) {
addResult(createResult(FAILURE, "Repository Info does not indicate, which property types can be created!"));
return;
}
// define the type
DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition(session, "tck:testid_with_properties", parentType);
// add a property for each creatable property type
for (PropertyType propType : PropertyType.values()) {
if (!cpt.canCreate().contains(propType)) {
continue;
}
newTypeDef.addPropertyDefinition(createPropertyDefinition(propType));
}
// create the type
ObjectType newType = createType(session, newTypeDef);
if (newType == null) {
return;
}
// get the type
ObjectType newType2 = null;
try {
newType2 = session.getTypeDefinition(newType.getId());
// assert type definitions
failure = createResult(FAILURE, "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!");
addResult(assertEquals(newType, newType2, null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false));
}
// check properties
List<PropertyDefinition<?>> newPropDefs = new ArrayList<PropertyDefinition<?>>();
for (Map.Entry<String, PropertyDefinition<?>> propDef : newType.getPropertyDefinitions().entrySet()) {
if (Boolean.FALSE.equals(propDef.getValue().isInherited())) {
newPropDefs.add(propDef.getValue());
}
}
failure = createResult(FAILURE, "The number of defined properties and the number of non-inherited properties don't match!");
addResult(assertEquals(newTypeDef.getPropertyDefinitions().size(), newPropDefs.size(), null, failure));
// check the order of the properties, which must match the order of the
// original type definition
// (OpenCMIS keeps the order of the property definitions.)
int i = 0;
for (Map.Entry<String, PropertyDefinition<?>> propDef : newTypeDef.getPropertyDefinitions().entrySet()) {
PropertyDefinition<?> newPropDef = newPropDefs.get(i);
failure = createResult(FAILURE, "Property " + (i + 1) + " must be of type " + propDef.getValue().getPropertyType() + " but is of type " + newPropDef.getPropertyType() + "!");
addResult(assertEquals(propDef.getValue().getPropertyType(), newPropDef.getPropertyType(), null, failure));
addResult(createInfoResult("Repository assigned the property '" + propDef.getValue().getId() + "' the following property id: " + newPropDef.getId()));
i++;
}
// delete the type
deleteType(session, newType.getId());
}
use of org.apache.chemistry.opencmis.commons.enums.PropertyType in project structr by structr.
the class CMISObjectWrapper method getProperties.
@Override
public Properties getProperties() {
final FilteredPropertyList properties = new FilteredPropertyList(propertyFilter);
final BindingsObjectFactory objFactory = new BindingsObjectFactoryImpl();
properties.add(objFactory.createPropertyIdData(PropertyIds.BASE_TYPE_ID, baseTypeId.value()));
properties.add(objFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, type));
properties.add(objFactory.createPropertyIdData(PropertyIds.OBJECT_ID, id));
properties.add(objFactory.createPropertyStringData(PropertyIds.NAME, name));
properties.add(objFactory.createPropertyStringData(PropertyIds.DESCRIPTION, description));
properties.add(objFactory.createPropertyStringData(PropertyIds.CREATED_BY, createdBy));
properties.add(objFactory.createPropertyStringData(PropertyIds.LAST_MODIFIED_BY, lastModifiedBy));
properties.add(objFactory.createPropertyDateTimeData(PropertyIds.CREATION_DATE, creationDate));
properties.add(objFactory.createPropertyDateTimeData(PropertyIds.LAST_MODIFICATION_DATE, lastModificationDate));
// add dynamic properties
if (dynamicPropertyMap != null) {
for (final Entry<PropertyKey, Object> entry : dynamicPropertyMap.entrySet()) {
final PropertyKey key = entry.getKey();
final PropertyType dataType = key.getDataType();
if (dataType != null) {
switch(dataType) {
case BOOLEAN:
properties.add(objFactory.createPropertyBooleanData(key.jsonName(), (Boolean) entry.getValue()));
break;
case DATETIME:
properties.add(objFactory.createPropertyDateTimeData(key.jsonName(), valueOrNull((Date) entry.getValue())));
break;
case DECIMAL:
properties.add(objFactory.createPropertyDecimalData(key.jsonName(), valueOrNull((Double) entry.getValue())));
break;
case INTEGER:
// INTEGER includes int and long so we have to cover both cases here
properties.add(objFactory.createPropertyIntegerData(key.jsonName(), intOrNull(entry.getValue())));
break;
case STRING:
properties.add(objFactory.createPropertyStringData(key.jsonName(), (String) entry.getValue()));
break;
}
}
}
}
// initialize type-dependent properties
createProperties(objFactory, properties);
// filter properties according to filter expression
return objFactory.createPropertiesData(properties.getList());
}
use of org.apache.chemistry.opencmis.commons.enums.PropertyType in project structr by structr.
the class CMISRepositoryService method createProperty.
private MutablePropertyDefinition createProperty(final Class type, final PropertyKey key) {
// include all dynamic and CMIS-enabled keys in definition
if (key.isDynamic() || key.isCMISProperty()) {
// only include primitives here
final TypeDefinitionFactory factory = TypeDefinitionFactory.newInstance();
final PropertyType dataType = key.getDataType();
if (dataType != null) {
final String propertyId = key.jsonName();
final String displayName = propertyId;
final String description = StringUtils.capitalize(propertyId);
final Class declaringClass = key.getDeclaringClass();
final boolean isInherited = !type.getSimpleName().equals(declaringClass.getSimpleName());
final Cardinality cardinality = Cardinality.SINGLE;
final Updatability updatability = Updatability.READWRITE;
final boolean required = key.isNotNull();
final boolean queryable = key.isIndexed();
final boolean orderable = key.isIndexed();
final MutablePropertyDefinition property = factory.createPropertyDefinition(propertyId, displayName, description, dataType, cardinality, updatability, isInherited, required, queryable, orderable);
// add enum choices if present
final Class valueType = key.valueType();
if (valueType != null && valueType.isEnum()) {
final List<Choice> choices = new LinkedList<>();
for (final Object option : valueType.getEnumConstants()) {
final String optionName = option.toString();
choices.add(factory.createChoice(optionName, optionName));
}
property.setIsOpenChoice(false);
property.setChoices(choices);
}
return property;
}
}
return null;
}
use of org.apache.chemistry.opencmis.commons.enums.PropertyType in project structr by structr.
the class AbstractNode method getDynamicProperties.
@Override
public PropertyMap getDynamicProperties() {
final PropertyMap propertyMap = new PropertyMap();
final Class type = getClass();
for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(type, PropertyView.All)) {
// include all dynamic keys in definition
if (key.isDynamic() || key.isCMISProperty()) {
// only include primitives here
final PropertyType dataType = key.getDataType();
if (dataType != null) {
propertyMap.put(key, getProperty(key));
}
}
}
return propertyMap;
}
use of org.apache.chemistry.opencmis.commons.enums.PropertyType in project structr by structr.
the class AbstractRelationship method getDynamicProperties.
public PropertyMap getDynamicProperties() {
final PropertyMap propertyMap = new PropertyMap();
final Class type = getClass();
for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(type, PropertyView.All)) {
// include all dynamic keys in definition
if (key.isDynamic() || key.isCMISProperty()) {
// only include primitives here
final PropertyType dataType = key.getDataType();
if (dataType != null) {
propertyMap.put(key, getProperty(key));
}
}
}
return propertyMap;
}
Aggregations