Search in sources :

Example 1 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project iaf by ibissource.

the class CmisUtils method populateCmisAttributes.

public static void populateCmisAttributes(PipeLineSession session) {
    CallContext callContext = (CallContext) session.get(CMIS_CALLCONTEXT_KEY);
    if (callContext != null) {
        session.put(CMIS_VERSION_KEY, callContext.getCmisVersion());
        session.put(CMIS_BINDING_KEY, callContext.getBinding());
        if ("basic".equalsIgnoreCase(CMIS_SECURITYHANDLER)) {
            HttpServletRequest request = (HttpServletRequest) callContext.get(CallContext.HTTP_SERVLET_REQUEST);
            session.setSecurityHandler(new HttpSecurityHandler(request));
        } else if ("wsse".equalsIgnoreCase(CMIS_SECURITYHANDLER)) {
            session.setSecurityHandler(new CmisSecurityHandler(callContext));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CmisSecurityHandler(nl.nn.adapterframework.extensions.cmis.server.CmisSecurityHandler) HttpSecurityHandler(nl.nn.adapterframework.http.HttpSecurityHandler) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext)

Example 2 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext 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 3 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class CMISConnector method isPublicApi.

private boolean isPublicApi() {
    boolean isPublicApi = false;
    CallContext callContext = AlfrescoCmisServiceCall.get();
    if (callContext != null) {
        String value = (String) callContext.get("isPublicApi");
        isPublicApi = (value == null ? false : Boolean.parseBoolean(value));
    }
    return isPublicApi;
}
Also used : PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext)

Example 4 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class CMISConnector method getRequestCmisVersion.

public CmisVersion getRequestCmisVersion() {
    CallContext callContext = AlfrescoCmisServiceCall.get();
    CmisVersion cmisVersion = (callContext != null ? callContext.getCmisVersion() : CmisVersion.CMIS_1_0);
    return cmisVersion;
}
Also used : CmisVersion(org.apache.chemistry.opencmis.commons.enums.CmisVersion) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext)

Example 5 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class CMISTest method testLastVersionOfVersionSeries.

/**
 * Test to ensure that set of aspect returned by cmisService#getAllVersions for latest version is the same
 * as for the object returned by cmisService#getObjectByPath.
 *
 * See <a href="https://issues.alfresco.com/jira/browse/MNT-9557">MNT-9557</a>
 */
@Test
public void testLastVersionOfVersionSeries() {
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final String FOLDER = "testUpdatePropertiesSetDeleteContentVersioning-" + GUID.generate(), DOC = "documentProperties-" + GUID.generate();
    try {
        final NodeRef nodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {

            @Override
            public NodeRef execute() throws Throwable {
                // create folder
                FileInfo folderInfo = fileFolderService.create(repositoryHelper.getCompanyHome(), FOLDER, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, FOLDER);
                assertNotNull(folderInfo);
                // create documents
                FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), DOC, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_DESCRIPTION, "Initial doc");
                return document.getNodeRef();
            }
        });
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                // make sure that there is no version history yet
                assertNull(versionService.getVersionHistory(nodeRef));
                // create a version
                // turn off auto-versioning
                Map<QName, Serializable> props = new HashMap<QName, Serializable>();
                props.put(ContentModel.PROP_INITIAL_VERSION, false);
                props.put(ContentModel.PROP_AUTO_VERSION, false);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
                versionService.ensureVersioningEnabled(nodeRef, props);
                return null;
            }
        });
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                assertNotNull(versionService.getVersionHistory(nodeRef));
                // create another one version
                versionService.createVersion(nodeRef, null);
                return null;
            }
        });
        final String NEW_DOC_NAME = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {

            @Override
            public String execute() throws Throwable {
                // add aspect to the node
                String newDocName = DOC + GUID.generate();
                nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null);
                nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, newDocName);
                return newDocName;
            }
        });
        CmisService cmisService = factory.getService(context);
        String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
        List<ObjectData> versions = cmisService.getAllVersions(repositoryId, nodeRef.toString(), null, null, null, null);
        assertNotNull(versions);
        // get the latest version
        ObjectData latestVersion = versions.get(0);
        // get the object
        ObjectData object = // cmisService.getObjectOfLatestVersion(repositoryId, nodeRef.toString(), null, false, null, null, null, null, false, false, null);
        cmisService.getObjectByPath(repositoryId, "/" + FOLDER + "/" + NEW_DOC_NAME, null, null, null, null, false, false, null);
        assertNotNull(latestVersion);
        assertNotNull(object);
        Object objectDescriptionString = object.getProperties().getProperties().get("cmis:name").getValues().get(0);
        Object latestVersionDescriptionString = latestVersion.getProperties().getProperties().get("cmis:name").getValues().get(0);
        // ensure that node and latest version both have same description
        assertEquals(objectDescriptionString, latestVersionDescriptionString);
        Set<String> documentAspects = new HashSet<String>();
        for (CmisExtensionElement cmisEE : object.getProperties().getExtensions().get(0).getChildren()) {
            documentAspects.add(cmisEE.getValue());
        }
        Set<String> latestVersionAspects = new HashSet<String>();
        for (CmisExtensionElement cmisEE : latestVersion.getProperties().getExtensions().get(0).getChildren()) {
            latestVersionAspects.add(cmisEE.getValue());
        }
        // ensure that node and latest version both have the same set of aspects
        assertEquals(latestVersionAspects, documentAspects);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

CallContext (org.apache.chemistry.opencmis.commons.server.CallContext)11 CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)5 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 FileInfo (org.alfresco.service.cmr.model.FileInfo)3 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)3 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)3 UnfileObject (org.apache.chemistry.opencmis.commons.enums.UnfileObject)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 QName (org.alfresco.service.namespace.QName)2 Properties (org.apache.chemistry.opencmis.commons.data.Properties)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1