Java Code Examples for org.apache.chemistry.opencmis.client.api.Session#getObject()

The following examples show how to use org.apache.chemistry.opencmis.client.api.Session#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public FolderNode getDescendants(String folderId, int depth)
{
    Session session = getCMISSession();

    CmisObject o = session.getObject(folderId);
    if(o instanceof Folder)
    {
        Folder f = (Folder)o;

        OperationContextImpl ctx = new OperationContextImpl();
        List<Tree<FileableCmisObject>> res = f.getDescendants(depth, ctx);
        FolderNode ret = (FolderNode)CMISNode.createNode(f);
        for(Tree<FileableCmisObject> t : res)
        {
            addChildren(ret, t);
        }

        return ret;
    }
    else
    {
        throw new IllegalArgumentException("Folder does not exist or is not a folder");
    }
}
 
Example 2
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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);
}
 
Example 3
Source File: CmisServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
@HasPermission(type = DefaultPermission.class, action = "search_cmis")
public List<CmisContentItem> search(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, String cmisRepo,
                                    String searchTerm, String path)
        throws CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException {
    List<CmisContentItem> toRet = new ArrayList<CmisContentItem>();
    DataSourceRepository repositoryConfig = getConfiguration(siteId, cmisRepo);
    if (repositoryConfig != null) {
        Session session = createCMISSession(repositoryConfig);
        if (session != null) {
            String contentPath = Paths.get(repositoryConfig.getBasePath(), path).toString();
            CmisObject cmisObject = session.getObjectByPath(contentPath);
            if (cmisObject != null) {
                if (CMIS_FOLDER.equals(cmisObject.getBaseTypeId())) {
                    String queryString = CMIS_SEARCH_QUERY.replace(CMIS_SEARCH_QUERY_FOLDER_ID_VARIABLE,
                            cmisObject.getId()).replace(CMIS_SEARCH_QUERY_SEARCH_TERM_VARIABLE, searchTerm);
                    ItemIterable<QueryResult> result = session.query(queryString, false);
                    Iterator<QueryResult> iterator = result.iterator();
                    int count = 0;
                    while (iterator.hasNext()) {
                        CmisContentItem item = new CmisContentItem();
                        QueryResult qr = iterator.next();

                        String contentId = qr.getPropertyById(OBJECT_ID).getFirstValue().toString();
                        StringTokenizer st = new StringTokenizer(contentId, ";");
                        if (st.hasMoreTokens()) {
                            item.setItemId(st.nextToken());
                        }
                        CmisObject qrObject = session.getObject(item.getItemId());
                        org.apache.chemistry.opencmis.client.api.Document cmisDoc =
                                (org.apache.chemistry.opencmis.client.api.Document)qrObject;
                        item.setItemName(cmisDoc.getName());
                        item.setItemPath(cmisDoc.getPaths().get(0));
                        item.setMimeType(cmisDoc.getContentStreamMimeType());
                        item.setSize(cmisDoc.getContentStreamLength());
                        toRet.add(item);
                    }
                }
            }
        }
    }
    return toRet;
}
 
Example 4
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
private CmisObject retrieveCMISObjectByIdFromServer(String nodeId) throws Exception {
    Session session = createSession();
    return session.getObject(nodeId);
}