Search in sources :

Example 16 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper 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 17 with TypeDefinitionWrapper

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

the class CMISConnector method getRelationships.

public List<ObjectData> getRelationships(NodeRef nodeRef, IncludeRelationships includeRelationships) /*, CmisVersion cmisVersion*/
{
    List<ObjectData> result = new ArrayList<ObjectData>();
    if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
        // relationships from and to versions are not preserved
        return result;
    }
    // get relationships
    List<AssociationRef> assocs = new ArrayList<AssociationRef>();
    if (includeRelationships == IncludeRelationships.SOURCE || includeRelationships == IncludeRelationships.BOTH) {
        assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }
    if (includeRelationships == IncludeRelationships.TARGET || includeRelationships == IncludeRelationships.BOTH) {
        assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }
    // filter relationships that not map the CMIS domain model
    for (AssociationRef assocRef : assocs) {
        TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName());
        if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null || getType(assocRef.getTargetRef()) == null) {
            continue;
        }
        try {
            result.add(createCMISObject(createNodeInfo(assocRef), null, false, IncludeRelationships.NONE, RENDITION_NONE, false, false));
        } catch (AccessDeniedException e) {
        // PUBLICAPI-110
        // ok, just skip it
        } catch (CmisObjectNotFoundException e) {
        // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
        }// TODO: Somewhere this has not been wrapped correctly
         catch (net.sf.acegisecurity.AccessDeniedException e) {
        // skip
        }
    }
    return result;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 18 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper 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 19 with TypeDefinitionWrapper

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

the class CMISConnector method getObjectRelationships.

public ObjectList getObjectRelationships(NodeRef nodeRef, RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount) {
    ObjectListImpl result = new ObjectListImpl();
    result.setHasMoreItems(false);
    result.setNumItems(BigInteger.ZERO);
    result.setObjects(new ArrayList<ObjectData>());
    if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
        // relationships from and to versions are not preserved
        return result;
    }
    // get relationships
    List<AssociationRef> assocs = new ArrayList<AssociationRef>();
    if (relationshipDirection == RelationshipDirection.SOURCE || relationshipDirection == RelationshipDirection.EITHER) {
        assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }
    if (relationshipDirection == RelationshipDirection.TARGET || relationshipDirection == RelationshipDirection.EITHER) {
        assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }
    int skip = (skipCount == null ? 0 : skipCount.intValue());
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int counter = 0;
    boolean hasMore = false;
    if (max > 0) {
        // filter relationships that not map the CMIS domain model
        for (AssociationRef assocRef : assocs) {
            TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName());
            if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null || getType(assocRef.getTargetRef()) == null) {
                continue;
            }
            if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId)) {
                continue;
            }
            counter++;
            if (skip > 0) {
                skip--;
                continue;
            }
            max--;
            if (max > 0) {
                try {
                    result.getObjects().add(createCMISObject(createNodeInfo(assocRef), filter, includeAllowableActions, IncludeRelationships.NONE, RENDITION_NONE, false, false));
                } catch (CmisObjectNotFoundException e) {
                // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
                }
            } else {
                hasMore = true;
            }
        }
    }
    result.setNumItems(BigInteger.valueOf(counter));
    result.setHasMoreItems(hasMore);
    return result;
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 20 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper 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)

Aggregations

TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)33 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)13 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)13 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)13 NodeRef (org.alfresco.service.cmr.repository.NodeRef)12 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)11 ArrayList (java.util.ArrayList)10 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)9 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)9 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)9 Serializable (java.io.Serializable)8 QName (org.alfresco.service.namespace.QName)8 PropertyDefinitionWrapper (org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper)7 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)4