List of usage examples for org.apache.commons.collections CollectionUtils find
public static Object find(Collection collection, Predicate predicate)
From source file:org.oscarehr.PMmodule.exporter.DATISMain.java
@Override protected String exportData() throws ExportException { List<IntakeNode> intakeNodes = intake.getNode().getChildren(); StringBuilder buf = new StringBuilder(); IntakeNode mainNode = null;//from w w w .j av a2 s .c o m IntakeNode gamblingNode = null; for (IntakeNode inode : intakeNodes) { if (inode.getLabelStr().startsWith(FILE_PREFIX_MAIN)) { mainNode = inode; } else if (inode.getLabelStr().startsWith(FILE_PREFIX_GAMBLING)) { gamblingNode = inode; } } Set<IntakeAnswer> answers = intake.getAnswers(); int counter = 0; for (IntakeAnswer ans : answers) { if (counter == fields.size()) { break; } if (ans.getNode().getGrandParent().equals(mainNode) || ans.getNode().getGrandParent().equals(gamblingNode)) { final String lbl = ans.getNode().getParent().getLabelStr().toUpperCase(); DATISField found = (DATISField) CollectionUtils.find(fields, new Predicate() { public boolean evaluate(Object arg0) { DATISField field = (DATISField) arg0; if (lbl.startsWith(field.getName())) { return true; } return false; } }); if (found != null) { writeCSV(buf, ans, found); //writeData(buf, ans, found); counter++; } } } if (buf.lastIndexOf(",") == -1) { return buf.toString(); } return buf.substring(0, buf.lastIndexOf(",")).toString(); }
From source file:org.oscarehr.PMmodule.exporter.DATISProgramInformation.java
@Override protected String exportData() throws ExportException { List<IntakeNode> intakeNodes = intake.getNode().getChildren(); StringBuilder buf = new StringBuilder(); IntakeNode file4Node = null;/*from w w w .ja v a 2s . co m*/ for (IntakeNode inode : intakeNodes) { if (inode.getLabelStr().startsWith(FILE_PREFIX)) { file4Node = inode; break; } } Set<IntakeAnswer> answers = intake.getAnswers(); int counter = 0; for (IntakeAnswer ans : answers) { if (counter == fields.size()) { break; } if (ans.getNode().getGrandParent().equals(file4Node)) { final String lbl = ans.getNode().getParent().getLabelStr().toUpperCase(); DATISField found = (DATISField) CollectionUtils.find(fields, new Predicate() { public boolean evaluate(Object arg0) { DATISField field = (DATISField) arg0; if (lbl.startsWith(field.getName())) { return true; } return false; } }); if (found != null) { writeCSV(buf, ans, found); //writeData(buf, ans, found); counter++; } } } if (buf.lastIndexOf(",") == -1) { return buf.toString(); } return buf.substring(0, buf.lastIndexOf(",")).toString(); }
From source file:org.pentaho.test.platform.plugin.pluginmgr.SystemPathPluginProviderIT.java
@SuppressWarnings("deprecation") @Test/*from w ww . j av a 2 s . c om*/ public void testLoadBeanDefinition() throws PlatformPluginRegistrationException { microPlatform.init(); List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession()); IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1")); assertNotNull("Plugin 1 should have been found", plugin); Collection<PluginBeanDefinition> beans = plugin.getBeans(); assertEquals("FooComponent was not loaded", 1, CollectionUtils.countMatches(beans, new Predicate() { public boolean evaluate(Object object) { PluginBeanDefinition bean = (PluginBeanDefinition) object; return bean.getBeanId().equals("FooComponent") && bean.getClassname().equals("org.pentaho.test.platform.plugin.pluginmgr.FooComponent"); } })); assertEquals("genericBean was not loaded", 1, CollectionUtils.countMatches(beans, new Predicate() { public boolean evaluate(Object object) { PluginBeanDefinition bean = (PluginBeanDefinition) object; return bean.getBeanId().equals("genericBean") && bean.getClassname().equals("java.lang.Object"); } })); }
From source file:org.pentaho.test.platform.plugin.pluginmgr.SystemPathPluginProviderIT.java
@SuppressWarnings("deprecation") @Test//from w ww . jav a 2 s .co m public void testLoadLifeCycleListener() throws PlatformPluginRegistrationException { microPlatform.init(); List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession()); IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1")); assertNotNull("Plugin 1 should have been found", plugin); assertEquals("org.pentaho.test.platform.plugin.pluginmgr.FooInitializer", plugin.getLifecycleListenerClassname()); }
From source file:org.pentaho.test.platform.plugin.pluginmgr.SystemPathPluginProviderIT.java
@SuppressWarnings("deprecation") @Test//from w w w .j ava 2 s. c om public void testLoadWebservices() throws PlatformPluginRegistrationException { microPlatform.init(); List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession()); System.out.println(PluginMessageLogger.getAll()); IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1")); assertNotNull("Plugin 1 should have been found", plugin); Collection<PluginServiceDefinition> webservices = plugin.getServices(); Object wsobj = CollectionUtils.find(webservices, new Predicate() { public boolean evaluate(Object object) { PluginServiceDefinition ws = (PluginServiceDefinition) object; boolean ret = ws.getTitle().equals("%TestWS1.TITLE%"); return ret; } }); assertNotNull("Webservice \"%TestWS1.TITLE%\" should have been loaded", wsobj); PluginServiceDefinition wsDfn = (PluginServiceDefinition) wsobj; assertEquals("org.pentaho.test.platform.engine.core.EchoServiceBean", wsDfn.getServiceClass()); assertEquals("xml", wsDfn.getTypes()[0]); assertEquals("gwt", wsDfn.getTypes()[1]); assertEquals("A test webservice", wsDfn.getDescription()); assertEquals(1, wsDfn.getExtraClasses().size()); assertEquals("java.lang.String", wsDfn.getExtraClasses().iterator().next()); }
From source file:org.pentaho.test.platform.plugin.pluginmgr.SystemPathPluginProviderIT.java
@SuppressWarnings("deprecation") @Test//from w ww .ja v a2s .c o m public void testLoadContentGenerators() throws PlatformPluginRegistrationException { microPlatform.init(); List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession()); IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("content-generator-plugin")); assertNotNull("content-generator-plugin should have been found", plugin); List<IContentInfo> contentTypes = plugin.getContentInfos(); Object contentType = CollectionUtils.find(contentTypes, new Predicate() { public boolean evaluate(Object object) { IContentInfo type = (IContentInfo) object; return type.getTitle().equals("Good Test Type"); } }); assertNotNull("\"Good Test Type\" should have been loaded", contentType); assertNotNull("\"Good Test Type\" extension definition is incorrect", ((IContentInfo) contentType).getExtension().equals("good-content-type")); IContentInfo contentInfo = (IContentInfo) contentType; IPluginOperation operation = contentInfo.getOperations().listIterator().next(); assertEquals("Missing perspective", "custom-perspective", operation.getPerspective()); assertEquals("\"Test Type Missing type\" should not have been loaded", 0, CollectionUtils.countMatches(contentTypes, new Predicate() { public boolean evaluate(Object object) { IContentInfo type = (IContentInfo) object; return type.getTitle().equals("Test Type Missing type"); } })); assertEquals("\"test-type-missing-title\" should not have been loaded", 0, CollectionUtils.countMatches(contentTypes, new Predicate() { public boolean evaluate(Object object) { IContentInfo type = (IContentInfo) object; return type.getExtension().equals("test-type-missing-title"); } })); }
From source file:org.pentaho.test.platform.plugin.pluginmgr.SystemPathPluginProviderIT.java
@SuppressWarnings("deprecation") @Test/*from ww w . j av a 2s. c o m*/ public void testLoadPerspectives() throws PlatformPluginRegistrationException { microPlatform.init(); List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession()); IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1")); assertNotNull("Plugin 1 should have been found", plugin); assertEquals(2, plugin.getPluginPerspectives().size()); IPluginPerspective perspective = plugin.getPluginPerspectives().get(0); assertEquals(perspective.getId(), "perspective1"); assertEquals(perspective.getTitle(), "Test Perspective 1"); assertEquals(perspective.getLayoutPriority(), 500); }
From source file:org.squashtest.tm.service.internal.deletion.CampaignDeletionHandlerImpl.java
private void removeItpiFromIteration(List<TestSuite> suites, final List<Long> targetIds) { Set<Long> idsToRemove = new HashSet<>(); // TODO : maybe use a couple of HQL queries that would compute this with more efficiency for (TestSuite suite : suites) { for (IterationTestPlanItem itpi : suite.getTestPlan()) { // Try to find one test suite in the IterationTestPlanItem that is none of the test suites to remove Object result = CollectionUtils.find(itpi.getTestSuites(), new Predicate() { @Override/*from w w w . jav a 2 s . co m*/ public boolean evaluate(Object ts) { TestSuite testSuite = (TestSuite) ts; return !targetIds.contains(testSuite.getId()); } }); // If nothing if found (ie : the iteration test plan item only belong to test suite that are selected) // we want to remove it from the iteration. if (result == null) { idsToRemove.add(itpi.getId()); } } } for (Long id : idsToRemove) { iterationTestPlanManagerService.removeTestPlanFromIteration(id); } }
From source file:org.squashtest.tm.service.internal.milestone.ActiveMilestoneHolderImpl.java
@Override public Optional<Milestone> getActiveMilestone() { if (activeMilestoneHolder.get() == null) { List<Milestone> visibles = milestoneFinderService.findAllVisibleToCurrentUser(); final Long milestoneId = activeMilestoneIdHolder.get(); Milestone milestone = (Milestone) CollectionUtils.find(visibles, new Predicate() { @Override/* w w w . j a va 2 s . com*/ public boolean evaluate(Object milestone) { return ((Milestone) milestone).getId().equals(milestoneId); } }); activeMilestoneHolder.set(Optional.fromNullable(milestone)); } return activeMilestoneHolder.get(); }
From source file:org.squashtest.tm.service.internal.testcase.CustomTestCaseModificationServiceImpl.java
private Couple<Long, String> extractAutomatedProjectAndTestName(Long testCaseId, String testPath) { // first we reject the operation if the script name is malformed if (!PathUtils.isPathWellFormed(testPath)) { throw new MalformedScriptPathException(); }/*from w ww .j a va 2 s. c om*/ // now it's clear to go, let's find which TA project it is. The first slash must be removed because it doesn't // count. String path = testPath.replaceFirst("^/", ""); int idxSlash = path.indexOf('/'); String projectLabel = path.substring(0, idxSlash); String testName = path.substring(idxSlash + 1); TestCase tc = testCaseDao.findById(testCaseId); GenericProject tmproject = tc.getProject(); TestAutomationProject tap = (TestAutomationProject) CollectionUtils .find(tmproject.getTestAutomationProjects(), new HasSuchLabel(projectLabel)); // if the project couldn't be found we must also reject the operation if (tap == null) { throw new UnallowedTestAssociationException(); } return new Couple<>(tap.getId(), testName); }