List of usage examples for org.apache.commons.collections CollectionUtils forAllDo
public static void forAllDo(Collection collection, Closure closure)
From source file:org.dasein.cloud.azure.platform.AzureSqlDatabaseSupport.java
@Override public Iterable<String> listAccess(String toProviderDatabaseId) throws CloudException, InternalException { final ArrayList<String> rules = new ArrayList<String>(); Database database = getDatabase(toProviderDatabaseId); if (database == null) throw new InternalException("Invaid database provider Id"); String serverName = Arrays.asList(database.getProviderDatabaseId().split(":")).get(0); HttpUriRequest listRulesRequest = new AzureSQLDatabaseSupportRequests(provider) .listFirewallRules(serverName).build(); ServerServiceResourcesModel rulesModel = new AzureRequester(provider, listRulesRequest) .withXmlProcessor(ServerServiceResourcesModel.class).execute(); if (rulesModel == null || rulesModel.getServerServiceResourcesModels() == null) return rules; CollectionUtils.forAllDo(rulesModel.getServerServiceResourcesModels(), new Closure() { @Override/* w w w .j a va 2s . c o m*/ public void execute(Object input) { ServerServiceResourceModel firewallRule = (ServerServiceResourceModel) input; String endIpAddress = firewallRule.getEndIpAddress(); if (endIpAddress == null) endIpAddress = firewallRule.getStartIpAddress(); rules.add(String.format("%s::%s::%s", firewallRule.getName(), firewallRule.getStartIpAddress(), endIpAddress)); } }); return rules; }
From source file:org.dasein.cloud.azure.platform.AzureSqlDatabaseSupport.java
@Override public Iterable<DatabaseBackup> listBackups(final String forOptionalProviderDatabaseId) throws CloudException, InternalException { final ArrayList<DatabaseBackup> backups = new ArrayList<DatabaseBackup>(); if (forOptionalProviderDatabaseId == null) { HttpUriRequest httpUriRequest = new AzureSQLDatabaseSupportRequests(this.provider).listServers() .build();/*from w ww . j a va2 s .c om*/ ServerServiceResourcesModel serversModel = new AzureRequester(provider, httpUriRequest) .withXmlProcessor(ServerServiceResourcesModel.class).execute(); if (serversModel == null) return backups; CollectionUtils.forAllDo(serversModel.getServerServiceResourcesModels(), new Closure() { @Override public void execute(Object input) { final ServerServiceResourceModel serverModel = (ServerServiceResourceModel) input; backups.addAll(getBackupsForServer(serverModel.getName())); } }); } else { List<String> providerDBIdParts = Arrays.asList(forOptionalProviderDatabaseId.split(":")); if (providerDBIdParts.size() != 2) throw new InternalException("Invalid provider database id"); final String serverName = providerDBIdParts.get(0); final String databaseName = providerDBIdParts.get(1); backups.addAll(getBackupsForServer(serverName)); CollectionUtils.filter(backups, new Predicate() { @Override public boolean evaluate(Object object) { DatabaseBackup backup = (DatabaseBackup) object; return backup.getProviderDatabaseId() .equalsIgnoreCase(String.format("%s:%s", serverName, databaseName)); } }); } return backups; }
From source file:org.dasein.cloud.azure.platform.AzureSqlDatabaseSupport.java
private ArrayList<DatabaseBackup> getBackupsForServer(final String serverName) { final ArrayList<DatabaseBackup> backups = new ArrayList<DatabaseBackup>(); try {// w ww. ja va2s .c o m HttpUriRequest serverListBackupsRequest = new AzureSQLDatabaseSupportRequests(provider) .getRecoverableDatabases(serverName).build(); RecoverableDatabasesModel recoverableDatabasesModel = new AzureRequester(provider, serverListBackupsRequest).withXmlProcessor(RecoverableDatabasesModel.class).execute(); CollectionUtils.forAllDo(recoverableDatabasesModel.getRecoverableDatabaseModels(), new Closure() { @Override public void execute(Object input) { RecoverableDatabaseModel recoverableDatabaseModel = (RecoverableDatabaseModel) input; DatabaseBackup databaseBackup = new DatabaseBackup(); databaseBackup.setProviderDatabaseId( String.format("%s:%s", serverName, getDatabaseName(recoverableDatabaseModel))); databaseBackup.setProviderOwnerId(provider.getContext().getAccountNumber()); databaseBackup.setProviderRegionId(provider.getContext().getRegionId()); databaseBackup.setCurrentState(DatabaseBackupState.AVAILABLE); databaseBackup.setProviderBackupId(recoverableDatabaseModel.getName()); backups.add(databaseBackup); } }); } catch (CloudException e) { e.printStackTrace(); } return backups; }
From source file:org.dasein.cloud.azurepack.network.AzurePackIpAddressSupport.java
@Override public @Nonnull Iterable<IpForwardingRule> listRulesForServer(@Nonnull final String serverId) throws InternalException, CloudException { if (serverId == null) throw new InternalException("Parameter serverId cannot be null"); String stampId = provider.getDataCenterServices().listDataCenters(provider.getContext().getRegionId()) .iterator().next().getProviderDataCenterId(); WAPNatConnectionModel wapNatConnectionModel = getNatConnectionForServer(serverId, stampId); if (wapNatConnectionModel == null) return Collections.emptyList(); HttpUriRequest listRulesRequest = new AzurePackNetworkRequests(provider) .listRulesForConnection(wapNatConnectionModel.getId(), stampId).build(); WAPNatRulesModel wapNatRulesModel = new AzurePackRequester(provider, listRulesRequest) .withJsonProcessor(WAPNatRulesModel.class).execute(); final ArrayList<IpForwardingRule> rules = new ArrayList<IpForwardingRule>(); CollectionUtils.forAllDo(wapNatRulesModel.getRules(), new Closure() { @Override/* w w w . j ava 2 s. c o m*/ public void execute(Object input) { WAPNatRuleModel wapNatRuleModel = (WAPNatRuleModel) input; IpForwardingRule rule = new IpForwardingRule(); rule.setServerId(serverId); rule.setProviderRuleId(wapNatRuleModel.getId()); rule.setPrivatePort(Integer.valueOf(wapNatRuleModel.getInternalPort())); rule.setPublicPort(Integer.valueOf(wapNatRuleModel.getExternalPort())); if (wapNatRuleModel.getProtocol() != null) rule.setProtocol(Protocol.valueOf(wapNatRuleModel.getProtocol().toUpperCase())); rules.add(rule); } }); return rules; }
From source file:org.dasein.cloud.azurepack.tests.HttpMethodAsserts.java
private static void assertHttpMethod(final HttpUriRequest actualHttpRequest, String expectedHttpMethod, String expectedUrl, Header[] expectedHeaders) { assertHttpMethod(actualHttpRequest, expectedHttpMethod, expectedUrl); assertNotNull(actualHttpRequest.getAllHeaders()); CollectionUtils.forAllDo(Arrays.asList(expectedHeaders), new Closure() { @Override/*from w ww.j av a 2 s . co m*/ public void execute(Object input) { final Header expectedHeader = (Header) input; boolean headerExists = CollectionUtils.exists(Arrays.asList(actualHttpRequest.getAllHeaders()), new Predicate() { @Override public boolean evaluate(Object object) { Header actualHeader = (Header) object; return expectedHeader.getName().equals(actualHeader.getName()) && expectedHeader.getValue().equals(actualHeader.getValue()); } }); assertTrue(String.format( "Expected %s header not found in the request or found with the wrong value in the request", expectedHeader.getName()), headerExists); } }); }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
/** * Return the children of the specified path. * * @param path path of which we want to know the children * @return the children of the specified path *//*w w w . jav a2s.c o m*/ @Override public List<ExternalData> getChildrenNodes(String path) throws RepositoryException { String pathLowerCase = path.toLowerCase(); if (pathLowerCase.endsWith(CND) || pathLowerCase.contains(CND_SLASH)) { return getCndChildren(path, pathLowerCase); } else { List<ExternalData> children = super.getChildrenNodes(path); if (!children.isEmpty()) { CollectionUtils.filter(children, FILTER_OUT_FILES_WITH_STARTING_DOT); CollectionUtils.forAllDo(children, ENHANCE); } return children; } }
From source file:org.jannocessor.collection.impl.PowerArrayList.java
@SuppressWarnings("unchecked") @Override// w ww . j av a 2s .c o m public PowerList<E> each(final Operation<? super E> operation) { CollectionUtils.forAllDo(this, new Closure() { public void execute(Object input) { operation.execute((E) input); } }); return this; }
From source file:org.jannocessor.collection.impl.PowerLinkedHashSet.java
public PowerSet<E> each(final Operation<? super E> operation) { CollectionUtils.forAllDo(this, new Closure() { @SuppressWarnings("unchecked") public void execute(Object input) { operation.execute((E) input); }//from w ww . ja v a 2 s. c o m }); return this; }
From source file:org.jenkinsci.plugins.drupal.builders.DrupalTestsBuilder.java
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { // Make sure logs directory exists. File logsDir = new File(build.getWorkspace().getRemote(), logs); if (!logsDir.exists()) { listener.getLogger().println("[DRUPAL] Creating logs directory " + logs); logsDir.mkdir();/*from ww w . ja va 2 s . c om*/ } // Enable Simpletest if necessary. File rootDir = new File(build.getWorkspace().getRemote(), root); DrushInvocation drush = new DrushInvocation(new FilePath(rootDir), build.getWorkspace(), launcher, listener, build.getEnvironment(listener)); if (drush.isModuleInstalled("simpletest", true)) { listener.getLogger().println("[DRUPAL] Simpletest is already enabled"); } else { listener.getLogger().println("[DRUPAL] Simpletest is not enabled. Enabling Simpletest..."); drush.enable("simpletest"); } // Build list of targets and filter out excluded groups/classes. final List<String> targets = new ArrayList<String>(); final Collection<String> groups = Arrays.asList(exceptGroups.toLowerCase().split(",[\\s]*")); final Collection<String> classes = Arrays.asList(exceptClasses.toLowerCase().split(",[\\s]*")); CollectionUtils.forAllDo(drush.getTests(), new Closure() { @Override public void execute(Object input) { DrupalTest test = (DrupalTest) input; if (!groups.contains(test.getGroup().toLowerCase()) && !classes.contains(test.getClassName().toLowerCase())) { targets.add(test.getClassName()); } } }); Collections.sort(targets); // Run Simpletest. if (CollectionUtils.isEmpty(targets)) { listener.getLogger().println("[DRUPAL] No test groups/classes to run"); } else { drush.testRun(logsDir, uri, targets); } return true; }
From source file:org.kalypso.model.wspm.pdb.wspm.CheckoutDataMapping.java
/** * All pdb elements that have an associated wspm element. *///from w w w . j a v a 2 s . co m public Set<Object> getAllPdbElementsWithWspm() { final Set<Object> all = new HashSet<>(); CollectionUtils.forAllDo(m_eventMapping.keySet(), new AddKeysWithMappingClosure(m_eventMapping, all)); // REMAR: for the moment, we ignore rivers, as overwriting causes them now problem (because they are not editable). // CollectionUtils.forAllDo( m_waterMapping.keySet(), new AddKeysWithMappingClosure( m_waterMapping, all ) ); CollectionUtils.forAllDo(m_stateMapping.keySet(), new AddKeysWithMappingClosure(m_stateMapping, all)); return Collections.unmodifiableSet(all); }