Package org.apache.chemistry.opencmis.client.api

Examples of org.apache.chemistry.opencmis.client.api.OperationContext


    public void refresh() {
        writeLock();
        try {
            String objectId = getObjectId();

            OperationContext oc = getCreationContext();

            // get the latest data from the repository
            ObjectData objectData = getSession()
                    .getBinding()
                    .getObjectService()
                    .getObject(getRepositoryId(), objectId, oc.getFilterString(), oc.isIncludeAllowableActions(),
                            oc.getIncludeRelationships(), oc.getRenditionFilterString(), oc.isIncludePolicies(),
                            oc.isIncludeAcls(), null);

            // reset this object
            initialize(getSession(), getObjectType(), objectData, this.creationContext);
        } finally {
            writeUnlock();
View Full Code Here


        }
    }

    public synchronized ItemIterable<QueryResult> query(String q, boolean searchAllVersions, int maxHits)
            throws Exception {
        OperationContext queryContext = new OperationContextImpl(null, false, false, false, IncludeRelationships.NONE,
                null, false, null, false, maxHits);

        Session session = clientSession.getSession();
        return session.query(q, searchAllVersions, queryContext);
    }
View Full Code Here

    ObjectId id = this.session.createDocument(properties, parentId,
        contentStream1, VersioningState.NONE);
    assertNotNull(id);

    // prepare new non-cache operation context
    OperationContext oc = this.session.createOperationContext();
    oc.setFilterString("*");
    oc.setCacheEnabled(false);

    // set new name and save
    Document doc2 = (Document) this.session.getObject(id, oc);
    TransientDocument tdoc2 = doc2.getTransientDocument();

View Full Code Here

    public ItemIterable<Document> getCheckedOutDocs(OperationContext context) {
        final String objectId = getObjectId();
        final NavigationService navigationService = getBinding().getNavigationService();
        final ObjectFactory objectFactory = getSession().getObjectFactory();
        final OperationContext ctxt = new OperationContextImpl(context);

        return new CollectionIterable<Document>(new AbstractPageFetcher<Document>(ctxt.getMaxItemsPerPage()) {

            @Override
            protected AbstractPageFetcher.Page<Document> fetchPage(long skipCount) {

                // get checked out documents for this folder
                ObjectList checkedOutDocs = navigationService.getCheckedOutDocs(getRepositoryId(), objectId,
                        ctxt.getFilterString(), ctxt.getOrderBy(), ctxt.isIncludeAllowableActions(),
                        ctxt.getIncludeRelationships(), ctxt.getRenditionFilterString(),
                        BigInteger.valueOf(this.maxNumItems), BigInteger.valueOf(skipCount), null);

                // convert objects
                List<Document> page = new ArrayList<Document>();
                if (checkedOutDocs.getObjects() != null) {
View Full Code Here

    public ItemIterable<CmisObject> getChildren(OperationContext context) {
        final String objectId = getObjectId();
        final NavigationService navigationService = getBinding().getNavigationService();
        final ObjectFactory objectFactory = getSession().getObjectFactory();
        final OperationContext ctxt = new OperationContextImpl(context);

        return new CollectionIterable<CmisObject>(new AbstractPageFetcher<CmisObject>(ctxt.getMaxItemsPerPage()) {

            @Override
            protected AbstractPageFetcher.Page<CmisObject> fetchPage(long skipCount) {

                // get the children
                ObjectInFolderList children = navigationService.getChildren(getRepositoryId(), objectId,
                        ctxt.getFilterString(), ctxt.getOrderBy(), ctxt.isIncludeAllowableActions(),
                        ctxt.getIncludeRelationships(), ctxt.getRenditionFilterString(), ctxt.isIncludePathSegments(),
                        BigInteger.valueOf(this.maxNumItems), BigInteger.valueOf(skipCount), null);

                // convert objects
                List<CmisObject> page = new ArrayList<CmisObject>();
                List<ObjectInFolderData> childObjects = children.getObjects();
View Full Code Here

            throw new IllegalArgumentException("Operation context must be set!");
        }

        final NavigationService navigationService = getBinding().getNavigationService();
        final ObjectFactory objectFactory = getObjectFactory();
        final OperationContext ctxt = new OperationContextImpl(context);

        return new CollectionIterable<Document>(new AbstractPageFetcher<Document>(ctxt.getMaxItemsPerPage()) {

            @Override
            protected AbstractPageFetcher.Page<Document> fetchPage(long skipCount) {

                // get all checked out documents
                ObjectList checkedOutDocs = navigationService.getCheckedOutDocs(getRepositoryId(), null,
                        ctxt.getFilterString(), ctxt.getOrderBy(), ctxt.isIncludeAllowableActions(),
                        ctxt.getIncludeRelationships(), ctxt.getRenditionFilterString(),
                        BigInteger.valueOf(this.maxNumItems), BigInteger.valueOf(skipCount), null);

                // convert objects
                List<Document> page = new ArrayList<Document>();
                if (checkedOutDocs.getObjects() != null) {
View Full Code Here

        newFolderProps.put(PropertyIds.NAME, "ADGFolderPaging");
        Folder folderPaging = root.createFolder(newFolderProps);
        createFolders(folderPaging, 10);

        System.out.println("Getting page of length 3 from item 5");
        OperationContext operationContext = new OperationContextImpl();
        operationContext.setMaxItemsPerPage(3);
        ItemIterable<CmisObject> children1 = folderPaging.getChildren(operationContext);
        int count = 0;
        for (CmisObject child : children1.skipTo(5).getPage()) {
            System.out.println("object " + count + " in page of " + children1.getPageNumItems()
                    + " is " + child.getName());
            count++;
        }

        // operationContext = new OperationContextImpl();
        // operationContext.setMaxItemsPerPage(3);
        // children1 = folderPaging.getChildren(operationContext);
        // int pageNumber = 0;
        // count = 1;
        // while (count > 0) {
        // count = 0;
        // for (CmisObject child : children1.skipTo(
        // pageNumber * operationContext.getMaxItemsPerPage()).getPage()) {
        // System.out.println("object " + count + " in page" + pageNumber +
        // " is "
        // + child.getName());
        // count++;
        // }
        // pageNumber++;
        // }

        System.out.println("Getting complete result set in pages of 3");
        operationContext = new OperationContextImpl();
        operationContext.setMaxItemsPerPage(3);
        children1 = folderPaging.getChildren(operationContext);
        int pageNumber = 0;
        boolean finished = false;
        while (!finished) {
            count = 0;
            ItemIterable<CmisObject> currentPage = children1.skipTo(
                    pageNumber * operationContext.getMaxItemsPerPage()).getPage();
            for (CmisObject item : currentPage) {
                System.out.println("object " + count + " in page" + pageNumber + " is "
                        + item.getName());
                count++;
            }
            pageNumber++;
            if (!currentPage.getHasMoreItems())
                finished = true;
        }

        // Types
        System.out.println("\nTypes...");
        System.out.println("--------");
        // Look at the type definition
        System.out.println("Getting type definition for doc");
        ObjectType objectType = session.getTypeDefinition(doc.getType().getId());
        System.out.println("doc is of type " + objectType.getDisplayName());
        System.out.println("isBaseType() returns " + (objectType.isBaseType() ? "true" : "false"));
        ObjectType baseType = objectType.getBaseType();
        if (baseType == null) {
            System.out.println("getBaseType() returns null");
        } else {
            System.out.println("getBaseType() returns " + baseType.getDisplayName());
        }
        ObjectType parentType = objectType.getParentType();
        if (parentType == null) {
            System.out.println("getParentType() returns null");
        } else {
            System.out.println("getParentType() returns " + parentType.getDisplayName());
        }
        System.out.println("Listing child types of " + objectType.getDisplayName());
        for (ObjectType o : objectType.getChildren()) {
            System.out.println("\t" + o.getDisplayName());
        }
        System.out.println("Getting immediate descendant types of " + objectType.getDisplayName());
        for (Tree<ObjectType> o : objectType.getDescendants(1)) {
            System.out.println("\t" + o.getItem().getDisplayName());
        }

        System.out.println("\nProperties...");
        System.out.println("-------------");
        // Look at all the properties of the document
        System.out.println(doc.getName() + " properties start");
        List<Property<?>> props = doc.getProperties();
        for (Property<?> p : props) {
            System.out.println(p.getDefinition().getDisplayName() + "=" + p.getValuesAsString());
        }
        System.out.println(doc.getName() + " properties end");

        // Get some document properties explicitly
        System.out.println("VersionLabel property on " + doc.getName() + " is "
                + doc.getVersionLabel());
        // System.out.println("Is this the latest version of " + doc.getName() +
        // " ?:  "
        // + (doc.isLatestVersion() ? "yes" : "no"));

        // get a property by id
        System.out.println("get property by property id");
        Property<?> someProperty = props.get(0);
        System.out.println(someProperty.getDisplayName() + " property on " + doc.getName()
                + " (by getPropertValue()) is " + doc.getPropertyValue(someProperty.getId()));

        // get a property by query name
        System.out.println("get property by query name");
        if (session.getRepositoryInfo().getCapabilities().getQueryCapability()
                .equals(CapabilityQuery.METADATAONLY)) {
            System.out.println("Full search not supported");
        } else {
            String query = "SELECT * FROM cmis:document WHERE cmis:name = 'test.txt'";
            ItemIterable<QueryResult> queryResult = session.query(query, false);
            for (QueryResult item : queryResult) {
                System.out.println("property cmis:createdBy on test.txt is "
                        + item.getPropertyByQueryName("cmis:createdBy").getFirstValue());
            }
        }

        GregorianCalendar calendar = doc.getCreationDate();
        String DATE_FORMAT = "yyyyMMdd";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        System.out.println("Creation date of " + doc.getName() + " is  "
                + sdf.format(calendar.getTime()));

        System.out.println("\nQuery...");
        System.out.println("--------");
        // Query 1 - need full query capability for this
        if (session.getRepositoryInfo().getCapabilities().getQueryCapability()
                .equals(CapabilityQuery.METADATAONLY)) {
            System.out.println("Full search not supported");
        } else {
            String query = "SELECT * FROM cmis:document WHERE cmis:name LIKE 'test%'";
            ItemIterable<QueryResult> q = session.query(query, false);

            // Did it work?
            System.out.println("***results from query " + query);

            int i = 1;
            for (QueryResult qr : q) {
                System.out.println("--------------------------------------------\n" + i + " , "
                        + qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:name").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:createdBy").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:objectId").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue()
                        + " , "
                        + qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue()
                        + " , "
                        + qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue());
                i++;
            }

            // Query 2
            query = "SELECT * FROM cmis:document WHERE cmis:name LIKE 'test%.txt' AND CONTAINS('test')";
            q = session.query(query, false);

            System.out.println("***results from query " + query);

            i = 1;
            for (QueryResult qr : q) {
                System.out.println("--------------------------------------------\n" + i + " , "
                        + qr.getPropertyByQueryName("cmis:objectTypeId").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:name").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:createdBy").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:objectId").getFirstValue() + " , "
                        + qr.getPropertyByQueryName("cmis:contentStreamFileName").getFirstValue()
                        + " , "
                        + qr.getPropertyByQueryName("cmis:contentStreamMimeType").getFirstValue()
                        + " , "
                        + qr.getPropertyByQueryName("cmis:contentStreamLength").getFirstValue());
                i++;
            }
        }

        System.out.println("\nCapabilities...");
        System.out.println("---------------");
        // Check what capabilities our repository supports
        System.out.println("Printing repository capabilities...");
        final RepositoryInfo repInfo = session.getRepositoryInfo();
        RepositoryCapabilities cap = repInfo.getCapabilities();
        System.out.println("\nNavigation Capabilities");
        System.out.println("-----------------------");
        System.out.println("Get descendants supported: "
                + (cap.isGetDescendantsSupported() ? "true" : "false"));
        System.out.println("Get folder tree supported: "
                + (cap.isGetFolderTreeSupported() ? "true" : "false"));
        System.out.println("\nObject Capabilities");
        System.out.println("-----------------------");
        System.out.println("Content Stream: " + cap.getContentStreamUpdatesCapability().value());
        System.out.println("Changes: " + cap.getChangesCapability().value());
        System.out.println("Renditions: " + cap.getRenditionsCapability().value());
        System.out.println("\nFiling Capabilities");
        System.out.println("-----------------------");
        System.out.println("Multifiling supported: "
                + (cap.isMultifilingSupported() ? "true" : "false"));
        System.out.println("Unfiling supported: " + (cap.isUnfilingSupported() ? "true" : "false"));
        System.out.println("Version specific filing supported: "
                + (cap.isVersionSpecificFilingSupported() ? "true" : "false"));
        System.out.println("\nVersioning Capabilities");
        System.out.println("-----------------------");
        System.out
                .println("PWC searchable: " + (cap.isPwcSearchableSupported() ? "true" : "false"));
        System.out.println("PWC Updatable: " + (cap.isPwcUpdatableSupported() ? "true" : "false"));
        System.out.println("All versions searchable: "
                + (cap.isAllVersionsSearchableSupported() ? "true" : "false"));
        System.out.println("\nQuery Capabilities");
        System.out.println("-----------------------");
        System.out.println("Query: " + cap.getQueryCapability().value());
        System.out.println("Join: " + cap.getJoinCapability().value());
        System.out.println("\nACL Capabilities");
        System.out.println("-----------------------");
        System.out.println("ACL: " + cap.getAclCapability().value());
        System.out.println("End of  repository capabilities");

        System.out.println("\nAllowable actions...");
        System.out.println("--------------------");
        // find the current allowable actions for the test.txt document
        System.out.println("Getting the current allowable actions for the " + doc.getName()
                + " document object...");
        for (Action a : doc.getAllowableActions().getAllowableActions()) {
            System.out.println("\t" + a.value());
        }

        // find out if we can currently check out test.txt
        if (doc.getAllowableActions().getAllowableActions().contains(Action.CAN_CHECK_OUT)) {
            System.out.println("can check out " + doc.getName());
        } else {
            System.out.println("can not check out " + doc.getName());
        }

        System.out.println("\nMultifiling and Unfiling...");
        System.out.println("---------------------------");
        // Try out multifiling if it is supported
        System.out.println("Trying out multifiling");
        Folder newFolder2 = null;
        if (!(cap.isMultifilingSupported())) {
            System.out.println("Multifiling not supported by this repository");
        } else {
            // Add a new folder to the root folder
            System.out.println("Creating 'ADGNewFolder 2' in the root folder");
            newFolderProps = new HashMap<String, String>();
            newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
            newFolderProps.put(PropertyIds.NAME, "ADGNewFolder 2");
            newFolder2 = root.createFolder(newFolderProps, null, null, null,
                    session.getDefaultContext());
            System.out.println("Adding " + textFileName + "to 'ADGNewFolder 2' in the root folder");
            doc.addToFolder(newFolder2, true);

            // Did it work?
            children = newFolder.getChildren();
            System.out.println("Now finding the following objects in the 'ADGNewFolder' folder:-");
            for (CmisObject o : children) {
                System.out.println(o.getName());
            }
            children = newFolder2.getChildren();
            System.out
                    .println("Now finding the following objects in the 'ADGNewFolder 2' folder:-");
            for (CmisObject o : children) {
                System.out.println(o.getName());
            }
        }

        // Try out unfiling if it is supported
        System.out.println("Trying out unfiling");
        if (!(cap.isUnfilingSupported())) {
            System.out.println("Unfiling not supported by this repository");
        } else {
            // remove our document from both folders
            System.out.println("removing :" + doc.getName() + "from 'ADGNewFolder':-");
            doc.removeFromFolder(newFolder);
            System.out.println("removing :" + doc.getName() + "from 'ADGNewFolder 2':-");
            doc.removeFromFolder(newFolder2);
            // Did it work?
            Document docTest = (Document) session.getObject(id);
            if (docTest != null) {
                System.out.println(docTest.getName() + " still exists");
            }

        }

        System.out.println("\nVersioning...");
        System.out.println("-------------");
        // Check whether a document is versionable
        boolean versionable = false;
        if (((DocumentType) (doc.getType())).isVersionable()) {
            System.out.println(doc.getName() + " is versionable");
            versionable = true;
        } else {
            System.out.println(doc.getName() + " is NOT versionable");
        }

        // check out the latest version of test.txt, make some changes to the
        // PWC, and
        // check in the new version
        if (versionable) {
            Document pwc = (Document) session.getObject(doc.checkOut());
            try {
                content = getContentAsString(pwc.getContentStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
            String updatedContents = content + "\nLine added in new version";

            try {
                buf = updatedContents.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            contentStream = session.getObjectFactory().createContentStream(
                    doc.getContentStream().getFileName(), buf.length,
                    doc.getContentStream().getMimeType(), new ByteArrayInputStream(buf));

            // Check in the pwc
            try {
                pwc.checkIn(false, null, contentStream, "minor version");
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("checkin failed, trying to cancel the checkout");
                pwc.cancelCheckOut();
            }

            System.out.println("Document version history");
            {
                List<Document> versions = doc.getAllVersions();
                for (Document version : versions) {
                    System.out.println("\tname: " + version.getName());
                    System.out.println("\tversion label: " + version.getVersionLabel());
                    System.out.println("\tversion series id: " + version.getVersionSeriesId());
                    System.out.println("\tchecked out by: "
                            + version.getVersionSeriesCheckedOutBy());
                    System.out.println("\tchecked out id: "
                            + version.getVersionSeriesCheckedOutId());
                    System.out.println("\tmajor version: " + version.isMajorVersion());
                    System.out.println("\tlatest version: " + version.isLatestVersion());
                    System.out.println("\tlatest major version: " + version.isLatestMajorVersion());
                    System.out.println("\tcheckin comment: " + version.getCheckinComment());
                    System.out.println("\tcontent length: " + version.getContentStreamLength()
                            + "\n");
                }
            }
        }

        System.out.println("\nRenditions...");
        System.out.println("-------------");

        // Renditions - find all objects and check for renditions
        if (session.getRepositoryInfo().getCapabilities().getRenditionsCapability()
                .equals(CapabilityRenditions.NONE)) {
            System.out.println("Repository does not support renditions");
        } else {
            System.out
                    .println("Finding first object in repository with thumbnail renditions - start");
            Folder node = root;
            Stack<Folder> stack = new Stack<Folder>();
            while (node != null) {
                children = node.getChildren();
                for (CmisObject o : children) {
                    if ((o.getType().isBaseType() && o.getType().getId().equals("cmis:folder"))
                            || o.getBaseType().getId().equals("cmis:folder")) {
                        stack.push((Folder) o);
                    } else {
                        OperationContext context = session.createOperationContext();
                        context.setRenditionFilterString("cmis:thumbnail");
                        CmisObject oo = session.getObject(o.getId(), context);
                        List<Rendition> rl = oo.getRenditions();
                        if (!rl.isEmpty()) {
                            System.out.println("found  " + o.getName() + " of type "
                                    + o.getType().getDisplayName() + "that has renditions...");
View Full Code Here

        }
        return result;
    }

    public ItemIterable<QueryResult> executeQuery(String query) {
        OperationContext operationContext = session.createOperationContext();
        operationContext.setMaxItemsPerPage(pageSize);
        return session.query(query, false, operationContext);
    }
View Full Code Here

    int processFolderRecursively(Folder folder) throws Exception {
        processFolderNode(folder);

       
        OperationContext operationContext = cmisConsumer.createOperationContext();
        operationContext.setMaxItemsPerPage(pageSize);

        int count = 0;
        int pageNumber = 0;
        boolean finished = false;
        ItemIterable<CmisObject> itemIterable = folder.getChildren(operationContext);
View Full Code Here

        }
        return result;
    }

    public ItemIterable<QueryResult> executeQuery(String query) {
        OperationContext operationContext = session.createOperationContext();
        operationContext.setMaxItemsPerPage(pageSize);
        return session.query(query, false, operationContext);
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.client.api.OperationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.