Search in sources :

Example 6 with PropertyDefinitionWrapper

use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.

the class OpenCmisQueryTest method testBasicDefaultMetaData.

public void testBasicDefaultMetaData() {
    CMISQueryOptions options = new CMISQueryOptions("SELECT * FROM cmis:document", rootNodeRef.getStoreRef());
    CMISResultSet rs = cmisQueryService.query(options);
    CMISResultSetMetaData md = rs.getMetaData();
    assertNotNull(md.getQueryOptions());
    TypeDefinitionWrapper typeDef = cmisDictionaryService.findType(BaseTypeId.CMIS_DOCUMENT.value());
    int count = 0;
    for (PropertyDefinitionWrapper pdef : typeDef.getProperties()) {
        count++;
    }
    assertEquals(count, md.getColumnNames().length);
    assertNotNull(md.getColumn(PropertyIds.OBJECT_ID));
    assertEquals(1, md.getSelectors().length);
    assertNotNull(md.getSelector(""));
    rs.close();
}
Also used : PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)

Example 7 with PropertyDefinitionWrapper

use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.

the class CMISConnector method checkChildObjectType.

/**
 * Checks if a child of a given type can be added to a given folder.
 */
@SuppressWarnings("unchecked")
public void checkChildObjectType(CMISNodeInfo folderInfo, String childType) {
    TypeDefinitionWrapper targetType = folderInfo.getType();
    PropertyDefinitionWrapper allowableChildObjectTypeProperty = targetType.getPropertyById(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
    List<String> childTypes = (List<String>) allowableChildObjectTypeProperty.getPropertyAccessor().getValue(folderInfo);
    if ((childTypes == null) || childTypes.isEmpty()) {
        return;
    }
    if (!childTypes.contains(childType)) {
        throw new CmisConstraintException("Objects of type '" + childType + "' cannot be added to this folder!");
    }
}
Also used : PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) 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)

Example 8 with PropertyDefinitionWrapper

use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.

the class CMISConnector method getAssocProperties.

public Properties getAssocProperties(CMISNodeInfo info, String filter) {
    PropertiesImpl result = new PropertiesImpl();
    Set<String> filterSet = splitFilter(filter);
    for (PropertyDefinitionWrapper propDefWrap : info.getType().getProperties()) {
        PropertyDefinition<?> propDef = propDefWrap.getPropertyDefinition();
        if ((filterSet != null) && (!filterSet.contains(propDef.getQueryName()))) {
            // skip properties that are not in the filter
            continue;
        }
        CMISPropertyAccessor cmisPropertyAccessor = propDefWrap.getPropertyAccessor();
        Serializable value = cmisPropertyAccessor.getValue(info);
        PropertyType propType = propDef.getPropertyType();
        PropertyData<?> propertyData = getProperty(propType, propDefWrap, value);
        result.addProperty(propertyData);
    }
    return result;
}
Also used : Serializable(java.io.Serializable) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) CMISPropertyAccessor(org.alfresco.opencmis.dictionary.CMISPropertyAccessor) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType)

Example 9 with PropertyDefinitionWrapper

use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.

the class CMISConnector method setProperties.

/**
 * Sets property values.
 */
@SuppressWarnings({ "rawtypes" })
public void setProperties(NodeRef nodeRef, TypeDefinitionWrapper type, Properties properties, String... exclude) {
    if (properties == null) {
        return;
    }
    Map<String, PropertyData<?>> incomingPropsMap = properties.getProperties();
    if (incomingPropsMap == null) {
        return;
    }
    // extract property data into an easier to use form
    Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsMap = new HashMap<String, Pair<TypeDefinitionWrapper, Serializable>>();
    for (String propertyId : incomingPropsMap.keySet()) {
        PropertyData<?> property = incomingPropsMap.get(propertyId);
        PropertyDefinitionWrapper propDef = type.getPropertyById(property.getId());
        if (propDef == null) {
            propDef = getOpenCMISDictionaryService().findProperty(propertyId);
            if (propDef == null) {
                throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
            }
        }
        Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
        Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
        if (!isUpdatable(updatability, isOnWorkingCopy)) {
            throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
        }
        TypeDefinitionWrapper propType = propDef.getOwningType();
        Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
        Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
        propsMap.put(propertyId, pair);
    }
    // Need to do deal with secondary types first
    Pair<TypeDefinitionWrapper, Serializable> pair = propsMap.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    Serializable secondaryTypesProperty = (pair != null ? pair.getSecond() : null);
    if (secondaryTypesProperty != null) {
        if (!(secondaryTypesProperty instanceof List)) {
            throw new CmisInvalidArgumentException("Secondary types must be a list!");
        }
        List secondaryTypes = (List) secondaryTypesProperty;
        if (secondaryTypes != null && secondaryTypes.size() > 0) {
            // add/remove secondary types/aspects
            processSecondaryTypes(nodeRef, secondaryTypes, propsMap);
        }
    }
    for (String propertyId : propsMap.keySet()) {
        if (propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
            // already handled above
            continue;
        }
        pair = propsMap.get(propertyId);
        TypeDefinitionWrapper propType = pair.getFirst();
        Serializable value = pair.getSecond();
        if (Arrays.binarySearch(exclude, propertyId) < 0) {
            setProperty(nodeRef, propType, propertyId, value);
        }
    }
    List<CmisExtensionElement> extensions = properties.getExtensions();
    if (extensions != null) {
        boolean isNameChanging = properties.getProperties().containsKey(PropertyIds.NAME);
        for (CmisExtensionElement extension : extensions) {
            if (ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace()) && SET_ASPECTS.equals(extension.getName())) {
                setAspectProperties(nodeRef, isNameChanging, extension);
                break;
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) AbstractPropertyData(org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyData) HashMap(java.util.HashMap) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) Updatability(org.apache.chemistry.opencmis.commons.enums.Updatability) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair)

Example 10 with PropertyDefinitionWrapper

use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.

the class CMISConnector method getAspectExtensions.

/**
 * Builds aspect extension.
 */
public List<CmisExtensionElement> getAspectExtensions(CMISNodeInfo info, String filter, Set<String> alreadySetProperties) {
    List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
    Set<String> propertyIds = new HashSet<String>(alreadySetProperties);
    List<CmisExtensionElement> propertyExtensionList = new ArrayList<CmisExtensionElement>();
    Set<String> filterSet = splitFilter(filter);
    Set<QName> aspects = info.getNodeAspects();
    for (QName aspect : aspects) {
        TypeDefinitionWrapper aspectType = getOpenCMISDictionaryService().findNodeType(aspect);
        if (aspectType == null) {
            continue;
        }
        AspectDefinition aspectDefinition = dictionaryService.getAspect(aspect);
        Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> aspectProperties = aspectDefinition.getProperties();
        extensions.add(new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, APPLIED_ASPECTS, null, aspectType.getTypeId()));
        for (PropertyDefinitionWrapper propDef : aspectType.getProperties()) {
            boolean addPropertyToExtensionList = getRequestCmisVersion().equals(CmisVersion.CMIS_1_1) && aspectProperties.keySet().contains(propDef.getAlfrescoName());
            // MNT-11876 : add property to extension even if it has been returned (CMIS 1.1)
            if (propertyIds.contains(propDef.getPropertyId()) && !addPropertyToExtensionList) {
                // skip properties that have already been added
                continue;
            }
            if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName()))) {
                // skip properties that are not in the filter
                continue;
            }
            Serializable value = propDef.getPropertyAccessor().getValue(info);
            propertyExtensionList.add(createAspectPropertyExtension(propDef.getPropertyDefinition(), value));
            // mark property as 'added'
            propertyIds.add(propDef.getPropertyId());
        }
    }
    if (!propertyExtensionList.isEmpty()) {
        CmisExtensionElementImpl propertiesExtension = new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, "properties", null, propertyExtensionList);
        extensions.addAll(Collections.singletonList(propertiesExtension));
    }
    return extensions;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ArrayList(java.util.ArrayList) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) HashSet(java.util.HashSet)

Aggregations

PropertyDefinitionWrapper (org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper)12 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)8 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)7 Serializable (java.io.Serializable)6 ArrayList (java.util.ArrayList)6 QName (org.alfresco.service.namespace.QName)6 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)5 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)5 List (java.util.List)4 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)4 Collections.singletonList (java.util.Collections.singletonList)3 CmisExtensionElement (org.apache.chemistry.opencmis.commons.data.CmisExtensionElement)3 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)3 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)2 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)2 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)2