Search in sources :

Example 1 with PropertyType

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());
}
Also used : CreatablePropertyTypes(org.apache.chemistry.opencmis.commons.data.CreatablePropertyTypes) ArrayList(java.util.ArrayList) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) DocumentTypeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) AbstractPropertyDefinition(org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Map(java.util.Map)

Example 2 with PropertyType

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());
}
Also used : BindingsObjectFactoryImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.BindingsObjectFactoryImpl) BindingsObjectFactory(org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory) GraphObject(org.structr.core.GraphObject) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyKey(org.structr.core.property.PropertyKey)

Example 3 with PropertyType

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;
}
Also used : Choice(org.apache.chemistry.opencmis.commons.definitions.Choice) Cardinality(org.apache.chemistry.opencmis.commons.enums.Cardinality) MutablePropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.MutablePropertyDefinition) GraphObject(org.structr.core.GraphObject) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) Updatability(org.apache.chemistry.opencmis.commons.enums.Updatability) LinkedList(java.util.LinkedList) TypeDefinitionFactory(org.apache.chemistry.opencmis.server.support.TypeDefinitionFactory)

Example 4 with PropertyType

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyKey(org.structr.core.property.PropertyKey)

Example 5 with PropertyType

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

PropertyType (org.apache.chemistry.opencmis.commons.enums.PropertyType)11 ArrayList (java.util.ArrayList)4 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)4 CreatablePropertyTypesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.CreatablePropertyTypesImpl)3 PropertyKey (org.structr.core.property.PropertyKey)3 BigInteger (java.math.BigInteger)2 SimpleDateFormat (java.text.SimpleDateFormat)2 GregorianCalendar (java.util.GregorianCalendar)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 PermissionMapping (org.apache.chemistry.opencmis.commons.data.PermissionMapping)2 PropertyBoolean (org.apache.chemistry.opencmis.commons.data.PropertyBoolean)2 PermissionDefinition (org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition)2 BaseTypeId (org.apache.chemistry.opencmis.commons.enums.BaseTypeId)2 AclCapabilitiesDataImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.AclCapabilitiesDataImpl)2 NewTypeSettableAttributesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.NewTypeSettableAttributesImpl)2 PropertyBooleanDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl)2 PropertyDateTimeDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl)2 RepositoryCapabilitiesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesImpl)2 RepositoryInfoImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoImpl)2