Search in sources :

Example 66 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-repository by Alfresco.

the class OpenCmisLocalTest method testALF10085.

public void testALF10085() throws InterruptedException {
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    Document doc1 = rootFolder.createDocument(props, null, null);
    props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    Document doc2 = rootFolder.createDocument(props, null, null);
    Thread.sleep(6000);
    session.getObject(doc1);
    doc1.refresh();
    Calendar doc1LastModifiedBefore = (Calendar) doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc1LastModifiedBefore);
    doc2.refresh();
    Calendar doc2LastModifiedBefore = (Calendar) doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc2LastModifiedBefore);
    // Add relationship A to B
    props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "R:cmiscustom:assoc");
        props.put(PropertyIds.NAME, "A Relationship");
        props.put(PropertyIds.SOURCE_ID, doc1.getId());
        props.put(PropertyIds.TARGET_ID, doc2.getId());
    }
    session.createRelationship(props);
    doc1.refresh();
    Calendar doc1LastModifiedAfter = (Calendar) doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc1LastModifiedAfter);
    doc2.refresh();
    Calendar doc2LastModifiedAfter = (Calendar) doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc2LastModifiedAfter);
    assertEquals(doc1LastModifiedBefore, doc1LastModifiedAfter);
    assertEquals(doc2LastModifiedBefore, doc2LastModifiedAfter);
}
Also used : Repository(org.apache.chemistry.opencmis.client.api.Repository) HashMap(java.util.HashMap) Calendar(java.util.Calendar) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 67 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-repository by Alfresco.

the class OpenCmisLocalTest method testEncodingForCreateContentStream.

public void testEncodingForCreateContentStream() {
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    FileFolderService ffs = serviceRegistry.getFileFolderService();
    // Authenticate as system
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
    authenticationComponent.setSystemUserAsCurrentUser();
    try {
        /* Create the document using openCmis services */
        Repository repository = getRepository("admin", "admin");
        Session session = repository.createSession();
        Folder rootFolder = session.getRootFolder();
        Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session);
        ContentStream content = document.getContentStream();
        assertNotNull(content);
        content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
        assertNotNull(content);
        NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId());
        FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef);
        Map<QName, Serializable> properties = fileInfo.getProperties();
        ContentDataWithId contentData = (ContentDataWithId) properties.get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content"));
        String encoding = contentData.getEncoding();
        assertEquals("ISO-8859-1", encoding);
    } finally {
        authenticationComponent.clearCurrentSecurityContext();
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentDataWithId(org.alfresco.repo.domain.node.ContentDataWithId) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.apache.chemistry.opencmis.client.api.Repository) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) AuthenticationComponent(org.alfresco.repo.security.authentication.AuthenticationComponent) FileInfo(org.alfresco.service.cmr.model.FileInfo) ServiceRegistry(org.alfresco.service.ServiceRegistry) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 68 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-repository by Alfresco.

the class OpenCmisLocalTest method testDownloadEvent.

public void testDownloadEvent() throws InterruptedException {
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    String docname = "mydoc-" + GUID.generate() + ".txt";
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, docname);
    }
    // content
    byte[] byteContent = "Hello from Download testing class".getBytes();
    InputStream stream = new ByteArrayInputStream(byteContent);
    ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream);
    Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR);
    NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
    ContentStream content = doc1.getContentStream();
    assertNotNull(content);
    // range request
    content = doc1.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
    assertNotNull(content);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.apache.chemistry.opencmis.client.api.Repository) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 69 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project SearchServices by Alfresco.

the class CMISDataCreatorTest method testQueryForMultipleDocumentProperties.

public void testQueryForMultipleDocumentProperties() throws Exception {
    Session session = getSession("admin", "admin");
    String folderName = getRootFolderName();
    Folder root = session.getRootFolder();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderName);
    // create the folder
    Folder newFolder = root.createFolder(properties);
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
    assertEquals(1, result.getTotalNumItems());
    Document document1 = createUniqueDocument(newFolder);
    Document document2 = createUniqueDocument(newFolder);
    // result = session.query("SELECT * FROM cmis:folder d join sys:hidden t on  d.cmis:objectId = t.cmis:objectId", false);
    // assertTrue(0 < result.getTotalNumItems());
    // result = session.query("SELECT * FROM cmis:folder d join sys:hidden t on  d.cmis:objectId = t.cmis:objectId where t.sys:cascadeHidden = false", false);
    // assertTrue(0 < result.getTotalNumItems());
    result = session.query("SELECT * FROM cmis:document d join exif:exif t on  d.cmis:objectId = t.cmis:objectId", false);
    long count = result.getTotalNumItems();
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("exif:focalLength", 10.33d);
    ArrayList<String> aspects = new ArrayList<String>();
    aspects.add("P:exif:exif");
    props.put("cmis:secondaryObjectTypeIds", aspects);
    document1.updateProperties(props);
    result = session.query("SELECT * FROM cmis:document d join exif:exif t on  d.cmis:objectId = t.cmis:objectId", false);
    assertEquals(count + 1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + document1.getName() + "' OR  cmis:name = '" + document2.getName() + "'", false);
    assertEquals(2, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + document1.getName() + "' AND cmis:contentStreamLength = 5 AND cmis:contentStreamMimeType = 'text/plain'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("SELECT * FROM cmis:document", false);
    long docCount = result.getTotalNumItems();
    result = session.query("SELECT * FROM cmis:document d left outer join exif:exif t on  d.cmis:objectId = t.cmis:objectId", false);
    assertEquals(docCount, result.getTotalNumItems());
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 70 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project SearchServices by Alfresco.

the class CMISDataCreatorTest method testQueryDocumentProperties.

public void testQueryDocumentProperties() throws Exception {
    Session session = getSession("admin", "admin");
    String folderName = getRootFolderName();
    Folder root = session.getRootFolder();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderName);
    // create the folder
    Folder newFolder = root.createFolder(properties);
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
    assertEquals(1, result.getTotalNumItems());
    Document uniqueDocument = createUniqueDocument(newFolder);
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND IN_FOLDER('" + newFolder.getId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where IN_FOLDER('" + newFolder.getId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:createdBy = '" + uniqueDocument.getCreatedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:objectId = '" + uniqueDocument.getId() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:lastModifiedBy = '" + uniqueDocument.getLastModifiedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String creationDate = ISO8601DateFormat.format(uniqueDocument.getCreationDate().getTime());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:creationDate = '" + creationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String modificationDate = ISO8601DateFormat.format(uniqueDocument.getLastModificationDate().getTime());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:lastModificationDate = '" + modificationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:objectTypeId = '" + uniqueDocument.getType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:baseTypeId = '" + uniqueDocument.getBaseType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamFileName = '" + uniqueDocument.getContentStreamFileName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamLength = '" + uniqueDocument.getContentStreamLength() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamMimeType = '" + uniqueDocument.getContentStreamMimeType() + "'", false);
    assertEquals(1, result.getTotalNumItems());
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) HashMap(java.util.HashMap) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session)

Aggregations

Document (org.apache.chemistry.opencmis.client.api.Document)110 Folder (org.apache.chemistry.opencmis.client.api.Folder)64 HashMap (java.util.HashMap)43 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)43 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)40 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)37 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)32 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)29 ByteArrayInputStream (java.io.ByteArrayInputStream)27 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)25 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)23 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)21 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)20 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 ArrayList (java.util.ArrayList)19 Session (org.apache.chemistry.opencmis.client.api.Session)19 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)19 Test (org.junit.Test)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17