Search in sources :

Example 31 with CmisService

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

the class CMISTest method testSearchPreviousDelete.

@Test
public void testSearchPreviousDelete() {
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        final NodeRef companyHome = repositoryHelper.getCompanyHome();
        // create parentFolder
        RetryingTransactionCallback<Object> testCallbackFolder = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                NodeRef parentFolder = createFolder(companyHome, "testCreateParent" + GUID.generate(), ContentModel.TYPE_FOLDER);
                return parentFolder;
            }
        };
        final NodeRef parentFolder = (NodeRef) transactionService.getRetryingTransactionHelper().doInTransaction(testCallbackFolder, false, true);
        // create children Folders
        final List<NodeRef> folders = new ArrayList<NodeRef>();
        RetryingTransactionCallback<Object> testCallbackChilds = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                for (int i = 0; i < 10; i++) {
                    folders.add(createFolder(parentFolder, "testCreateList-" + GUID.generate() + i, ContentModel.TYPE_FOLDER));
                }
                return folders;
            }
        };
        transactionService.getRetryingTransactionHelper().doInTransaction(testCallbackChilds, false, true);
        // remove children nodes
        executorService.submit(new Runnable() {

            public void run() {
                for (final NodeRef node : folders) {
                    AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {

                        public Void doWork() throws Exception {
                            transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                                public Void execute() throws Throwable {
                                    nodeService.deleteNode(node);
                                    return null;
                                }
                            }, false, true);
                            return null;
                        }
                    }, AuthenticationUtil.getAdminUserName());
                }
            }
        });
        // select children nodes removed
        withCmisService(new CmisServiceCallback<String>() {

            @Override
            public String execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                // prepare cmis query
                String queryString = "SELECT cmis:name, cmis:objectId FROM cmis:folder WHERE IN_FOLDER('" + parentFolder + "')";
                cmisService.query(repositoryId, queryString, Boolean.FALSE, Boolean.TRUE, IncludeRelationships.NONE, "", BigInteger.TEN, BigInteger.ZERO, null);
                return "";
            }
        }, CmisVersion.CMIS_1_1);
    } catch (Exception e) {
        fail(e.toString());
    } finally {
        executorService.shutdownNow();
    }
}
Also used : RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) ArrayList(java.util.ArrayList) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ExecutorService(java.util.concurrent.ExecutorService) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)31 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)26 List (java.util.List)23 ObjectInFolderList (org.apache.chemistry.opencmis.commons.data.ObjectInFolderList)23 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)23 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)23 FileInfo (org.alfresco.service.cmr.model.FileInfo)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)14 HashMap (java.util.HashMap)11 PropertiesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl)11 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)11 PropertyStringImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl)10 Map (java.util.Map)9 MimetypeMap (org.alfresco.repo.content.MimetypeMap)9 QName (org.alfresco.service.namespace.QName)8 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)8 PropertyIdImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl)8