Example usage for org.apache.commons.collections CollectionUtils addAll

List of usage examples for org.apache.commons.collections CollectionUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils addAll.

Prototype

public static void addAll(Collection collection, Object[] elements) 

Source Link

Document

Adds all elements in the array to the given collection.

Usage

From source file:org.geolatte.geom.builder.client.DslTest.java

@Test
public void testLinearRing3D() {

    LinearRing lr = ring(WGS84_Z, g(0, 0, 0), g(1, 0, 0), g(1, 1, 0), g(0, 1, 0), g(0, 0, 0));
    assertTrue(hasVerticalAxis(lr.getCoordinateReferenceSystem()));

    ArrayList<G3D> points = new ArrayList<G3D>();
    CollectionUtils.addAll(points, lr.getPositions().iterator());
    assertEquals(points.get(0).getLon(), 0, DELTA);
    assertEquals(points.get(0).getLat(), 0, DELTA);
    assertEquals(points.get(0).getHeight(), 0, DELTA);
    assertEquals(points.get(1).getLon(), 1, DELTA);
    assertEquals(points.get(1).getLat(), 0, DELTA);
    assertEquals(points.get(1).getHeight(), 0, DELTA);
    assertEquals(points.get(2).getLon(), 1, DELTA);
    assertEquals(points.get(2).getLat(), 1, DELTA);
    assertEquals(points.get(2).getHeight(), 0, DELTA);
    assertEquals(points.get(3).getLon(), 0, DELTA);
    assertEquals(points.get(3).getLat(), 1, DELTA);
    assertEquals(points.get(3).getHeight(), 0, DELTA);
    assertEquals(points.get(4).getLon(), 0, DELTA);
    assertEquals(points.get(4).getLat(), 0, DELTA);
    assertEquals(points.get(4).getHeight(), 0, DELTA);
}

From source file:org.hyperic.hq.ui.action.resource.hub.RemoveResourceAction.java

private void activateAlerts(HttpServletRequest request, String[] resourceItems, boolean enabled)
        throws Exception {

    Integer sessionId = RequestUtils.getSessionId(request);

    List<String> resourceList = new ArrayList<String>();
    CollectionUtils.addAll(resourceList, resourceItems);
    List<AppdefEntityID> entities = BizappUtils.buildAppdefEntityIds(resourceList);

    eventsBoss.activateAlertDefinitions(sessionId.intValue(),
            entities.toArray(new AppdefEntityID[entities.size()]), enabled);

    RequestUtils.setConfirmation(request,
            enabled ? "resource.common.confirm.AlertsEnabled" : "resource.common.confirm.AlertsDisabled");
}

From source file:org.hyperic.hq.ui.action.resource.hub.RemoveResourceAction.java

private void removeResources(HttpServletRequest request, String[] resourceItems)
        throws SessionNotFoundException, ApplicationException, VetoException, RemoteException,
        ServletException {//w  w w  .  j a  va  2s . c  o m

    final Integer sessionId = RequestUtils.getSessionId(request);

    List<String> resourceList = new ArrayList<String>();
    CollectionUtils.addAll(resourceList, resourceItems);
    List<AppdefEntityID> entities = BizappUtils.buildAppdefEntityIds(resourceList);
    final Reference<SessionNotFoundException> snfeToThrow = new Reference<SessionNotFoundException>();
    final Reference<ApplicationException> aeToThrow = new Reference<ApplicationException>();
    final Reference<SessionTimeoutException> stoeToThrow = new Reference<SessionTimeoutException>();
    if (resourceItems != null && resourceItems.length > 0) {
        final Reference<Integer> numDeleted = new Reference<Integer>();
        final Reference<String> vetoMessage = new Reference<String>();
        //Fix for [HHQ-5417] - numDeleted.get() returned null
        numDeleted.set(0);
        // about the exception handling:
        // if someone either deleted the entity out from under our user
        // or the user hit the back button, a derivative of
        // AppdefEntityNotFoundException gets thrown... we can still
        // keep going on, trying to delete the other things in our list
        // (which is why the whole shebang isn't in one big
        // try / catch) but we only confirm that something was deleted
        // if something actually, um, was
        for (final AppdefEntityID resourceId : entities) {
            final Runnable runner = new Runnable() {
                public void run() {
                    try {
                        List<AppdefEntityID> list = Arrays
                                .asList(appdefBoss.removeAppdefEntity(sessionId.intValue(), resourceId, false));
                        Integer num = numDeleted.get();
                        numDeleted.set(num + list.size());
                    } catch (AppdefEntityNotFoundException e) {
                        log.error("Removing resource " + resourceId + "failed.", e);
                    } catch (VetoException v) {
                        vetoMessage.set(v.getMessage());
                        log.info(vetoMessage);
                    } catch (SessionNotFoundException e) {
                        snfeToThrow.set(e);
                    } catch (SessionTimeoutException e) {
                        stoeToThrow.set(e);
                    } catch (ApplicationException e) {
                        aeToThrow.set(e);
                    }
                }
            };
            transactionRetry.runTransaction(runner, 3, 1000);
            // this is ugly, may need to rethink the TransactionRetry api to avoid this type of code
            if (snfeToThrow.get() != null) {
                throw snfeToThrow.get();
            } else if (stoeToThrow.get() != null) {
                throw stoeToThrow.get();
            } else if (aeToThrow.get() != null) {
                throw aeToThrow.get();
            }
        }
        if (vetoMessage.get() != null) {
            RequestUtils.setErrorObject(request, "resource.common.inventory.groups.error.RemoveVetoed",
                    vetoMessage.get());
        } else if (numDeleted.get() > 0) {
            RequestUtils.setConfirmation(request, "resource.common.confirm.ResourcesRemoved");
        }
    }
}

From source file:org.hyperic.hq.ui.action.resource.platform.autodiscovery.AutoDiscoveryResultsForm.java

/**
 * @param list//from  www .j  a  va  2  s .  co m
 */
public void setServerTypeFilterList(AppdefResourceTypeValue[] serverTypes) {

    serverTypeFilterList = new ArrayList();
    CollectionUtils.addAll(serverTypeFilterList, serverTypes);
}

From source file:org.hyperic.hq.ui.action.resource.platform.autodiscovery.EditAutoDiscoveryPrepAction.java

/**
 * Get the selected server types.//from w  w  w .j ava 2s .  c  o  m
 */
private List<AppdefResourceTypeValue> buildSelectedServerTypes(List<ServerTypeValue> serverTypes,
        ServerSignature[] serverSigs) throws Exception {
    List<ServerSignature> serverDetectorList = new ArrayList<ServerSignature>();
    CollectionUtils.addAll(serverDetectorList, serverSigs);

    ServerTypeValue[] types = serverTypes.toArray(new ServerTypeValue[0]);

    return BizappUtils.buildServerTypesFromServerSig(types, serverDetectorList.iterator());
}

From source file:org.hyperic.hq.ui.action.resource.platform.autodiscovery.PlatformAutoDiscoveryForm.java

/**
 * build up a list of label beans of serverType.names as label and server
 * type id as value/*from  ww w.j a v  a2 s .  co m*/
 */
public void setServerTypes(AppdefResourceTypeValue[] serverTypes) {

    this.sTypes = new ArrayList();

    CollectionUtils.addAll(sTypes, serverTypes);

    for (int i = 0; i < serverTypes.length; i++) {
        AppdefResourceTypeValue stype = serverTypes[i];

        if (stype != null) {
            LabelValueBean val = new LabelValueBean(stype.getName(), stype.getId().toString());
            serverTypesLB.add(val);
        }
    }
}

From source file:org.hyperic.hq.ui.action.resource.platform.autodiscovery.ViewResultsPrepAction.java

public ActionForward workflow(ComponentContext context, ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    AutoDiscoveryResultsForm aForm = (AutoDiscoveryResultsForm) form;

    AIPlatformValue aiVal = (AIPlatformValue) request.getAttribute(Constants.AIPLATFORM_ATTR);

    ServletContext ctx = getServlet().getServletContext();
    Integer sessionId = RequestUtils.getSessionId(request);

    AppdefResourceTypeValue[] supportedSTypeFilter;
    supportedSTypeFilter = BizappUtils.buildSupportedAIServerTypes(ctx, request, aiVal.getPlatformTypeName(),
            appdefBoss, aiBoss);//from  w  w w  .  j  a v a 2 s . c o m

    AppdefResourceTypeValue[] serverTypeFilter = BizappUtils.buildfilteredAIServerTypes(supportedSTypeFilter,
            aiVal.getAIServerValues());

    aForm.setServerTypeFilterList(serverTypeFilter);

    PlatformValue pValue = (PlatformValue) RequestUtils.getResource(request);
    if (pValue != null) {
        aForm.setEid(pValue.getEntityId().getAppdefKey());
    }

    aForm.setAiRid(aiVal.getId());

    aForm.buildActionOptions(request);

    List<AIServerValue> newModifiedServers = new PageList<AIServerValue>();
    AIServerValue[] aiServerVals = aiVal.getAIServerValues();
    CollectionUtils.addAll(newModifiedServers, aiServerVals);

    List<AIAppdefResourceValue> filteredNewServers = BizappUtils.filterAIResourcesByStatus(newModifiedServers,
            aForm.getStdStatusFilter());

    String name = "";

    if (aForm.getServerTypeFilter() != null && aForm.getServerTypeFilter().intValue() != -1) {
        ServerType sTypeVal = appdefBoss.findServerTypeById(sessionId.intValue(), aForm.getServerTypeFilter());
        name = sTypeVal.getName();
    }

    List<AIServerValue> filteredServers2 = BizappUtils.filterAIResourcesByServerType(filteredNewServers, name);

    List<AIIpValue> newIps = new ArrayList<AIIpValue>();

    AIIpValue[] aiIpVals = aiVal.getAIIpValues();
    CollectionUtils.addAll(newIps, aiIpVals);

    List<AIAppdefResourceValue> filteredIps = BizappUtils.filterAIResourcesByStatus(newIps,
            aForm.getIpsStatusFilter());

    List sortedFilteredIps = BizappUtils.sortAIResource(filteredIps);
    request.setAttribute(Constants.AI_IPS, sortedFilteredIps);
    request.setAttribute(Constants.AI_SERVERS, filteredServers2);

    return null;
}

From source file:org.hyperic.hq.ui.action.resource.service.inventory.NewServiceFormPrepareAction.java

public ActionForward workflow(ComponentContext context, ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    ResourceForm newForm = (ResourceForm) form;

    int sessionId = RequestUtils.getSessionId(request).intValue();

    AppdefEntityID aeid = RequestUtils.getEntityId(request);
    Integer parentId = aeid.getId();
    List serviceTypeVals = new ArrayList();
    ServerTypeValue svrType = null;/*w w  w. j av  a2s. co m*/
    ServerValue svrVal = null;
    try {
        AppdefEntityTypeID atid = RequestUtils.getChildResourceTypeId(request);

        // parent is a platform, we're creating a platform service
        if (atid.getType() == AppdefEntityConstants.APPDEF_TYPE_SERVER) {
            List<ServerValue> servers = appdefBoss.findServersByTypeAndPlatform(sessionId, parentId,
                    atid.getID(), PageControl.PAGE_ALL);
            // look for the correct server parent
            svrVal = (ServerValue) servers.get(0);
            svrType = svrVal.getServerType();
        } else {
            // Just get the service type
            serviceTypeVals.add(appdefBoss.findServiceTypeById(sessionId, atid.getId()));
            newForm.setResourceType(atid.getId());

            svrVal = appdefBoss.findVirtualServerByPlatformServiceType(sessionId, parentId, atid.getId());
        }
    } catch (ParameterNotFoundException e) {
        if (aeid.getType() == AppdefEntityConstants.APPDEF_TYPE_SERVER) {
            svrVal = appdefBoss.findServerById(sessionId, parentId);
            svrType = svrVal.getServerType();
        } else {
            serviceTypeVals.addAll(appdefBoss.findViewablePlatformServiceTypes(sessionId, aeid.getId()));

        }
    }

    // Set the server value
    request.setAttribute(Constants.PARENT_RESOURCE_ATTR, svrVal);

    if (svrVal != null) {
        newForm.setRid(svrVal.getId());
        newForm.setType(new Integer(AppdefEntityConstants.APPDEF_TYPE_SERVER));
    } else {
        newForm.setRid(aeid.getId());
        newForm.setType(new Integer(aeid.getType()));
    }

    if (svrType != null) {
        List<ServiceTypeValue> serviceTypes = appdefBoss.findServiceTypesByServerType(sessionId,
                svrType.getId().intValue());
        CollectionUtils.addAll(serviceTypeVals, serviceTypes.toArray());
    }

    newForm.setResourceTypes(serviceTypeVals);

    return null;
}

From source file:org.jahia.services.atmosphere.AtmosphereServlet.java

@Override
public void init(final ServletConfig sc) throws ServletException {
    ServletConfig scFacade;/*from ww  w.j a va 2  s . c o  m*/

    String asyncSupport = SettingsBean.getInstance().getAtmosphereAsyncSupport();
    // override asyncSupport only if explicitly set via jahia.properties or not set at all
    if (StringUtils.isNotEmpty(asyncSupport) || sc.getInitParameter(PROPERTY_COMET_SUPPORT) == null) {
        final String implName = StringUtils.defaultIfBlank(asyncSupport, DEFAULT_ASYNC_SUPPORT);
        scFacade = new ServletConfig() {
            @Override
            public String getInitParameter(String name) {
                return PROPERTY_COMET_SUPPORT.equals(name) ? implName : sc.getInitParameter(name);
            }

            @Override
            public Enumeration<String> getInitParameterNames() {
                ArrayList<String> names = Lists.newArrayList(PROPERTY_COMET_SUPPORT);
                CollectionUtils.addAll(names, sc.getInitParameterNames());
                return Collections.enumeration(names);
            }

            @Override
            public ServletContext getServletContext() {
                return sc.getServletContext();
            }

            @Override
            public String getServletName() {
                return sc.getServletName();
            }
        };
    } else {
        scFacade = sc;
    }

    super.init(scFacade);
}

From source file:org.jbpm.instance.migration.Migrator.java

/**
 * /*from w  w  w. jav  a2  s. com*/
 * @param processDefinitionName The name of the ProcessDefinition that this migrator is responsible for.
 * @param jbpmContext A JBPMContext that the migrator can use to look up the latest ProcessDefinition (among other things).
 * @param migrations An arrray of migration instances.
 * @param subProcessMigrators An array of migrator classes for any subprocesses that this Migrator may encounter.
 * @throws InvalidMigrationException
 */
public Migrator(String processDefinitionName, JbpmContext jbpmContext, Migration[] migrations,
        Migrator[] subProcessMigrators) throws InvalidMigrationException {
    this.processDefinitionName = processDefinitionName;
    this.jbpmContext = jbpmContext;

    if (!ArrayUtils.isEmpty(migrations)) {
        CollectionUtils.addAll(this.migrations, migrations);
    }

    for (int i = 0; subProcessMigrators != null && i < subProcessMigrators.length; i++) {
        this.subProcessMigrators.put(subProcessMigrators[i].getProcessDefinitionName(), subProcessMigrators[i]);
    }

    populateCompositeNodeMap();
}