List of usage examples for org.apache.commons.collections IteratorUtils toList
public static List toList(Iterator iterator)
From source file:com.hurence.logisland.kafka.registry.KafkaRegistry.java
public List<Topic> getAllTopics() throws RegistryException { return IteratorUtils.toList( topicsKafkaStore.getAll().stream().map(value -> ((TopicValue) value).getTopic()).iterator()); }
From source file:com.uber.hoodie.common.table.log.avro.AvroLogAppenderTest.java
@SuppressWarnings("unchecked") @Test/*from www. j a v a 2 s . c om*/ public void testBasicAppendAndRead() throws IOException, URISyntaxException, InterruptedException { HoodieLogAppendConfig logConfig = HoodieLogAppendConfig.newBuilder().onPartitionPath(partitionPath) .withLogFileExtension(HoodieLogFile.DELTA_EXTENSION).withFileId("test-fileid1") .withBaseCommitTime("100").withSchema(SchemaTestUtil.getSimpleSchema()).withFs(fs).build(); RollingAvroLogAppender logAppender = new RollingAvroLogAppender(logConfig); logAppender.append(SchemaTestUtil.generateTestRecords(0, 100).iterator()); long size1 = logAppender.getCurrentSize(); logAppender.close(); // Close and Open again and append 100 more records logAppender = new RollingAvroLogAppender(logConfig); List<IndexedRecord> secondBatchInput = SchemaTestUtil.generateTestRecords(100, 100); logAppender.append(secondBatchInput.iterator()); long size2 = logAppender.getCurrentSize(); logAppender.close(); // Close and Open again and append 100 more records logAppender = new RollingAvroLogAppender(logConfig); List<IndexedRecord> lastBatchInput = SchemaTestUtil.generateTestRecords(200, 100); logAppender.append(lastBatchInput.iterator()); long size3 = logAppender.getCurrentSize(); logAppender.close(); AvroLogReader logReader = new AvroLogReader(logConfig.getLogFile(), fs, logConfig.getSchema()); // Try to grab the middle block here List<GenericRecord> secondBatch = IteratorUtils.toList(logReader.readBlock(size1)); assertEquals("Stream collect should return 100 records", 100, secondBatch.size()); assertEquals("Collected list should match the input list (ordering guaranteed)", secondBatchInput, secondBatch); // Try to grab the middle block here List<GenericRecord> lastBatch = IteratorUtils.toList(logReader.readBlock(size2)); assertEquals("Stream collect should return 100 records", 100, secondBatch.size()); assertEquals("Collected list should match the input list (ordering guaranteed)", lastBatchInput, lastBatch); List<GenericRecord> imaginaryBatch = IteratorUtils.toList(logReader.readBlock(size3)); assertEquals("Stream collect should return 0 records", 0, imaginaryBatch.size()); }
From source file:com.activecq.tools.flipbook.components.impl.FlipbookServiceImpl.java
public List<String> getImagePaths(final Component component, final ResourceResolver resourceResolver) { List<String> paths = new ArrayList<String>(); final Resource cr = resourceResolver.resolve(component.getPath()); if (cr == null) { return paths; }/*w ww .j a v a 2s. c o m*/ final Resource flipbook = cr.getChild(COMPONENT_FLIPBOOK_NODE); if (flipbook == null) { return paths; } final List<Resource> children = IteratorUtils.toList(flipbook.listChildren()); for (final Resource child : children) { if (ResourceUtil.isA(child, JcrConstants.NT_FILE)) { for (final String ext : IMAGE_EXTENSIONS) { if (StringUtils.endsWithIgnoreCase(child.getName(), ext)) { paths.add(child.getPath()); break; } } } } return paths; }
From source file:com.adobe.acs.commons.synth.children.ChildrenAsPropertyResourceTest.java
@Test public void testGet_Unsorted() throws Exception { valueMap.put("animals", sortedJSON.toString()); List<Resource> expected = new ArrayList<Resource>(); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-1", new ValueMapDecorator(entry1))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-2", new ValueMapDecorator(entry2))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-3", new ValueMapDecorator(entry3))); ChildrenAsPropertyResource childrenAsPropertyResource = new ChildrenAsPropertyResource(resource, "animals"); List<Resource> actual = IteratorUtils.toList(childrenAsPropertyResource.listChildren()); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals(expected.get(i).getName(), actual.get(i).getName()); }/*from w w w . j a va2s. c om*/ }
From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java
/** * Filter query results/* w w w .ja v a2s . c om*/ * * @param rootPath * @param result * @return list of resource paths of candidate error pages */ private List<String> filterResults(String rootPath, SearchResult result) { final List<Node> nodes = IteratorUtils.toList(result.getNodes()); final List<String> resultPaths = new ArrayList<String>(); if (StringUtils.isBlank(rootPath)) { return resultPaths; } // Filter results by the searchResource path; All valid results' paths should begin // with searchResource.getPath() for (Node node : nodes) { if (node == null) { continue; } try { // Make sure all query results under or equals to the current Search Resource if (StringUtils.equals(node.getPath(), rootPath) || StringUtils.startsWith(node.getPath(), rootPath.concat("/"))) { resultPaths.add(node.getPath()); } } catch (RepositoryException ex) { log.warn("Could not get path for node. {}", ex.getMessage()); // continue } } return resultPaths; }
From source file:com.streamsets.pipeline.stage.destination.kafka.KafkaTarget.java
@SuppressWarnings("unchecked") private void writeOneMessagePerRecord(Batch batch, List<Record> responseRecords) throws StageException { long count = 0; Iterator<Record> records = batch.getRecords(); while (records.hasNext()) { Record record = records.next();/*from ww w. j a va 2 s. c o m*/ try { String topic = conf.getTopic(record); Object partitionKey = conf.getPartitionKey(record, topic); kafkaProducer.enqueueMessage(topic, serializeRecord(record), partitionKey); count++; sendLineageEventIfNeeded(topic); } catch (KafkaConnectionException ex) { // Kafka connection exception is thrown when the client cannot connect to the list of brokers // even after retrying with backoff as specified in the retry and backoff config options // In this case we fail pipeline. throw ex; } catch (StageException ex) { errorRecordHandler.onError(new OnRecordErrorException(record, ex.getErrorCode(), ex.getParams())); } catch (IOException ex) { errorRecordHandler.onError(new OnRecordErrorException(record, KafkaErrors.KAFKA_51, record.getHeader().getSourceId(), ex.toString(), ex)); } } if (this.responseConf.sendResponseToOrigin) { try { responseRecords.addAll(kafkaProducer.write(getContext())); } catch (StageException ex) { if (ex.getErrorCode().getCode().equals(KafkaErrors.KAFKA_69.name())) { List<Record> recordList = IteratorUtils.toList(records); List<Integer> failedRecordIndices = (List<Integer>) ex.getParams()[0]; List<Exception> failedRecordExceptions = (List<Exception>) ex.getParams()[1]; for (int i = 0; i < failedRecordIndices.size(); i++) { Record record = recordList.get(failedRecordIndices.get(i)); Exception error = failedRecordExceptions.get(i); errorRecordHandler.onError(new OnRecordErrorException(record, KafkaErrors.KAFKA_51, record.getHeader().getSourceId(), error.toString(), error)); } } else { throw ex; } } } recordCounter += count; LOG.debug("Wrote {} records in this batch.", count); }
From source file:com.adobe.acs.commons.synth.children.ChildrenAsPropertyResourceTest.java
@Test public void testGet_Sorted() throws Exception { valueMap.put("animals", unsortedJSON.toString()); List<Resource> expected = new ArrayList<Resource>(); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-1", new ValueMapDecorator(entry1))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-2", new ValueMapDecorator(entry2))); expected.add(new SyntheticChildAsPropertyResource(resource, "entry-3", new ValueMapDecorator(entry3))); childrenAsPropertyResource = new ChildrenAsPropertyResource(resource, "animals", ChildrenAsPropertyResource.RESOURCE_NAME_COMPARATOR); ;//w ww . jav a 2s . com List<Resource> actual = IteratorUtils.toList(childrenAsPropertyResource.listChildren()); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals(expected.get(i).getName(), actual.get(i).getName()); } }
From source file:controllerClasses.special.fileParser.FileUpload.java
private synchronized void readAndPopulateList() throws FileNotFoundException, LdapLdifException { LdifReader reader = new LdifReader(); List<LdifEntry> entries = reader.parseLdifFile(fil.getAbsolutePath()); List<String> ocStringList = new ArrayList<>(); int ep = 0;//from ww w . ja v a 2s. co m for (LdifEntry entry : entries) { if (null != entry.get("cn")) { List<Value<?>> oc = fraIteratorTilListe(entry.get("objectClass").getAll()); for (Value<?> s : oc) { ocStringList.add(s.getString()); } if (ocStringList.contains("person") && !ocStringList.contains("user") && !ocStringList.contains("computer") && ocStringList.contains("contact")) { Emailcontacts entity = new Emailcontacts(new EmailcontactsPK()); try { entity.getEmailcontactsPK().setContactname( (entry.get("cn").getString() == null) ? "NOT SET" : entry.get("cn").getString()); } catch (LdapInvalidAttributeValueException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.getEmailcontactsPK().setContactname("NOT SET"); } try { entity.setEmailaddress((entry.get("mail").getString() == null) ? "NOT SET" : entry.get("mail").getString()); } catch (LdapInvalidAttributeValueException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setEmailaddress("NOT SET"); } entity.getEmailcontactsPK().setProjectid((String) FacesContext.getCurrentInstance() .getExternalContext().getSessionMap().get("projectID")); list.getEc().add(entity); } else if (ocStringList.contains("person") && ocStringList.contains("user") && !ocStringList.contains("computer") && !ocStringList.contains("contact")) { ep++; Users entity = new Users(new UsersPK()); try { entity.getUsersPK() .setUsername((entry.get("sAMAccountName").getString() == null) ? "NOT SET" : entry.get("sAMAccountName").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } try { entity.setFirstname((entry.get("givenName").getString() == null) ? "NOT SET" : entry.get("givenName").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setFirstname("NOT SET"); } try { entity.setLastname( (entry.get("sn").getString() == null) ? "NOT SET" : entry.get("sn").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setLastname("NOT SET"); } try { entity.setTitle((entry.get("title").getString() == null) ? "NOT SET" : entry.get("title").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setTitle("NOT SET"); } entity.setItcontact("NO"); try { entity.setDepartment((entry.get("department").getString() == null) ? "NOT SET" : entry.get("department").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setDepartment("NOT SET"); } entity.getUsersPK().setProjectid((String) FacesContext.getCurrentInstance().getExternalContext() .getSessionMap().get("projectID")); try { entity.setMobile(Integer.parseInt(entry.get("mobile").getString())); } catch (LdapInvalidAttributeValueException | NullPointerException | NumberFormatException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setMobile(12345); } try { entity.setEmploymentnr(entry.get("employmentNr").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setEmploymentnr(Integer.toString(ep)); } try { entity.setDn(entry.getDn().getNormName()); List<Value<?>> emailalias = IteratorUtils.toList(entry.get("proxyAddresses").getAll()); String res = ""; for (Value e : emailalias) { res = (res + ", " + e.getString() + " "); } entity.setEmailalias(res); } catch (NullPointerException e) { entity.setEmailalias("NOT SET"); } try { entity.setEmail(entry.get("mail").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); entity.setEmail("NOT SET"); } list.getUsr().add(entity); } else if (ocStringList.contains("group")) { int gr = Integer.parseInt(entry.get("grouptype").get().getString()); if (gr > 0) { Distributiongroups dgro = new Distributiongroups(new DistributiongroupsPK()); try { dgro.getDistributiongroupsPK().setDisplayname(entry.get("cn").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } dgro.setDn(entry.getDn().getNormName()); dgro.getDistributiongroupsPK().setProjectid((String) FacesContext.getCurrentInstance() .getExternalContext().getSessionMap().get("projectID")); try { dgro.setEmailalias(entry.get("mail").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); dgro.setEmailalias("NOT SET"); } try { dgro.setExternalemail(entry.get("msExchRequireAuthToSentTo").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); dgro.setExternalemail("NO"); } if ((!dgro.getExternalemail().isEmpty()) && dgro.getExternalemail().equalsIgnoreCase("true")) { dgro.setExternalemail("YES"); } list.getDgr().add(dgro); try { List<Value<?>> memberss = fraIteratorTilListe(entry.get("member").getAll()); List<DN> mem = new ArrayList<>(); for (Value<?> s : memberss) { try { mem.add(new DN(s.getString())); } catch (LdapInvalidDnException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } } getMembers() .add(new Members(mem, dgro.getDistributiongroupsPK().getDisplayname(), false)); } catch (NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } } else if (gr < 0) { Groups gro = new Groups(new GroupsPK()); try { gro.setDescription(entry.get("description").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); gro.setDescription("NOT SET"); } try { gro.setGroupowner(entry.get("managedBy").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); gro.setGroupowner("NOT SET"); } try { gro.getGroupsPK().setGroupname(entry.get("cn").getString()); } catch (LdapInvalidAttributeValueException | NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } gro.setDn(entry.getDn().toString()); gro.setFunctions("NOT SET"); gro.getGroupsPK().setProjectid((String) FacesContext.getCurrentInstance() .getExternalContext().getSessionMap().get("projectID")); list.getGr().add(gro); try { List<Value<?>> members = fraIteratorTilListe(entry.get("member").getAll()); List<DN> mem = new ArrayList<>(); for (Value<?> s : members) { try { mem.add(new DN(s.getString())); } catch (LdapInvalidDnException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } } getMembers().add(new Members(mem, gro.getGroupsPK().getGroupname(), true)); } catch (NullPointerException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } } } } } try { reader.close(); } catch (IOException ex) { Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.hurence.logisland.kafka.registry.KafkaRegistry.java
public List<Job> getAllJobs() throws RegistryException { return IteratorUtils .toList(jobsKafkaStore.getAll().stream().map(value -> ((JobValue) value).getJob()).iterator()); }
From source file:com.activecq.samples.workflow.impl.LocalizedTagTitleExtractorProcessWorkflow.java
/** * Returns localized Tag Titles for all the ancestor tags to the tags supplied in "tagPaths" * <p/>//from w w w .j a v a2 s . co m * Tags in * * @param tags * @param locale * @param tagManager * @param localizedTagTitles * @return */ private List<String> tagsToDownstreamLocalizedTagTitles(final Tag[] tags, final Locale locale, final TagManager tagManager, List<String> localizedTagTitles, int depth) { depth++; for (final Tag tag : tags) { if (tag.listChildren() != null && tag.listChildren().hasNext()) { final List<Tag> children = IteratorUtils.toList(tag.listChildren()); localizedTagTitles = tagsToDownstreamLocalizedTagTitles(children.toArray(new Tag[children.size()]), locale, tagManager, localizedTagTitles, depth); } if (depth > 1) { // Do not include the tags explicitly set on the resource localizedTagTitles.add(getLocalizedTagTitle(tag, locale)); } } return localizedTagTitles; }