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

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


    try
    {
      cmisClientSession = getCmisClientSession();

      //creating a new folder
      Folder root = cmisClientSession.getRootFolder();
     
      ItemIterable<QueryResult> results = cmisClientSession.query(CMIS_TEST_QUERY, false);
      for (QueryResult result : results) {
         String repositoryId = cmisClientSession.getRepositoryInfo().getId();
        String folderId = result.getPropertyById("cmis:objectId").getFirstValue().toString();
        cmisClientSession.getBinding().getObjectService().deleteTree(repositoryId, folderId, true, null, false, null);
      }

      Map<String, Object> folderProperties = new HashMap<String, Object>();
      folderProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
      folderProperties.put(PropertyIds.NAME, "testdata");
 
      Folder newFolder = root.createFolder(folderProperties);

      String name = "testdata1.txt";
      createNewDocument(newFolder, name);
     
      name = "testdata2.txt";
View Full Code Here


      count = getJobDocumentsProcessed(jobIDString);
      if (count != 3)
        throw new ManifoldCFException("Wrong number of documents processed - expected 3, saw "+new Long(count).toString());
     
      // Add a file and recrawl
      Folder testFolder = getTestFolder(cmisClientSession);
      createNewDocument(testFolder, "testdata3.txt");
      createNewDocument(testFolder, "testdata4.txt");

      // Now, start the job, and wait until it completes.
      startJob(jobIDString);
View Full Code Here

  }

  @Test
  public void transientFolderSessionCheck() throws UnsupportedEncodingException {
      String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.FOLDER1_NAME;
    Folder folder1 = (Folder) this.session.getObjectByPath(path);
    assertNotNull("folder not found: " + path, folder1);

    TransientFolder tfolder = folder1.getTransientFolder();
    assertNotNull(tfolder);

    String newFolderName = UUID.randomUUID().toString();
    tfolder.setPropertyValue(PropertyIds.NAME, newFolderName);
   
    Folder folder2 = (Folder) this.session2.getObjectByPath(path);
    assertNotNull(folder2);
    assertEquals(folder2.getProperty(PropertyIds.NAME).getValueAsString(), FixtureData.FOLDER1_NAME.toString());
    assertEquals(tfolder.getProperty(PropertyIds.NAME).getValueAsString(), newFolderName);
   
    tfolder.save();
    session2.clear();

    ObjectId id = this.session2.createObjectId(tfolder.getId());
   
    Folder folder3 = (Folder) this.session2.getObject(id);
    assertNotNull(folder3);
    assertEquals(folder3.getProperty(PropertyIds.NAME).getValueAsString(), newFolderName);
  }
View Full Code Here

public abstract class AbstractWriteObjectCopyIT extends AbstractSessionTest {

    @Test
    public void copyDocument() {
        String pathr = "/" + Fixture.TEST_ROOT_FOLDER_NAME;
        Folder testRoot = (Folder) this.session.getObjectByPath(pathr);

        // create a folder to copy into
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, "newfolder");
        properties.put(PropertyIds.OBJECT_TYPE_ID,
View Full Code Here

    model.addFolderListener(this);
    createGUI();
  }

  public void folderLoaded(ClientModelEvent event) {
    Folder currentFolder = event.getClientModel().getCurrentFolder();

    if (currentFolder != null) {
      String path = currentFolder.getPath();
      pathField.setText(path);

      Folder parent = currentFolder.getFolderParent();
      if (parent == null) {
        parentId = null;
        upButton.setEnabled(false);
      } else {
        parentId = parent.getId();
        upButton.setEnabled(true);
      }
    } else {
      pathField.setText("???");
      parentId = null;
View Full Code Here

        success = createResult(OK, "Root folder id: " + ri.getRootFolderId());
        failure = createResult(FAILURE, "Root folder id is not set!");
        addResult(assertStringNotEmpty(ri.getRootFolderId(), success, failure));

        // get the root folder
        Folder rootFolder = session.getRootFolder();

        if (rootFolder == null) {
            addResult(createResult(FAILURE, "Root folder is not available!"));
            return;
        }

        String[] propertiesToCheck = new String[rootFolder.getType().getPropertyDefinitions().size()];

        int i = 0;
        for (String propId : rootFolder.getType().getPropertyDefinitions().keySet()) {
            propertiesToCheck[i++] = propId;
        }

        addResult(checkObject(rootFolder, propertiesToCheck, "Root folder object spec compliance"));

        // folder and path
        failure = createResult(FAILURE,
                "Root folder id in the repository info doesn't match the root folder object id!");
        addResult(assertEquals(ri.getRootFolderId(), rootFolder.getId(), null, failure));

        failure = createResult(FAILURE, "Root folder is not a cmis:folder!");
        addResult(assertEquals(BaseTypeId.CMIS_FOLDER, rootFolder.getBaseTypeId(), null, failure));

        failure = createResult(FAILURE, "Root folder path is not '/'!");
        addResult(assertEquals("/", rootFolder.getPath(), null, failure));

        failure = createResult(FAILURE, "Root folder has parents!");
        addResult(assertEquals(0, rootFolder.getParents().size(), null, failure));

        // allowable actions
        failure = createResult(FAILURE, "Root folder has CAN_GET_FOLDER_PARENT allowable action!");
        addResult(assertNotAllowableAction(rootFolder, Action.CAN_GET_FOLDER_PARENT, null, failure));
View Full Code Here

    /**
     * Creates a folder.
     */
    protected Folder createFolder(Folder parent, String name, String objectTypeId) {
        Folder result = null;

        CmisTestResult f;

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);

        try {
            // create the folder
            result = parent.createFolder(properties);
        } catch (CmisBaseException e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not be created! Exception: " + e.getMessage(),
                    e, true));
        }

        try {
            // check the new folder
            String[] propertiesToCheck = new String[result.getType().getPropertyDefinitions().size()];

            int i = 0;
            for (String propId : result.getType().getPropertyDefinitions().keySet()) {
                propertiesToCheck[i++] = propId;
            }

            addResult(checkObject(result, propertiesToCheck, "New folder object spec compliance"));

            // check object parents
            List<Folder> objectParents = result.getParents();

            f = createResult(FAILURE, "Newly created folder has no or more than one parent! Id: " + result.getId(),
                    true);
            addResult(assertEquals(1, objectParents.size(), null, f));

            f = createResult(FAILURE, "First object parent of the newly created folder does not match parent! Id: "
                    + result.getId(), true);
            assertShallowEquals(parent, objectParents.get(0), null, f);

            // check folder parent
            Folder folderParent = result.getFolderParent();
            f = createResult(FAILURE, "Newly created folder has no folder parent! Id: " + result.getId(), true);
            addResult(assertNotNull(folderParent, null, f));

            f = createResult(FAILURE,
                    "Folder parent of the newly created folder does not match parent! Id: " + result.getId(), true);
View Full Code Here

            testFolderParentPath = TestParameters.DEFAULT_TEST_FOLDER_PARENT_VALUE;
        }

        String name = "cmistck" + System.currentTimeMillis() + session.getRepositoryInfo().hashCode();

        Folder parent = null;
        try {
            CmisObject parentObject = session.getObjectByPath(testFolderParentPath);
            if (!(parentObject instanceof Folder)) {
                addResult(createResult(FAILURE, "Parent folder of the test folder is actually not a folder! Path: "
                        + testFolderParentPath, true));
View Full Code Here

        // Remove anything that was created by a previous run of this program
        cleanup(session);

        // Get everything in the root folder and print the names of the objects
        Folder root = session.getRootFolder();
        ItemIterable<CmisObject> children = root.getChildren();
        System.out.println("Found the following objects in the root folder:-");
        for (CmisObject o : children) {
            System.out.println(o.getName() + " which is of type " + o.getType().getDisplayName());
        }

        System.out.println("\nFile and Folders...");
        System.out.println("-------------------");

        // Add a new folder to the root folder
        System.out.println("Creating 'ADGNewFolder' in the root folder");
        Map<String, String> newFolderProps = new HashMap<String, String>();
        newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        newFolderProps.put(PropertyIds.NAME, "ADGNewFolder");
        Folder newFolder = root.createFolder(newFolderProps);

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

        // Create a simple text document in the new folder
        // First, create the content stream
        final String textFileName = "test.txt";
        System.out.println("creating a simple text document, " + textFileName);
        String mimetype = "text/plain; charset=UTF-8";
        String content = "This is some test content.";
        String filename = textFileName;

        byte[] buf = null;
        try {
            buf = content.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ByteArrayInputStream input = new ByteArrayInputStream(buf);
        ContentStream contentStream = session.getObjectFactory().createContentStream(filename,
                buf.length, mimetype, input);

        // Create the Document Object
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        properties.put(PropertyIds.NAME, filename);
        ObjectId id = newFolder.createDocument(properties, contentStream, VersioningState.NONE);

        // Did it work?
        // Get the contents of the document by id
        Document doc = (Document) session.getObject(id);
        try {
            content = getContentAsString(doc.getContentStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
       
        // Get the contents of the document by path
        String path = newFolder.getPath() + "/" + textFileName;
        System.out.println("Getting object by path " + path);
        doc = (Document) session.getObjectByPath(path);
        try {
            content = getContentAsString(doc.getContentStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("Contents of " + doc.getName() + " are: " + content);
       

        // Create Document Object with no content stream
        System.out.println("creating a document  called testNoContent with no ContentStream");
        properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        properties.put(PropertyIds.NAME, "testNoContent");
        newFolder.createDocument(properties, null, VersioningState.NONE);

        // Create a new document and then update its name
        final String textFileName2 = "test2.txt";
        System.out.println("creating a simple text document, " + textFileName2);
        mimetype = "text/plain; charset=UTF-8";
        content = "This is some test content for our second document.";
        filename = textFileName2;

        buf = null;
        try {
            buf = content.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        input = new ByteArrayInputStream(buf);
        contentStream = session.getObjectFactory().createContentStream(filename, buf.length,
                mimetype, input);
        properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        properties.put(PropertyIds.NAME, filename);
        ObjectId id2 = newFolder.createDocument(properties, contentStream, VersioningState.NONE);

        Document doc2 = (Document) session.getObject(id2);
        System.out.println("renaming " + doc2.getName() + " to test3.txt");
        properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, "test3.txt");
        id2 = doc2.updateProperties(properties);
        System.out.println("renamed to " + doc2.getName());

        // Update the content stream
        content = "This is some updated test content for our renamed second document.";
        buf = null;
        try {
            buf = content.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        input = new ByteArrayInputStream(buf);
        contentStream = session.getObjectFactory().createContentStream("test3.txt", buf.length,
                mimetype, input);
        properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        properties.put(PropertyIds.NAME, "test3.txt");
        doc2.setContentStream(contentStream, true);

        // did it work?
        try {
            content = getContentAsString(doc2.getContentStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Contents of " + doc2.getName() + " are: " + content);

        // Force and handle a CmisInvalidArgumentException exception
        System.out.println("\nExceptions...");
        System.out.println("-------------");
        System.out.println("Forcing and handling a CmisInvalidArgumentException");
        try {
            doc2.setContentStream(null, false);
        } catch (CmisInvalidArgumentException e1) {
            System.out.println("caught an " + e1.getClass().getName() + " exception with message "
                    + e1.getMessage());
        }

        // delete a document
        System.out.println("\nMore files and folders...");
        System.out.println("-------------------------");
        children = newFolder.getChildren();
        System.out.println("Now finding the following objects in our folder:-");
        for (CmisObject o : children) {
            System.out.println(o.getName());
        }
        System.out.println("Deleting document " + doc2.getName());
        doc2.delete(true);
        System.out.println("Now finding the following objects in our folder:-");
        for (CmisObject o : children) {
            System.out.println(o.getName());
        }

        // Create a new folder tree, and delete it
        System.out.println("Creating 'ADGFolder1' in the root folder");
        newFolderProps = new HashMap<String, String>();
        newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        newFolderProps.put(PropertyIds.NAME, "ADGFolder1");
        Folder folder1 = root.createFolder(newFolderProps);
        newFolderProps.put(PropertyIds.NAME, "ADGFolder11");
        Folder folder11 = folder1.createFolder(newFolderProps);
        newFolderProps.put(PropertyIds.NAME, "ADGFolder12");
        Folder folder12 = folder1.createFolder(newFolderProps);
        System.out.println("delete the 'ADGFolder1' tree");
        folder1.deleteTree(true, UnfileObject.DELETE, true);

        // Create a folder tree to navigate through
        System.out.println("Creating folder tree for navigation");
        newFolderProps = new HashMap<String, String>();
        HashMap<String, String> newFileProps = new HashMap<String, String>();

        newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        newFolderProps.put(PropertyIds.NAME, "ADGFolder1");
        folder1 = root.createFolder(newFolderProps);

        newFileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        newFileProps.put(PropertyIds.NAME, "ADGFile1f1");
        folder1.createDocument(newFileProps, contentStream, VersioningState.NONE);

        newFolderProps.put(PropertyIds.NAME, "ADGFolder11");
        folder11 = folder1.createFolder(newFolderProps);

        newFileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        newFileProps.put(PropertyIds.NAME, "ADGFile11f1");
        folder11.createDocument(newFileProps, contentStream, VersioningState.NONE);

        newFileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        newFileProps.put(PropertyIds.NAME, "ADGFile11f2");
        folder11.createDocument(newFileProps, contentStream, VersioningState.NONE);

        newFolderProps.put(PropertyIds.NAME, "ADGFolder111");
        folder11.createFolder(newFolderProps);

        newFolderProps.put(PropertyIds.NAME, "ADGFolder112");
        folder11.createFolder(newFolderProps);

        newFolderProps.put(PropertyIds.NAME, "ADGFolder12");
        folder12 = folder1.createFolder(newFolderProps);

        newFolderProps.put(PropertyIds.NAME, "ADGFolder121");
        Folder folder121 = folder12.createFolder(newFolderProps);

        newFileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        newFileProps.put(PropertyIds.NAME, "ADGFile121f1");
        folder121.createDocument(newFileProps, contentStream, VersioningState.NONE);

        newFolderProps.put(PropertyIds.NAME, "ADGFolder122");
        folder12.createFolder(newFolderProps);

        // Navigating the object tree
        System.out.println("\nNavigating the object tree...");
        System.out.println("-----------------------------");

        // Get the children of folder1
        children = folder1.getChildren();
        System.out.println("Children of " + folder1.getName() + ":-");
        for (CmisObject o : children) {
            System.out.println(o.getName());
        }

        // Get the descendants of folder1
        if (!session.getRepositoryInfo().getCapabilities().isGetDescendantsSupported()) {
            System.out.println("getDescendants not supported in this repository");
        } else {
            System.out.println("Descendants of " + folder1.getName() + ":-");
            for (Tree<FileableCmisObject> t : folder1.getDescendants(-1)) {
                printTree(t);
            }
        }

        // Get the foldertree of folder1
        if (!session.getRepositoryInfo().getCapabilities().isGetFolderTreeSupported()) {
            System.out.println("getFolderTree not supported in this repository");
        } else {
            System.out.println("Foldertree for " + folder1.getName() + ":-");
            for (Tree<FileableCmisObject> t : folder1.getFolderTree(-1)) {
                printFolderTree(t);
            }
        }

        // Paging
        System.out.println("\nPaging...");
        System.out.println("--------");
        System.out.println("Creating folders for paging example");
        newFolderProps = new HashMap<String, String>();
        newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        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 {
View Full Code Here

            VersioningState versioningState, Session session) throws FileNotFoundException {
        if (type == null) {
            type = BaseTypeId.CMIS_DOCUMENT.value(); // "cmis:document";
        }

        Folder parentFolder = getFolder(parentIdOrPath, session);

        String name = file.getName();
        String mimetype = MimeTypes.getMIMEType(file);

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, type);
        properties.put(PropertyIds.NAME, name);

        ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(file.length()), mimetype,
                new FileInputStream(file));

        return parentFolder.createDocument(properties, contentStream, versioningState);
    }
View Full Code Here

TOP

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

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.