Search in sources :

Example 26 with TypeDefinitionWrapper

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

the class CMISConnector method query.

@SuppressWarnings("unchecked")
public ObjectList query(String statement, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount) /*, CmisVersion cmisVersion*/
{
    // prepare results
    ObjectListImpl result = new ObjectListImpl();
    result.setObjects(new ArrayList<ObjectData>());
    // prepare query
    CMISQueryOptions options = new CMISQueryOptions(statement, getRootStoreRef());
    CmisVersion cmisVersion = getRequestCmisVersion();
    options.setCmisVersion(cmisVersion);
    options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
    int skip = 0;
    if ((skipCount != null) && (skipCount.intValue() >= 0)) {
        skip = skipCount.intValue();
        options.setSkipCount(skip);
    }
    if ((maxItems != null) && (maxItems.intValue() >= 0)) {
        options.setMaxItems(maxItems.intValue());
    }
    boolean fetchObject = includeAllowableActions || (includeRelationships != IncludeRelationships.NONE) || (!RENDITION_NONE.equals(renditionFilter));
    // query
    CMISResultSet rs = getOpenCMISQueryService().query(options);
    try {
        CMISResultSetColumn[] columns = rs.getMetaData().getColumns();
        for (CMISResultSetRow row : rs) {
            NodeRef nodeRef = row.getNodeRef();
            if (!nodeService.exists(nodeRef) || filter(nodeRef)) {
                continue;
            }
            TypeDefinitionWrapper type = getType(nodeRef);
            if (type == null) {
                continue;
            }
            ObjectDataImpl hit = new ObjectDataImpl();
            PropertiesImpl properties = new PropertiesImpl();
            hit.setProperties(properties);
            Map<String, Serializable> values = row.getValues();
            for (CMISResultSetColumn column : columns) {
                AbstractPropertyData<?> property = getProperty(column.getCMISDataType(), column.getCMISPropertyDefinition(), values.get(column.getName()));
                property.setQueryName(column.getName());
                properties.addProperty(property);
            }
            if (fetchObject) {
                // set allowable actions
                if (includeAllowableActions) {
                    CMISNodeInfoImpl nodeInfo = createNodeInfo(nodeRef);
                    if (!nodeInfo.getObjectVariant().equals(CMISObjectVariant.NOT_EXISTING)) {
                        hit.setAllowableActions(getAllowableActions(nodeInfo));
                    }
                }
                // set relationships
                if (includeRelationships != IncludeRelationships.NONE) {
                    hit.setRelationships(getRelationships(nodeRef, includeRelationships));
                }
                // set renditions
                if (!RENDITION_NONE.equals(renditionFilter)) {
                    List<RenditionData> renditions = getRenditions(nodeRef, renditionFilter, null, null);
                    if ((renditions != null) && (!renditions.isEmpty())) {
                        hit.setRenditions(renditions);
                    } else {
                        hit.setRenditions(Collections.EMPTY_LIST);
                    }
                }
            }
            result.getObjects().add(hit);
        }
        long numberFound = rs.getNumberFound();
        if (numberFound != -1) {
            result.setNumItems(BigInteger.valueOf(numberFound));
        }
        result.setHasMoreItems(rs.hasMore());
    } finally {
        rs.close();
    }
    return result;
}
Also used : CmisVersion(org.apache.chemistry.opencmis.commons.enums.CmisVersion) Serializable(java.io.Serializable) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) 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) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl) CMISQueryOptions(org.alfresco.opencmis.search.CMISQueryOptions) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) CMISResultSetRow(org.alfresco.opencmis.search.CMISResultSetRow) ObjectDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl) CMISResultSetColumn(org.alfresco.opencmis.search.CMISResultSetColumn) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Example 27 with TypeDefinitionWrapper

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

the class AlfrescoCmisServiceImpl method removePolicy.

@Override
public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    TypeDefinitionWrapper type = info.getType();
    if (type == null) {
        throw new CmisObjectNotFoundException("No corresponding type found! Not a CMIS object?");
    }
    throw new CmisConstraintException("Object is not policy controllable!");
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 28 with TypeDefinitionWrapper

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

the class AlfrescoCmisServiceImpl method create.

// --- object service ---
@Override
public String create(String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List<String> policies, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // check properties
    if (properties == null || properties.getProperties() == null) {
        throw new CmisInvalidArgumentException("Properties must be set!");
    }
    // get the type
    String objectTypeId = connector.getObjectTypeIdProperty(properties);
    // find the type
    TypeDefinitionWrapper type = connector.getOpenCMISDictionaryService().findType(objectTypeId);
    if (type == null) {
        throw new CmisInvalidArgumentException("Type '" + objectTypeId + "' is unknown!");
    }
    // create object
    String newId = null;
    switch(type.getBaseTypeId()) {
        case CMIS_DOCUMENT:
            versioningState = getDocumentDefaultVersioningState(versioningState, type);
            newId = createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, null, null, extension);
            break;
        case CMIS_FOLDER:
            newId = createFolder(repositoryId, properties, folderId, policies, null, null, extension);
            break;
        case CMIS_POLICY:
            newId = createPolicy(repositoryId, properties, folderId, policies, null, null, extension);
            break;
        case CMIS_ITEM:
            newId = createItem(repositoryId, properties, folderId, policies, null, null, extension);
            break;
        default:
            break;
    }
    // check new object id
    if (newId == null) {
        throw new CmisRuntimeException("Creation failed!");
    }
    boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired) {
        try {
            getObjectInfo(repositoryId, newId, "*", IncludeRelationships.NONE);
        } catch (InvalidNodeRefException e) {
            throw new CmisRuntimeException("Creation failed! New object not found!");
        }
    }
    // return the new object id
    return newId;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 29 with TypeDefinitionWrapper

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

the class AlfrescoCmisServiceImpl method createRelationship.

@Override
public String createRelationship(String repositoryId, Properties properties, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // get type
    String objectTypeId = connector.getObjectTypeIdProperty(properties);
    final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_RELATIONSHIP);
    // get source object
    String sourceId = connector.getSourceIdProperty(properties);
    CMISNodeInfo sourceInfo = getOrCreateNodeInfo(sourceId, "Source");
    if (!sourceInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !sourceInfo.isVariant(CMISObjectVariant.FOLDER) && !sourceInfo.isVariant(CMISObjectVariant.ITEM)) {
        throw new CmisInvalidArgumentException("Source is not the latest version of a document, a folder or an item object!");
    }
    final NodeRef sourceNodeRef = sourceInfo.getNodeRef();
    // get target object
    String targetId = connector.getTargetIdProperty(properties);
    CMISNodeInfo targetInfo = getOrCreateNodeInfo(targetId, "Target");
    if (!targetInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !targetInfo.isVariant(CMISObjectVariant.FOLDER) && !targetInfo.isVariant(CMISObjectVariant.ITEM)) {
        throw new CmisInvalidArgumentException("Target is not the latest version of a document, a folder or an item object!!");
    }
    final NodeRef targetNodeRef = targetInfo.getNodeRef();
    // check policies and ACLs
    if ((policies != null) && (!policies.isEmpty())) {
        throw new CmisConstraintException("Relationships are not policy controllable!");
    }
    if ((addAces != null) && (addAces.getAces() != null) && (!addAces.getAces().isEmpty())) {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }
    if ((removeAces != null) && (removeAces.getAces() != null) && (!removeAces.getAces().isEmpty())) {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }
    // create relationship
    // ALF-10085 : disable auditing behaviour for this use case
    // Lasts for txn
    boolean wasEnabled = connector.disableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
    try {
        AssociationRef assocRef = connector.getNodeService().createAssociation(sourceNodeRef, targetNodeRef, type.getAlfrescoClass());
        return CMISConnector.ASSOC_ID_PREFIX + assocRef.getId();
    } finally {
        if (wasEnabled) {
            connector.enableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 30 with TypeDefinitionWrapper

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

the class AlfrescoCmisServiceImpl method getTypesDescendants.

/**
 * Gathers the type descendants tree.
 */
private TypeDefinitionContainer getTypesDescendants(int depth, TypeDefinitionWrapper tdw, boolean includePropertyDefinitions) {
    TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl();
    result.setTypeDefinition(tdw.getTypeDefinition(includePropertyDefinitions));
    if (depth != 0) {
        String typeId = tdw.getTypeId();
        List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId);
        if (children != null) {
            result.setChildren(new ArrayList<TypeDefinitionContainer>());
            for (TypeDefinitionWrapper tdc : children) {
                result.getChildren().add(getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions));
            }
        }
    }
    return result;
}
Also used : TypeDefinitionContainerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer)

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