org.apache.chemistry.opencmis.client.api.ItemIterable Java Examples
The following examples show how to use
org.apache.chemistry.opencmis.client.api.ItemIterable.
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: FolderNode.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public void checkChildren(ItemIterable<CmisObject> expectedChildren) { Map<String, FolderNode> expectedFolderNodes = new HashMap<String, FolderNode>(); Map<String, CMISNode> expectedDocumentNodes = new HashMap<String, CMISNode>(); for(CmisObject child : expectedChildren) { CMISNode dn = CMISNode.createNode(child); if(dn instanceof FolderNode) { expectedFolderNodes.put(getBareObjectId(dn.getNodeId()), (FolderNode)dn); } else { expectedDocumentNodes.put(getBareObjectId(dn.getNodeId()), dn); } } checkChildrenImpl(expectedFolderNodes, expectedDocumentNodes); }
Example #2
Source File: CmisIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
private void deleteAllContent() { Session session = createSession(); Folder rootFolder = session.getRootFolder(); ItemIterable<CmisObject> children = rootFolder.getChildren(); for (CmisObject cmisObject : children) { if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) { List<String> notDeltedIdList = ((Folder)cmisObject) .deleteTree(true, UnfileObject.DELETE, true); if (notDeltedIdList != null && notDeltedIdList.size() > 0) { throw new RuntimeException("Cannot empty repo"); } } else { cmisObject.delete(true); } } session.getBinding().close(); }
Example #3
Source File: SampleClient.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public static void main1(String[] args) throws IOException { Folder root = connect(); root.getName(); // cleanup(root, TEST_FOLDER_NAME); // Folder newFolder = createFolder(root, TEST_FOLDER_NAME); // createDocument(newFolder, TEST_DOCUMENT_NAME_1); // createDocument(newFolder, TEST_DOCUMENT_NAME_2); // System.out.println("+++ List Folder +++"); // listFolder(0, newFolder); // DeleteDocument(newFolder, "/" + TEST_DOCUMENT_NAME_2); // System.out.println("+++ List Folder +++"); // listFolder(0, newFolder); CmisObject object = session.getObjectByPath(TEST_FOLDER_PATH); System.out.println(object.getId() + " " + object.getName()); // // object = session.getObjectByPath(TEST_FOLDER_NAME + "/" + // TEST_DOCUMENT_NAME_1); // System.out.println(object.getId() + " " + // object.getProperty(TypeManager.PROP_TITLE).getValues().get(0)); // checkoutCheckin(); ItemIterable<QueryResult> result = session .query("SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE ldoc:tags = '12345'", true); for (QueryResult r : result) { System.out.println("result: " + r.getPropertyById("ldoc:tags")); } }
Example #4
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
public void testCreate() { 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); for(int i = 0; i < 50; i++) { AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("user"+i); List<String> permissions = new ArrayList<String>(1); permissions.add(BasicPermissions.READ); List<Ace> addAces = new ArrayList<Ace>(1); addAces.add(new AccessControlEntryImpl(principal, permissions)); newFolder.addAcl(addAces, AclPropagation.PROPAGATE); Map<String, Object> updateProperties = new HashMap<String, Object>(); updateProperties.put("cm:title", "Update title "+i); newFolder.updateProperties(properties); if(i % 10 == 0) { System.out.println("@ "+i); } } ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false); assertTrue(result.getTotalNumItems() > 0); result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false); assertTrue(result.getTotalNumItems() > 0); }
Example #5
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public FolderNode getChildren(String folderId, int skipCount, int maxItems) { CmisObject o = session.getObject(folderId); if(o instanceof Folder) { Folder f = (Folder)o; FolderNode ret = (FolderNode)CMISNode.createNode(f); OperationContextImpl ctx = new OperationContextImpl(); ItemIterable<CmisObject> res = f.getChildren(ctx); res.skipTo(skipCount); ItemIterable<CmisObject> l = res.getPage(maxItems); for(CmisObject c : l) { CMISNode child = null; if(c.getBaseType() instanceof FolderTypeDefinition) { child = (FolderNode)CMISNode.createNode(c); ret.addFolder((FolderNode)child); } else { child = CMISNode.createNode(c); ret.addNode(child); } } return ret; } else { throw new IllegalArgumentException("Folder does not exist or is not a folder"); } }
Example #6
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
public void testCreateLots() throws Exception { Session session = getSession("admin", "admin"); Folder root = session.getRootFolder(); String folderNameBase = getRootFolderName(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); properties.put(PropertyIds.NAME, folderNameBase); Folder base = root.createFolder(properties); for(int i = 0; i < 10; i++) { AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl(""+i+i+i); List<String> permissions = new ArrayList<String>(1); permissions.add(BasicPermissions.ALL); List<Ace> addAces = new ArrayList<Ace>(1); addAces.add(new AccessControlEntryImpl(principal, permissions)); base.addAcl(addAces, AclPropagation.PROPAGATE); } Thread last = null; for(int i = 0; i < 10; i++) { Creator creator = new Creator(base.getPath(), i); Thread thread = new Thread(creator); thread.start(); last = thread; } if(last != null) { last.join(); } ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false); assertTrue(result.getTotalNumItems() > 0); //result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false); //assertTrue(result.getTotalNumItems() > 0); }
Example #7
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
public void testQueryFolderProperties() { 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()); String uniqueName = getUniqueName(); Map<String, Object> uProperties = new HashMap<String, Object>(); uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); uProperties.put(PropertyIds.NAME, uniqueName); Folder uniqueFolder = newFolder.createFolder(uProperties); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"'", false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND IN_FOLDER('"+ uniqueFolder.getParentId() + "')" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where IN_FOLDER('"+ uniqueFolder.getParentId() + "')" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:createdBy = '"+ uniqueFolder.getCreatedBy()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:objectId = '"+ uniqueFolder.getId()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:lastModifiedBy = '"+ uniqueFolder.getLastModifiedBy()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+ uniqueFolder.getName()+"'" , false); assertEquals(1, result.getTotalNumItems()); String creationDate = ISO8601DateFormat.format(uniqueFolder.getCreationDate().getTime()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:creationDate = '"+ creationDate +"'" , false); assertEquals(1, result.getTotalNumItems()); String modificationDate = ISO8601DateFormat.format(uniqueFolder.getLastModificationDate().getTime()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:lastModificationDate = '"+ modificationDate+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:objectTypeId = '"+ uniqueFolder.getType().getQueryName()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:baseTypeId = '"+ uniqueFolder.getBaseType().getQueryName()+"'" , false); assertEquals(1, result.getTotalNumItems()); }
Example #8
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
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()); }
Example #9
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
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()); }
Example #10
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public ItemIterable<ObjectType> getTypeChildren(String typeId, boolean includePropertyDefinitions) { ItemIterable<ObjectType> res = session.getTypeChildren(typeId, includePropertyDefinitions); return res; }
Example #11
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public ItemIterable<Document> getCheckedOutDocs() { OperationContextImpl ctx = new OperationContextImpl(); ItemIterable<Document> res = session.getCheckedOutDocs(ctx); return res; }
Example #12
Source File: CmisServiceImpl.java From studio with GNU General Public License v3.0 | 4 votes |
@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 #13
Source File: CmisSender.java From iaf with Apache License 2.0 | 4 votes |
private String sendMessageForActionFind(String message) throws SenderException, TimeOutException { Element queryElement = null; try { if (XmlUtils.isWellFormed(message, "query")) { queryElement = XmlUtils.buildElement(message); } else { queryElement = XmlUtils.buildElement("<query/>"); } } catch (DomBuilderException e) { throw new SenderException(e); } String statement = XmlUtils.getChildTagAsString(queryElement, "statement"); String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems"); String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount"); String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions"); String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions"); OperationContext operationContext = cmisSession.createOperationContext(); if (StringUtils.isNotEmpty(maxItems)) { operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems)); } boolean sav = false; if (StringUtils.isNotEmpty(searchAllVersions)) { sav = Boolean.parseBoolean(searchAllVersions); } if (StringUtils.isNotEmpty(includeAllowableActions)) { operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions)); } XmlBuilder cmisXml = new XmlBuilder("cmis"); ItemIterable<QueryResult> q = cmisSession.query(statement, sav, operationContext); if(q == null) { cmisXml.addAttribute("totalNumItems", 0); } else { if (StringUtils.isNotEmpty(skipCount)) { long sc = Long.parseLong(skipCount); q = q.skipTo(sc); } if (StringUtils.isNotEmpty(maxItems)) { q = q.getPage(); } XmlBuilder rowsetXml = new XmlBuilder("rowset"); for (QueryResult qResult : q) { XmlBuilder rowXml = new XmlBuilder("row"); for (PropertyData<?> property : qResult.getProperties()) { rowXml.addSubElement(CmisUtils.getPropertyXml(property)); } rowsetXml.addSubElement(rowXml); } cmisXml.addAttribute("totalNumItems", q.getTotalNumItems()); cmisXml.addSubElement(rowsetXml); } return cmisXml.toXML(); }
Example #14
Source File: TestBindingTypes.java From iaf with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public CmisSender createSender() throws ConfigurationException { CmisSender sender = spy(new CmisSender()); sender.setUrl("http://dummy.url"); sender.setRepository("dummyRepository"); sender.setFileContentSessionKey("fileContent"); sender.setFileNameSessionKey("my-file"); sender.setUsername("test"); sender.setPassword("test"); sender.setKeepSession(false); byte[] base64 = Base64.encodeBase64("dummy data".getBytes()); session.put("fileContent", new String(base64)); HttpServletResponse response = mock(HttpServletResponse.class); session.put(IPipeLineSession.HTTP_RESPONSE_KEY, response); Session cmisSession = mock(Session.class); ObjectFactory objectFactory = mock(ObjectFactoryImpl.class); doReturn(objectFactory).when(cmisSession).getObjectFactory(); // GENERIC cmis object ObjectId objectId = mock(ObjectIdImpl.class); doReturn(objectId).when(cmisSession).createObjectId(anyString()); CmisObject cmisObject = spy(new CmisTestObject()); doReturn(cmisObject).when(cmisSession).getObject(any(ObjectId.class)); doReturn(cmisObject).when(cmisSession).getObject(any(ObjectId.class), any(OperationContext.class)); // GET OperationContext operationContext = mock(OperationContextImpl.class); doReturn(operationContext).when(cmisSession).createOperationContext(); // CREATE Folder folder = mock(FolderImpl.class); doReturn(cmisObject).when(folder).createDocument(anyMap(), any(ContentStreamImpl.class), any(VersioningState.class)); doReturn(folder).when(cmisSession).getRootFolder(); // FIND ItemIterable<QueryResult> query = new EmptyItemIterable<QueryResult>(); doReturn(query).when(cmisSession).query(anyString(), anyBoolean(), any(OperationContext.class)); try { doReturn(cmisSession).when(sender).createCmisSession(any(ParameterValueList.class)); } catch (SenderException e) { //Since we stub the entire session it won't throw exceptions } return sender; }