Search in sources :

Example 1 with MutablePropertyDefinition

use of org.apache.chemistry.opencmis.commons.definitions.MutablePropertyDefinition 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 2 with MutablePropertyDefinition

use of org.apache.chemistry.opencmis.commons.definitions.MutablePropertyDefinition in project structr by structr.

the class CMISRepositoryService method extendTypeDefinition.

private MutableTypeDefinition extendTypeDefinition(final Class<? extends GraphObject> type, final Boolean includePropertyDefinitions) {
    final String typeName = type.getSimpleName();
    MutableTypeDefinition result = null;
    try {
        // instantiate class to obtain runtime CMIS information
        final GraphObject obj = type.newInstance();
        if (obj != null) {
            final CMISInfo info = obj.getCMISInfo();
            if (info != null) {
                final BaseTypeId baseTypeId = info.getBaseTypeId();
                if (baseTypeId != null) {
                    switch(baseTypeId) {
                        case CMIS_DOCUMENT:
                            result = getDocumentTypeDefinition(typeName, includePropertyDefinitions, false);
                            break;
                        case CMIS_FOLDER:
                            result = getFolderTypeDefinition(typeName, includePropertyDefinitions, false);
                            break;
                        case CMIS_ITEM:
                            result = getItemTypeDefinition(typeName, includePropertyDefinitions, false);
                            break;
                        case CMIS_POLICY:
                            result = getPolicyTypeDefinition(typeName, includePropertyDefinitions, false);
                            break;
                        case CMIS_RELATIONSHIP:
                            result = getRelationshipTypeDefinition(typeName, includePropertyDefinitions, false);
                            break;
                        case CMIS_SECONDARY:
                            result = getSecondaryTypeDefinition(typeName, includePropertyDefinitions, false);
                            break;
                    }
                    if (result != null) {
                        // initialize..
                        for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(type, PropertyView.All)) {
                            final MutablePropertyDefinition property = createProperty(type, key);
                            if (property != null) {
                                result.addPropertyDefinition(property);
                            }
                        }
                    }
                }
            }
        }
    } catch (final IllegalAccessException | InstantiationException iex) {
        logger.warn("", iex);
    }
    return result;
}
Also used : MutableTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition) CMISInfo(org.structr.cmis.CMISInfo) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) MutablePropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.MutablePropertyDefinition) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

MutablePropertyDefinition (org.apache.chemistry.opencmis.commons.definitions.MutablePropertyDefinition)2 GraphObject (org.structr.core.GraphObject)2 LinkedList (java.util.LinkedList)1 Choice (org.apache.chemistry.opencmis.commons.definitions.Choice)1 MutableTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition)1 BaseTypeId (org.apache.chemistry.opencmis.commons.enums.BaseTypeId)1 Cardinality (org.apache.chemistry.opencmis.commons.enums.Cardinality)1 PropertyType (org.apache.chemistry.opencmis.commons.enums.PropertyType)1 Updatability (org.apache.chemistry.opencmis.commons.enums.Updatability)1 TypeDefinitionFactory (org.apache.chemistry.opencmis.server.support.TypeDefinitionFactory)1 CMISInfo (org.structr.cmis.CMISInfo)1 PropertyKey (org.structr.core.property.PropertyKey)1