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

The following examples show how to use org.apache.chemistry.opencmis.client.api.Session#getObjectByPath() . 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: AbstractE2EFunctionalTest.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
private FileModel getCustomModel(String fileName)
{
    FileModel customModel = null;

    try
    {
        if ((fileName != null) && (fileName.endsWith("-model.xml")))

        {
            Session session = contentService.getCMISSession(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword());

            CmisObject modelInRepo = session.getObjectByPath(String.format("/Data Dictionary/Models/%s", fileName));

            if (modelInRepo != null)
            {
                customModel = new FileModel(modelInRepo.getName());
                customModel.setNodeRef(modelInRepo.getId());
                customModel.setNodeRef(customModel.getNodeRefWithoutVersion());
                customModel.setCmisLocation(String.format("/Data Dictionary/Models/%s", fileName));
                LOGGER.info("Custom Model file: " + customModel.getCmisLocation());
            }
            else
            {
                LOGGER.info("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
            }
        }
    }
    catch (Exception e)
    {
        LOGGER.warn("Error Getting Custom Model: " + fileName, e);
    }

    return customModel;
}
 
Example 2
Source File: CmisServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
@HasPermission(type = DefaultPermission.class, action = "clone_content_cmis")
public void cloneContent(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, String cmisRepoId, String cmisPath,
                         @ProtectedResourceId(PATH_RESOURCE_ID) String studioPath)
        throws StudioPathNotFoundException, CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException, CmisPathNotFoundException, ServiceLayerException {
    if (!contentService.contentExists(siteId, studioPath))
        throw new StudioPathNotFoundException("Studio repository path does not exist for site " + siteId +
                " (path: " + studioPath + ")");
    List<CmisContentItemTO> toRet = new ArrayList<CmisContentItemTO>();
    DataSourceRepository repositoryConfig = getConfiguration(siteId, cmisRepoId);
    if (repositoryConfig != null) {
        logger.debug("Create new CMIS session");
        Session session = createCMISSession(repositoryConfig);
        if (session != null) {
            String contentPath = Paths.get(repositoryConfig.getBasePath(), cmisPath).toString();
            logger.debug("Find object for CMIS path: " + contentPath);
            CmisObject cmisObject = session.getObjectByPath(contentPath);
            if (cmisObject != null) {
                if (BaseTypeId.CMIS_FOLDER.equals(cmisObject.getBaseTypeId())) {
                    throw new CmisPathNotFoundException();
                } else if (CMIS_DOCUMENT.equals(cmisObject.getBaseTypeId())) {
                    org.apache.chemistry.opencmis.client.api.Document cmisDoc =
                            (org.apache.chemistry.opencmis.client.api.Document)cmisObject;
                    String fileName = cmisDoc.getName();
                    String savePath = studioPath + FILE_SEPARATOR + fileName;
                    ContentStream cs = cmisDoc.getContentStream();
                    logger.debug("Save CMIS file to: " + savePath);
                    contentService.writeContent(siteId, savePath, cs.getStream());
                }
            } else {
                throw new CmisPathNotFoundException();
            }
        } else {
            throw new CmisUnauthorizedException();
        }
    }
}
 
Example 3
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
        public void run()
        {
            Session session = getSession(""+id+id+id, ""+id+id+id);
            
            CmisObject object = session.getObjectByPath(path);
            
            Map<String, Object> baseProps = new HashMap<String, Object>();
            baseProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
            baseProps.put(PropertyIds.NAME, "Thread"+id);
            
            
            ObjectId base = session.createFolder(baseProps, object);

            for(int i = 0; i < 100; i++)
            {
                    
                Map<String, Object> properties = new HashMap<String, Object>();
                properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
                properties.put(PropertyIds.NAME, "Folder-"+i);
                
                ObjectId folder = session.createFolder(properties, base);
               
                System.out.println("Thread "+id +"   @Folder "+i);
                
                for(int j = 0; j < 1000; j++)
                {
                    Map<String, Object> folderProps = new HashMap<String, Object>();
                    folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
                    folderProps.put(PropertyIds.NAME, "Folder-"+i);
                    
                    ObjectId child = session.createFolder(folderProps, folder);
                    
                    
//                    Map<String, Object> docProps = new HashMap<String, Object>();
//                    docProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
//                    docProps.put(PropertyIds.NAME, "Doc-"+j);
//                    
//                    ContentStreamImpl contentSream = new ContentStreamImpl();
//                    contentSream.setFileName(GUID.generate());
//                    contentSream.setLength(BigInteger.valueOf(10));
//                    contentSream.setMimeType("text/plain");
//                    contentSream.setStream(new StringInputStream("abcdefghij"));
//                    
//                     ObjectId document = session.createDocument(docProps, folder, contentSream, VersioningState.MAJOR);
                    
                    if(j % 20 == 0)
                    {
                        System.out.println(id+"    @ "+j);
                    }
                }
            }
            
        }
 
Example 4
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 = "list_cmis")
public List<CmisContentItem> list(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId,
                                  String cmisRepo, String path)
        throws CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException {
    List<CmisContentItem> items = 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())) {
                    Folder folder = (Folder)cmisObject;
                    Iterable<CmisObject> iterable = folder.getChildren();
                    Iterator<CmisObject> iterator = iterable.iterator();
                    while (iterator.hasNext()) {
                        CmisContentItem item = new CmisContentItem();
                        CmisObject cmisItem = iterator.next();
                        item.setItemName(cmisItem.getName());
                        if (CMIS_DOCUMENT.equals(cmisItem.getBaseTypeId())) {
                            org.apache.chemistry.opencmis.client.api.Document cmisDoc =
                                    (org.apache.chemistry.opencmis.client.api.Document)cmisItem;
                            item.setItemPath(cmisDoc.getPaths().get(0));
                            item.setMimeType(cmisDoc.getContentStreamMimeType());
                            String contentId = cmisDoc.getId();
                            StringTokenizer st = new StringTokenizer(contentId, ";");
                            if (st.hasMoreTokens()) {
                                item.setItemId(st.nextToken());
                            }
                            item.setSize(cmisDoc.getContentStreamLength());
                            items.add(item);
                        } else if (CMIS_FOLDER.equals(cmisItem.getBaseTypeId())) {
                            Folder cmisFolder = (Folder)cmisItem;
                            item.setItemId(cmisFolder.getId());
                            item.setItemPath(cmisFolder.getPath());
                            item.setMimeType(MIME_TYPE_FOLDER);
                            item.setSize(-1);
                            items.add(item);
                        }
                    }
                }
            }
        }
    }
    return items;
}
 
Example 5
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;
}