Search in sources :

Example 11 with CmisExtensionElement

use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-repository by Alfresco.

the class CMISConnector method createAspectPropertyExtension.

/**
 * Creates a property extension element.
 */
@SuppressWarnings("rawtypes")
private CmisExtensionElement createAspectPropertyExtension(PropertyDefinition<?> propertyDefinition, Object value) {
    String name;
    switch(propertyDefinition.getPropertyType()) {
        case BOOLEAN:
            name = "propertyBoolean";
            break;
        case DATETIME:
            name = "propertyDateTime";
            break;
        case DECIMAL:
            name = "propertyDecimal";
            break;
        case INTEGER:
            name = "propertyInteger";
            break;
        case ID:
            name = "propertyId";
            break;
        default:
            name = "propertyString";
    }
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("propertyDefinitionId", propertyDefinition.getId());
    attributes.put("queryName", propertyDefinition.getQueryName());
    // optional value
    if (propertyDefinition.getDisplayName() != null && propertyDefinition.getDisplayName().trim().length() > 0) {
        attributes.put("displayName", propertyDefinition.getDisplayName());
    }
    // optional value
    if (propertyDefinition.getLocalName() != null && propertyDefinition.getLocalName().trim().length() > 0) {
        attributes.put("localName", propertyDefinition.getLocalName());
    }
    List<CmisExtensionElement> propertyValues = new ArrayList<CmisExtensionElement>();
    if (value != null) {
        if (value instanceof List) {
            for (Object o : ((List) value)) {
                if (o != null) {
                    propertyValues.add(new CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null, convertAspectPropertyValue(o)));
                } else {
                    logger.warn("Unexpected null entry in list value for property " + propertyDefinition.getDisplayName() + ", value = " + value);
                }
            }
        } else {
            propertyValues.add(new CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null, convertAspectPropertyValue(value)));
        }
    }
    return new CmisExtensionElementImpl(CMIS_NAMESPACE, name, attributes, propertyValues);
}
Also used : CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl)

Aggregations

CmisExtensionElement (org.apache.chemistry.opencmis.commons.data.CmisExtensionElement)11 ArrayList (java.util.ArrayList)10 List (java.util.List)8 HashMap (java.util.HashMap)7 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)7 Serializable (java.io.Serializable)6 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)5 QName (org.alfresco.service.namespace.QName)5 CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)5 Test (org.junit.Test)5 Collections.singletonList (java.util.Collections.singletonList)4 Map (java.util.Map)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)4 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)4 CmisExtensionElementImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl)4 HashSet (java.util.HashSet)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)3