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

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


import org.junit.Test;

public abstract class AbstractTransientObjectIT extends AbstractSessionTest {
  @Test
  public void transientUpdate() throws Exception {
    ObjectId parentId = this.session.createObjectId(this.fixture
        .getTestRootId());
    String filename1 = UUID.randomUUID().toString();
    String typeId = FixtureData.DOCUMENT_TYPE_ID.value();

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

    String mimetype = "text/html; charset=UTF-8";
    String content1 = "Im Walde rauscht ein Wasserfall. Wenn's nicht mehr rauscht ist's Wasser all.";

    byte[] buf1 = content1.getBytes("UTF-8");
    ByteArrayInputStream in1 = new ByteArrayInputStream(buf1);
    ContentStream contentStream1 = this.session.getObjectFactory()
        .createContentStream(filename1, buf1.length, mimetype, in1);
    assertNotNull(contentStream1);

    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();

    assertEquals(filename1, tdoc2.getName());

    ContentStream cs2 = tdoc2.getContentStream();
    assertNotNull(cs2);
    assertContent(buf1, readContent(cs2));

    String filename2 = UUID.randomUUID().toString();
    tdoc2.setName(filename2);
    assertEquals(filename2, tdoc2.getName());

    ObjectId id2 = tdoc2.save();
    assertNotNull(id2);

    // set new content and save
    Document doc3 = (Document) this.session.getObject(id2, oc);
    TransientDocument tdoc3 = doc3.getTransientDocument();

    assertEquals(filename2, tdoc3.getName());

    ContentStream cs3 = tdoc3.getContentStream();
    assertNotNull(cs3);
    assertContent(buf1, readContent(cs3));

    String content3 = "Es rauscht noch.";

    byte[] buf3 = content3.getBytes("UTF-8");
    ByteArrayInputStream in3 = new ByteArrayInputStream(buf3);
    ContentStream contentStream3 = this.session.getObjectFactory()
        .createContentStream(tdoc3.getName(), buf3.length, mimetype,
            in3);
    assertNotNull(contentStream3);

    tdoc3.setContentStream(contentStream3, true);

    ObjectId id3 = tdoc3.save();
    assertNotNull(id3);

    // set new name, delete content and save
    Document doc4 = (Document) this.session.getObject(id3, oc);
    TransientDocument tdoc4 = doc4.getTransientDocument();

    assertEquals(tdoc3.getName(), tdoc4.getName());

    ContentStream cs4 = tdoc4.getContentStream();
    assertNotNull(cs4);
    assertContent(buf3, readContent(cs4));

    String filename4 = UUID.randomUUID().toString();
    tdoc4.setName(filename4);
    assertEquals(filename4, tdoc4.getName());

    tdoc4.deleteContentStream();

    ObjectId id4 = tdoc4.save();
    assertNotNull(id4);

    // delete object
    Document doc5 = (Document) this.session.getObject(id4, oc);
    TransientDocument tdoc5 = doc5.getTransientDocument();

    assertEquals(filename4, tdoc5.getName());

    ContentStream cs5 = tdoc4.getContentStream();
    assertNull(cs5);

    assertEquals(false, tdoc5.isMarkedForDelete());

    tdoc5.delete(true);

    assertEquals(true, tdoc5.isMarkedForDelete());

    ObjectId id5 = tdoc5.save();
    assertNull(id5);

    // check
    try {
      this.session.getObject(id4, oc);
View Full Code Here


    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

    assertEquals(tdoc.getProperty(PropertyIds.NAME).getValueAsString(), newDocName);
   
    tdoc.save();
    session2.clear();

    ObjectId id = this.session2.createObjectId(tdoc.getId());
       
    Document doc3 = (Document) this.session2.getObject(id);
    assertNotNull(doc3);
    assertEquals(doc3.getProperty(PropertyIds.NAME).getValueAsString(), newDocName);
  }
View Full Code Here

    public Document createDocument(Map<String, ?> properties, ContentStream contentStream,
            VersioningState versioningState, List<Policy> policies, List<Ace> addAces, List<Ace> removeAces,
            OperationContext context) {

        ObjectId newId = getSession().createDocument(properties, this, contentStream, versioningState, policies,
                addAces, removeAces);

        // if no context is provided the object will not be fetched
        if ((context == null) || (newId == null)) {
            return null;
View Full Code Here

    public Document createDocumentFromSource(ObjectId source, Map<String, ?> properties,
            VersioningState versioningState, List<Policy> policies, List<Ace> addAces, List<Ace> removeAces,
            OperationContext context) {

        ObjectId newId = getSession().createDocumentFromSource(source, properties, this, versioningState, policies,
                addAces, removeAces);

        // if no context is provided the object will not be fetched
        if ((context == null) || (newId == null)) {
            return null;
View Full Code Here

    }

    public Folder createFolder(Map<String, ?> properties, List<Policy> policies, List<Ace> addAces,
            List<Ace> removeAces, OperationContext context) {

        ObjectId newId = getSession().createFolder(properties, this, policies, addAces, removeAces);

        // if no context is provided the object will not be fetched
        if ((context == null) || (newId == null)) {
            return null;
        }
View Full Code Here

    }

    public Policy createPolicy(Map<String, ?> properties, List<Policy> policies, List<Ace> addAces,
            List<Ace> removeAces, OperationContext context) {

        ObjectId newId = getSession().createPolicy(properties, this, policies, addAces, removeAces);

        // if no context is provided the object will not be fetched
        if ((context == null) || (newId == null)) {
            return null;
        }
View Full Code Here

        // 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,
                FixtureData.FOLDER_TYPE_ID.value());
        ObjectId folderId = session.createFolder(properties, testRoot);
        assertNotNull(folderId);

        // get the document
        String pathd = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
                + FixtureData.DOCUMENT1_NAME;
        Document document = (Document) session.getObjectByPath(pathd);

        // copy the document
        properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, "newdocname");
        Document copy = document.copy(folderId, properties, null, null, null, null, session.getDefaultContext());

        assertEquals(folderId.getId(), copy.getParents().get(0).getId());
        assertEquals("newdocname", copy.getPropertyValue(PropertyIds.NAME));

        // old doc still unchanged
        session.clear();
        document = (Document) session.getObjectByPath(pathd);
View Full Code Here

        // 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");
View Full Code Here

            if (properties.isEmpty()) {
                return false;
            }

            ObjectId newId = object.updateProperties(properties, false);

            if ((newId != null) && newId.getId().equals(model.getCurrentObject().getId())) {
                try {
                    model.reloadObject();
                    model.reloadFolder();
                } catch (Exception ex) {
                    ClientHelper.showError(null, ex);
View Full Code Here

TOP

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

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.