Search in sources :

Example 16 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getAcl.

@SuppressWarnings("unchecked")
@Override
public Acl getAcl(String repositoryId, String objectId, Boolean onlyBasicPermissions, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    // relationships don't have ACLs
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        return new AccessControlListImpl(Collections.EMPTY_LIST);
    }
    // get the ACL
    return connector.getACL(info.getCurrentNodeNodeRef(), onlyBasicPermissions);
}
Also used : AccessControlListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 17 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method bulkUpdateProperties.

@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    if (objectIdAndChangeTokens.size() > connector.getBulkMaxItems()) {
        throw new CmisConstraintException("Bulk update not supported for more than " + connector.getBulkMaxItems() + " objects.");
    }
    // MNT-16376 We need the CMIS call context from this thread to set
    // to the working threads below, in order to correctly identify
    // the CMIS version protocol used for this CMIS call
    final CallContext cmisCallContext = AlfrescoCmisServiceCall.get();
    // WorkProvider
    class WorkProvider implements BatchProcessWorkProvider<BulkEntry> {

        private final Iterator<BulkUpdateObjectIdAndChangeToken> iterator;

        private final int size;

        private final int batchSize;

        private BulkUpdateContext context;

        public WorkProvider(List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeTokens, BulkUpdateContext context, int batchSize) {
            this.iterator = objectIdAndChangeTokens.iterator();
            this.size = objectIdAndChangeTokens.size();
            this.context = context;
            this.batchSize = batchSize;
        }

        @Override
        public synchronized int getTotalEstimatedWorkSize() {
            return size;
        }

        @Override
        public synchronized Collection<BulkEntry> getNextWork() {
            Collection<BulkEntry> results = new ArrayList<BulkEntry>(batchSize);
            while (results.size() < batchSize && iterator.hasNext()) {
                results.add(new BulkEntry(context, iterator.next(), properties, addSecondaryTypeIds, removeSecondaryTypeIds, getContext().isObjectInfoRequired()));
            }
            return results;
        }
    }
    BulkUpdateContext context = new BulkUpdateContext(objectIdAndChangeTokens.size());
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    final String runAsUser = AuthenticationUtil.getRunAsUser();
    // Worker
    BatchProcessWorker<BulkEntry> worker = new BatchProcessWorker<BulkEntry>() {

        @Override
        public void process(final BulkEntry entry) throws Throwable {
            entry.update();
        }

        public String getIdentifier(BulkEntry entry) {
            return entry.getObjectIdAndChangeToken().getId();
        }

        @Override
        public void beforeProcess() throws Throwable {
            // Authentication
            AuthenticationUtil.pushAuthentication();
            AuthenticationUtil.setFullyAuthenticatedUser(runAsUser);
            AlfrescoCmisServiceCall.set(cmisCallContext);
        }

        @Override
        public void afterProcess() throws Throwable {
            // Clear authentication
            AuthenticationUtil.popAuthentication();
        }
    };
    // Processor
    BatchProcessor<BulkEntry> processor = new BatchProcessor<BulkEntry>("CMISbulkUpdateProperties", helper, new WorkProvider(objectIdAndChangeTokens, context, connector.getBulkBatchSize()), connector.getBulkWorkerThreads(), connector.getBulkBatchSize(), null, logger, 100);
    processor.process(worker, true);
    for (CMISNodeInfo info : context.getSuccesses()) {
        NodeRef nodeRef = info.getNodeRef();
        connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
    }
    return context.getChanges();
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) ArrayList(java.util.ArrayList) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider) BatchProcessWorker(org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker) NodeRef(org.alfresco.service.cmr.repository.NodeRef) BatchProcessor(org.alfresco.repo.batch.BatchProcessor) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider) Iterator(java.util.Iterator) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List)

Example 18 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method applyAcl.

// --- ACL service ---
@Override
public Acl applyAcl(String repositoryId, String objectId, final Acl addAces, final Acl removeAces, AclPropagation aclPropagation, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // We are spec compliant if we just let it through and the tck will not fail
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    // relationships don't have ACLs
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }
    final NodeRef nodeRef = info.getCurrentNodeNodeRef();
    final TypeDefinitionWrapper type = info.getType();
    connector.applyACL(nodeRef, type, addAces, removeAces);
    return connector.getACL(nodeRef, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 19 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getObjectInfo.

protected ObjectInfo getObjectInfo(String repositoryId, String objectId, String filter, IncludeRelationships includeRelationships) {
    ObjectInfo info = objectInfoMap.get(objectId);
    if (info == null) {
        CMISNodeInfo nodeInfo = getOrCreateNodeInfo(objectId);
        if (nodeInfo.getObjectVariant() == CMISObjectVariant.INVALID_ID || nodeInfo.getObjectVariant() == CMISObjectVariant.NOT_EXISTING || nodeInfo.getObjectVariant() == CMISObjectVariant.NOT_A_CMIS_OBJECT || nodeInfo.getObjectVariant() == CMISObjectVariant.PERMISSION_DENIED) {
            info = null;
        } else {
            // object info has not been found -> create one
            try {
                if (filter == null) {
                    filter = MIN_FILTER;
                } else if (!filter.equals("*")) {
                    filter = filter + "," + MIN_FILTER;
                }
                // get the object and its info
                ObjectData object = connector.createCMISObject(nodeInfo, filter, false, includeRelationships, null, false, false);
                info = getObjectInfoIntern(repositoryId, object);
                // add object info
                objectInfoMap.put(objectId, info);
            } catch (Exception e) {
                e.printStackTrace();
                info = null;
            }
        }
    }
    return info;
}
Also used : ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ObjectInfo(org.apache.chemistry.opencmis.commons.server.ObjectInfo) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Example 20 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getProperties.

@Override
public Properties getProperties(String repositoryId, String objectId, String filter, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired) {
        getObjectInfo(repositoryId, info.getObjectId(), IncludeRelationships.NONE);
    }
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        return connector.getAssocProperties(info, filter);
    } else {
        return connector.getNodeProperties(info, filter);
    }
}
Also used : CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Aggregations

CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)42 NodeRef (org.alfresco.service.cmr.repository.NodeRef)26 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)15 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)13 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)13 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)10 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)8 ArrayList (java.util.ArrayList)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)5 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)5 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)4 QName (org.alfresco.service.namespace.QName)4 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)4 IOException (java.io.IOException)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3 Serializable (java.io.Serializable)2