public static void listTopFolderWithPagingAndPropFilter(Session session) { Folder root = session.getRootFolder(); Set<String> propertyFilter = new HashSet<String>(); propertyFilter.add(PropertyIds.CREATED_BY); propertyFilter.add(PropertyIds.NAME); OperationContext operationContext = new OperationContextImpl(); int maxItemsPerPage = 5; operationContext.setMaxItemsPerPage(maxItemsPerPage); operationContext.setFilter(propertyFilter); ItemIterable<CmisObject> contentItems = root.getChildren(operationContext); long numerOfPages = Math.abs(contentItems.getTotalNumItems() / maxItemsPerPage); int pageNumber = 1; boolean finishedPaging = false; int count = 0; while (!finishedPaging) { logger.info("Page " + pageNumber + " (" + numerOfPages + ")"); ItemIterable<CmisObject> currentPage = contentItems.skipTo(count).getPage(); for (CmisObject contentItem : currentPage) { logger.info( contentItem.getName() + " [type=" + contentItem.getType().getDisplayName() + "]"); count++; } pageNumber++; if (!currentPage.getHasMoreItems()) { finishedPaging = true; } } }
public AbstractMacroBaseUnitTestCase() { // log4j: PropertyConfigurator.configure( AbstractMacroBaseUnitTestCase.class.getClassLoader().getResource("log4j.properties")); // CMIS Repository Map<String, ConfluenceCMISRepository> repoConfigs = new WeakHashMap<String, ConfluenceCMISRepository>(); ConfluenceCMISRepository repoConfig = new ConfluenceCMISRepository( TEST_SERVER_NAME, TEST_REALM, TEST_USERNAME, TEST_PASSWORD, null); repoConfigs.put(TEST_SERVER_NAME, repoConfig); bandanaManager = mock(BandanaManager.class); when(bandanaManager.getValue((BandanaContext) anyObject(), anyString())) .thenReturn(repoConfigs); // CMIS ObjectId documentObjectId = mock(ObjectId.class); when(documentObjectId.getId()).thenReturn(TEST_DOCUMENT_ID); Document documentObject = getTestDocument(); List<CmisObject> documentList = new ArrayList<CmisObject>(); documentList.add(documentObject); ObjectId folderObjectId = mock(ObjectId.class); when(folderObjectId.getId()).thenReturn(TEST_FOLDER_ID); ItemIterable<CmisObject> children = mock(ItemIterable.class); when(children.getTotalNumItems()).thenReturn(1l); when(children.getHasMoreItems()).thenReturn(true).thenReturn(false); when(children.iterator()).thenReturn(documentList.iterator()); Folder folderObject = createMockedCmisObject( new String[][] { {PropertyIds.NAME, "Name", "A folder"}, {PropertyIds.BASE_TYPE_ID, "Base Type Id", "cmis:folder"}, {PropertyIds.OBJECT_TYPE_ID, "Object Type Id", "cmis:folder"}, {PropertyIds.OBJECT_ID, "Object Type Id", TEST_FOLDER_ID} }, Folder.class); when(folderObject.getId()).thenReturn(TEST_FOLDER_ID); when(folderObject.getChildren()).thenReturn(children); Session session = mock(Session.class); when(session.createObjectId(TEST_DOCUMENT_ID)).thenReturn(documentObjectId); when(session.createObjectId(TEST_FOLDER_ID)).thenReturn(folderObjectId); when(session.getObject(documentObjectId)).thenReturn(documentObject); when(session.getObject(folderObjectId)).thenReturn(folderObject); confluenceCMISRepository = mock(ConfluenceCMISRepository.class); when(confluenceCMISRepository.getSession()).thenReturn(session); }