List of usage examples for org.apache.commons.collections4 IteratorUtils toList
public static <E> List<E> toList(final Iterator<? extends E> iterator)
From source file:com.shampan.model.PageModel.java
public List<PageCategoryDAO> getCategories() { MongoCollection<PageCategoryDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGECATEGORIES.toString(), PageCategoryDAO.class); MongoCursor<PageCategoryDAO> cursorCategoryList = mongoCollection.find().iterator(); List<PageCategoryDAO> categoryList = IteratorUtils.toList(cursorCategoryList); return categoryList; }
From source file:com.github.rvesse.airline.builder.GroupBuilder.java
public GroupBuilder<C> withCommands(Iterable<Class<? extends C>> commands) { this.commands.addAll(IteratorUtils.toList(commands.iterator())); return this; }
From source file:io.kodokojo.service.redis.RedisProjectStore.java
@Override public String addProjectConfiguration(ProjectConfiguration projectConfiguration) { if (projectConfiguration == null) { throw new IllegalArgumentException("projectConfiguration must be defined."); }/*from w w w . j av a 2 s .c om*/ if (isBlank(projectConfiguration.getEntityIdentifier())) { throw new IllegalArgumentException("EntityIdentifier must be defined."); } if (StringUtils.isNotBlank(projectConfiguration.getIdentifier())) { throw new IllegalArgumentException( "ProjectConfiguration " + projectConfiguration.getName() + " already exist"); } String identifier = generateId(); return writeProjectConfiguration(new ProjectConfiguration(projectConfiguration.getEntityIdentifier(), identifier, projectConfiguration.getName(), IteratorUtils.toList(projectConfiguration.getAdmins()), projectConfiguration.getStackConfigurations(), IteratorUtils.toList(projectConfiguration.getUsers()))); }
From source file:com.shampan.model.PageModel.java
public List<PageSubCategoryDAO> getSubCategories() { MongoCollection<PageSubCategoryDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGESUBCATEGORIES.toString(), PageSubCategoryDAO.class); MongoCursor<PageSubCategoryDAO> cursorCategoryList = mongoCollection.find().iterator(); List<PageSubCategoryDAO> subCategoryList = IteratorUtils.toList(cursorCategoryList); return subCategoryList; }
From source file:com.shampan.model.VideoModel.java
/** * This method will return a video information * * @param videoId video Id/*w w w.j a v a 2 s.c o m*/ * @author created by Rashida on 21 October */ public List<VideoDAO> getVideos(String userId) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("userId").is(userId).get(); Document pQuery = new Document(); pQuery.put("videoId", "$all"); pQuery.put("categoryId", "$all"); pQuery.put("userInfo", "$all"); pQuery.put("imageUrl", "$all"); MongoCursor<VideoDAO> cursorVideoList = mongoCollection.find(selectQuery).projection(pQuery).iterator(); List<VideoDAO> videoList = IteratorUtils.toList(cursorVideoList); return videoList; }
From source file:net.ontopia.topicmaps.nav2.taglibs.TMvalue.TologQueryTag.java
/** * INTERNAL: Wraps a QueryResultIF instance in a suitable * MapCollection implementation.//from ww w . j a v a 2s.c o m */ protected Collection getMapCollection(QueryResultIF result) { if (select != null) { int index = result.getIndex(select); if (index < 0) throw new IndexOutOfBoundsException("No query result column named '" + select + "'"); List list = new ArrayList(); while (result.next()) list.add(result.getValue(index)); result.close(); return list; } if (result instanceof net.ontopia.topicmaps.query.impl.basic.QueryResult) // BASIC return net.ontopia.topicmaps.query.impl.basic.QueryResultWrappers.getWrapper(result); else { // FIXME: Should pass collection size if available. return IteratorUtils.toList(new QueryResultIterator(result)); } }
From source file:io.wcm.testing.mock.sling.resource.JcrResourceResolverTest.java
@Test public void testGetResourcesAndValues() throws IOException, RepositoryException { Resource resource1 = this.resourceResolver.getResource(getTestRootNode().getPath() + "/node1"); assertNotNull(resource1);/* w w w . jav a 2s . c o m*/ assertEquals("node1", resource1.getName()); ValueMap props = resource1.getValueMap(); assertEquals(STRING_VALUE, props.get("stringProp", String.class)); assertArrayEquals(STRING_ARRAY_VALUE, props.get("stringArrayProp", String[].class)); assertEquals((Integer) INTEGER_VALUE, props.get("integerProp", Integer.class)); assertEquals(DOUBLE_VALUE, props.get("doubleProp", Double.class), 0.0001); assertEquals(BOOLEAN_VALUE, props.get("booleanProp", Boolean.class)); assertEquals(DATE_VALUE, props.get("dateProp", Date.class)); assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime()); Resource binaryPropResource = resource1.getChild("binaryProp"); InputStream is = binaryPropResource.adaptTo(InputStream.class); byte[] dataFromResource = IOUtils.toByteArray(is); is.close(); assertArrayEquals(BINARY_VALUE, dataFromResource); // read second time to ensure not the original input stream was returned InputStream is2 = binaryPropResource.adaptTo(InputStream.class); byte[] dataFromResource2 = IOUtils.toByteArray(is2); is2.close(); assertArrayEquals(BINARY_VALUE, dataFromResource2); List<Resource> children = IteratorUtils.toList(resource1.listChildren()); assertEquals(2, children.size()); assertEquals("node11", children.get(0).getName()); assertEquals("node12", children.get(1).getName()); }
From source file:com.rsmart.kuali.kfs.module.ld.businessobject.lookup.CurrentFundsLookupableHelperServiceImpl.java
/** * Gets a list with the fields that will be displayed on page * //from w ww .j a v a 2 s .co m * @param fieldValues list of fields that are used as a key to filter out data * @see org.kuali.kfs.kns.lookup.Lookupable#getSearchResults(java.util.Map) */ @Override public List getSearchResults(Map fieldValues) { LOG.info("getSearchResults() - Entry"); boolean unbounded = false; Long actualCountIfTruncated = new Long(0); setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION)); setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY)); // get the pending entry option. This method must be prior to the get search results String pendingEntryOption = laborInquiryOptionsService.getSelectedPendingEntryOption(fieldValues); // get the consolidation option boolean isConsolidated = laborInquiryOptionsService.isConsolidationSelected(fieldValues, (Collection<Row>) getRows()); String searchObjectCodeVal = (String) fieldValues.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE); // Check for a valid labor object code for this inquiry if (StringUtils.isNotBlank(searchObjectCodeVal)) { Map objectCodeFieldValues = new HashMap(); objectCodeFieldValues.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, fieldValues.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR)); objectCodeFieldValues.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, fieldValues.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)); objectCodeFieldValues.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, searchObjectCodeVal); LaborLedgerObject foundObjectCode = (LaborLedgerObject) businessObjectService .findByPrimaryKey(LaborObject.class, objectCodeFieldValues); if (foundObjectCode == null) { GlobalVariables.getMessageMap().putError(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, LaborKeyConstants.ERROR_INVALID_LABOR_OBJECT_CODE, "2"); return new CollectionIncomplete(new ArrayList(), actualCountIfTruncated); } } // Parse the map and call the DAO to process the inquiry Collection<AccountStatusCurrentFunds> searchResultsCollection = buildCurrentFundsCollection( IteratorUtils.toList(laborDao.getCurrentFunds(fieldValues, isConsolidated)), isConsolidated, pendingEntryOption); // update search results according to the selected pending entry option laborInquiryOptionsService.updateCurrentFundsByPendingLedgerEntry(searchResultsCollection, fieldValues, pendingEntryOption, isConsolidated); // gets the July1st budget amount column. Collection<July1PositionFunding> july1PositionFundings = laborDao.getJuly1(fieldValues); this.updateJuly1BalanceAmount(searchResultsCollection, july1PositionFundings, isConsolidated); // sort list if default sort column given List searchResults = (List) searchResultsCollection; List defaultSortColumns = getDefaultSortColumns(); if (defaultSortColumns.size() > 0) { Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true)); } return new CollectionIncomplete(searchResults, actualCountIfTruncated); }
From source file:io.kodokojo.endpoint.ProjectSparkEndpoint.java
@Override public void configure() { post(BASE_API + "/projectconfig", JSON_CONTENT_TYPE, (request, response) -> { String body = request.body(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Try to create project {}", body); }//from w ww . ja va2 s. c o m Gson gson = localGson.get(); ProjectCreationDto dto = gson.fromJson(body, ProjectCreationDto.class); if (dto == null) { halt(400); return ""; } User owner = userStore.getUserByIdentifier(dto.getOwnerIdentifier()); String entityId = owner.getEntityIdentifier(); if (StringUtils.isBlank(entityId)) { halt(400); return ""; } Set<StackConfiguration> stackConfigurations = createDefaultStackConfiguration(dto.getName()); if (CollectionUtils.isNotEmpty(dto.getStackConfigs())) { stackConfigurations = dto.getStackConfigs().stream().map(stack -> { Set<BrickConfiguration> brickConfigurations = stack.getBrickConfigs().stream().map(b -> { Brick brick = brickFactory.createBrick(b.getName()); return new BrickConfiguration(brick); }).collect(Collectors.toSet()); StackType stackType = StackType.valueOf(stack.getType()); BootstrapStackData bootstrapStackData = projectManager.bootstrapStack(dto.getName(), stack.getName(), stackType); return new StackConfiguration(stack.getName(), stackType, brickConfigurations, bootstrapStackData.getLoadBalancerHost(), bootstrapStackData.getSshPort()); }).collect(Collectors.toSet()); } List<User> users = new ArrayList<>(); users.add(owner); if (CollectionUtils.isNotEmpty(dto.getUserIdentifiers())) { for (String userId : dto.getUserIdentifiers()) { User user = userStore.getUserByIdentifier(userId); users.add(user); } } ProjectConfiguration projectConfiguration = new ProjectConfiguration(entityId, dto.getName(), Collections.singletonList(owner), stackConfigurations, users); String projectConfigIdentifier = projectStore.addProjectConfiguration(projectConfiguration); response.status(201); response.header("Location", "/projectconfig/" + projectConfigIdentifier); return projectConfigIdentifier; }); get(BASE_API + "/projectconfig/:id", JSON_CONTENT_TYPE, (request, response) -> { String identifier = request.params(":id"); ProjectConfiguration projectConfiguration = projectStore.getProjectConfigurationById(identifier); if (projectConfiguration == null) { halt(404); return ""; } SimpleCredential credential = extractCredential(request); if (userStore.userIsAdminOfProjectConfiguration(credential.getUsername(), projectConfiguration)) { return new ProjectConfigDto(projectConfiguration); } halt(403); return ""; }, jsonResponseTransformer); put(BASE_API + "/projectconfig/:id/user", JSON_CONTENT_TYPE, ((request, response) -> { SimpleCredential credential = extractCredential(request); String identifier = request.params(":id"); ProjectConfiguration projectConfiguration = projectStore.getProjectConfigurationById(identifier); if (projectConfiguration == null) { halt(404); return ""; } if (userStore.userIsAdminOfProjectConfiguration(credential.getUsername(), projectConfiguration)) { JsonParser parser = new JsonParser(); JsonArray root = (JsonArray) parser.parse(request.body()); List<User> users = IteratorUtils.toList(projectConfiguration.getUsers()); List<User> usersToAdd = new ArrayList<>(); for (JsonElement el : root) { String userToAddId = el.getAsJsonPrimitive().getAsString(); User userToAdd = userStore.getUserByIdentifier(userToAddId); if (userToAdd != null && !users.contains(userToAdd)) { users.add(userToAdd); usersToAdd.add(userToAdd); } } projectConfiguration.setUsers(users); projectStore.updateProjectConfiguration(projectConfiguration); projectManager.addUsersToProject(projectConfiguration, usersToAdd); } else { halt(403, "You have not right to add user to project configuration id " + identifier + "."); } return ""; }), jsonResponseTransformer); delete(BASE_API + "/projectconfig/:id/user", JSON_CONTENT_TYPE, ((request, response) -> { SimpleCredential credential = extractCredential(request); if (credential != null) { String identifier = request.params(":id"); ProjectConfiguration projectConfiguration = projectStore.getProjectConfigurationById(identifier); if (projectConfiguration == null) { halt(404); return ""; } if (userStore.userIsAdminOfProjectConfiguration(credential.getUsername(), projectConfiguration)) { JsonParser parser = new JsonParser(); JsonArray root = (JsonArray) parser.parse(request.body()); List<User> users = IteratorUtils.toList(projectConfiguration.getUsers()); for (JsonElement el : root) { String userToDeleteId = el.getAsJsonPrimitive().getAsString(); User userToDelete = userStore.getUserByIdentifier(userToDeleteId); if (userToDelete != null) { users.remove(userToDelete); } } projectConfiguration.setUsers(users); projectStore.updateProjectConfiguration(projectConfiguration); } else { halt(403, "You have not right to delete user to project configuration id " + identifier + "."); } } return ""; }), jsonResponseTransformer); // -- Project // Start project post(BASE_API + "/project/:id", JSON_CONTENT_TYPE, ((request, response) -> { SimpleCredential credential = extractCredential(request); if (credential != null) { User currentUser = userStore.getUserByUsername(credential.getUsername()); String projectConfigurationId = request.params(":id"); ProjectConfiguration projectConfiguration = projectStore .getProjectConfigurationById(projectConfigurationId); if (projectConfiguration == null) { halt(404, "Project configuration not found."); return ""; } if (userStore.userIsAdminOfProjectConfiguration(credential.getUsername(), projectConfiguration)) { String projectId = projectStore.getProjectIdByProjectConfigurationId(projectConfigurationId); if (StringUtils.isBlank(projectId)) { // projectManager.bootstrapStack(projectConfiguration.getName(), projectConfiguration.getDefaultStackConfiguration().getName(), projectConfiguration.getDefaultStackConfiguration().getType()); Project project = projectManager.start(projectConfiguration); response.status(201); String projectIdStarted = projectStore.addProject(project, projectConfigurationId); return projectIdStarted; } else { halt(409, "Project already exist."); } } else { halt(403, "You have not right to start project configuration id " + projectConfigurationId + "."); } } return ""; })); get(BASE_API + "/project/:id", JSON_CONTENT_TYPE, ((request, response) -> { SimpleCredential credential = extractCredential(request); if (credential != null) { User currentUser = userStore.getUserByUsername(credential.getUsername()); String projectId = request.params(":id"); Project project = projectStore.getProjectByIdentifier(projectId); if (project == null) { halt(404); return ""; } ProjectConfiguration projectConfiguration = projectStore .getProjectConfigurationById(project.getProjectConfigurationIdentifier()); if (userStore.userIsAdminOfProjectConfiguration(currentUser.getUsername(), projectConfiguration)) { return new ProjectDto(project); } else { halt(403, "You have not right to lookup project id " + projectId + "."); } } return ""; }), jsonResponseTransformer); }
From source file:io.wcm.testing.mock.sling.resource.SlingCrudResourceResolverTest.java
@Test public void testListChildren() throws IOException { Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1"); List<Resource> children = IteratorUtils.toList(resource1.listChildren()); assertEquals(2, children.size());/* ww w . ja va 2 s . com*/ assertEquals("node11", children.get(0).getName()); assertEquals("node12", children.get(1).getName()); }