Example usage for org.apache.commons.collections OrderedMapIterator getValue

List of usage examples for org.apache.commons.collections OrderedMapIterator getValue

Introduction

In this page you can find the example usage for org.apache.commons.collections OrderedMapIterator getValue.

Prototype

Object getValue();

Source Link

Document

Gets the current value, which is the value associated with the last key returned by next().

Usage

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.QueryValuesLoader.java

@Override
public List<ListOfValuesItem> loadValues(InputControl inputControl, ResourceReference dataSource,
        Map<String, Object> parameters, Map<String, Class<?>> parameterTypes,
        ReportInputControlInformation info) throws CascadeResourceNotFoundException {
    List<ListOfValuesItem> result = null;
    ResourceReference dataSourceForQuery = resolveDatasource(inputControl, dataSource);
    final Query query = cachedRepositoryService.getResource(Query.class, inputControl.getQuery());

    Map<String, Object> domainSchemaParameters = new HashMap<String, Object>();

    //TODO Extract this parameter extension to separate interface
    prepareDomainDataSource(dataSourceForQuery, domainSchemaParameters);

    Map<String, Object> executionParameters = filterAndFillMissingQueryParameters(query, parameters,
            domainSchemaParameters);//from  w ww . ja v a 2s. c  om
    Map<String, Class<?>> executionParameterTypes = filterParameterTypes(executionParameters.keySet(),
            parameterTypes);

    if (parameters != null && parameters.containsKey(EhcacheEngineService.IC_REFRESH_KEY)) {
        executionParameters.put(EhcacheEngineService.IC_REFRESH_KEY, "true");
    }

    /* Typed results are returned */
    OrderedMap results = cachedEngineService.executeQuery(ExecutionContextImpl.getRuntimeExecutionContext(),
            inputControl.getQuery(), inputControl.getQueryValueColumn(), inputControl.getQueryVisibleColumns(),
            dataSourceForQuery, executionParameters, executionParameterTypes, inputControl.getName());

    if (results != null) {
        OrderedMapIterator it = results.orderedMapIterator();
        while (it.hasNext()) {
            if (result == null)
                result = new ArrayList<ListOfValuesItem>(results.size());
            Object valueColumn = it.next();
            Object[] visibleColumns = (Object[]) it.getValue();

            StringBuilder label = new StringBuilder();
            for (int i = 0; i < visibleColumns.length; i++) {
                Object visibleColumn = visibleColumns[i];
                String visibleColumnName = inputControl.getQueryVisibleColumns()[i];
                boolean isVisibleColumnMatchesValueColumn = inputControl.getQueryValueColumn()
                        .equals(visibleColumnName);

                if (label.length() > 0) {
                    label.append(COLUMN_VALUE_SEPARATOR);
                }

                String formattedValue = formatValueToString(visibleColumn, isVisibleColumnMatchesValueColumn,
                        inputControl, info);
                label.append(
                        visibleColumn != null ? formattedValue : InputControlHandler.NULL_SUBSTITUTION_LABEL);
            }
            ListOfValuesItem item = new ListOfValuesItemImpl();
            item.setLabel(label.toString());
            if (valueColumn instanceof BigDecimal) {
                valueColumn = ((BigDecimal) valueColumn).stripTrailingZeros();
            }
            item.setValue(valueColumn);
            result.add(item);
        }
    }
    return result;
}

From source file:com.naryx.tagfusion.cfm.tag.ext.cfTHROTTLE.java

public cfTagReturnType render(cfSession _Session) throws cfmRunTimeException {

    if (actionType == ACTION_THROTTLE) {

        //-- Determine the token; if not present then use the clients remote IP address
        String token;//  w  ww.ja v a2s . c  om
        if (containsAttribute("TOKEN"))
            token = getDynamic(_Session, "TOKEN").getString();
        else
            token = _Session.REQ.getRemoteAddr();

        int hitThresHold = getDynamic(_Session, "HITTHRESHOLD").getInt();
        long hitTimePeriodMs = getDynamic(_Session, "HITTIMEPERIOD").getLong();
        long hitMinTimeMs = getDynamic(_Session, "MINHITTIME").getLong();

        throttleClient client;
        cfStructData result = new cfStructData();

        synchronized (throttleHistory) {
            client = (throttleClient) throttleHistory.get(token);
            if (client == null) {
                client = new throttleClient(token);
                throttleHistory.put(token, client);
            }
        }

        //-- Synchronize on this client
        synchronized (client) {
            long lasthit = client.lastHit();
            long age = client.age();

            totalHit++;
            client.hit(); //-- Register this hit

            if (age <= hitTimePeriodMs && client.hitCount >= hitThresHold) { //- checks to make sure they are within their allocated amount
                result.put("THROTTLE", cfBooleanData.TRUE);
                client.throttled();
                totalThrottled++;
            } else if (lasthit > 10 && lasthit < hitMinTimeMs) { //-- checks for too fast accesses between requests
                result.put("THROTTLE", cfBooleanData.TRUE);
                client.throttled();
                totalThrottled++;
                totalThrottledQuick++;
            } else
                result.put("THROTTLE", cfBooleanData.FALSE);

            //-- If the age of this entry has expired then reset it.
            if (age > hitTimePeriodMs)
                client.reset();

            //-- Set the data into the session
            result.setData("HITCOUNT", new cfNumberData(client.hitCount));
            result.setData("TOTALHITS", new cfNumberData(client.totalHits));
            result.setData("LASTHIT", new cfNumberData(lasthit));
            result.setData("AGE", new cfNumberData(age));

        }

        _Session.setData("CFTHROTTLE", result);

    } else if (actionType == ACTION_SET) {

        //-- Check to see if the history length has changed or been passed in
        if (containsAttribute("HISTORY")) {
            throttleHistory = new LRUMap(getDynamic(_Session, "HISTORY").getInt());
        }

    } else if (actionType == ACTION_FLUSH) {

        //-- Clears out the history
        synchronized (throttleHistory) {
            throttleHistory.clear();
        }

    } else if (actionType == ACTION_STATUS) {

        cfArrayData array = cfArrayData.createArray(1);

        synchronized (throttleHistory) {
            org.apache.commons.collections.OrderedMapIterator it = throttleHistory.orderedMapIterator();
            throttleClient client;
            cfStructData clientData;

            while (it.hasNext()) {
                it.next();
                client = (throttleClient) it.getValue();

                clientData = new cfStructData();

                clientData.setData("TOKEN", new cfStringData(client.token));
                clientData.setData("HIT", new cfNumberData(client.hitCount));
                clientData.setData("TOTALHITS", new cfNumberData(client.totalHits));
                clientData.setData("TOTALTHROTTLE", new cfNumberData(client.totalThrottled));
                clientData.setData("THROTTLE", new cfNumberData(client.throttled));
                clientData.setData("LASTHIT", new cfDateData(client.lastUsed));
                clientData.setData("AGE", new cfNumberData(client.age()));

                array.addElement(clientData);
            }
        }

        cfStructData throttle = new cfStructData();
        throttle.setData("CLIENTS", array);
        throttle.setData("HITS", new cfNumberData(totalHit));
        throttle.setData("THROTTLE", new cfNumberData(totalThrottled));
        throttle.setData("QUICKTHROTTLE", new cfNumberData(totalThrottledQuick));
        throttle.setData("STARTTIME", new cfDateData(startTime));

        _Session.setData("CFTHROTTLE", throttle);
    }

    return cfTagReturnType.NORMAL;
}

From source file:org.apache.torque.util.SummaryHelper.java

/**
 * Builds the criteria to use in summarizing the information.  Note that
 * the criteria passed in will be modified.
 *
 * @param c The base criteria to build the summary criteria from.
 * @return A criteria to use in summarizing the information.
 * @throws TorqueException//from   ww  w. j  av a  2s . c o  m
 *
 * @deprecated please use
 *             buildCriteria(org.apache.torque.criteria.Criteria)
 *             instead.
 *             This method will be removed in a future version of Torque.
 */
@Deprecated
public Criteria buildCriteria(Criteria c) throws TorqueException {
    c.getSelectColumns().clear();
    c.getGroupByColumns().clear();

    UniqueList<String> criteriaSelectModifiers;
    criteriaSelectModifiers = c.getSelectModifiers();

    if (criteriaSelectModifiers != null && criteriaSelectModifiers.size() > 0
            && criteriaSelectModifiers.contains(SqlEnum.DISTINCT.toString())) {
        criteriaSelectModifiers.remove(SqlEnum.DISTINCT.toString());
    }
    c.setIgnoreCase(false);

    List<Column> cols = getGroupByColumns();
    boolean haveFromTable = !cols.isEmpty(); // Group By cols define src table.
    for (Column col : cols) {
        c.addGroupByColumn(col);
        c.addSelectColumn(col);
    }
    if (haveFromTable) {
        logger.debug("From table defined by Group By Cols");
    }

    // Check if the from table is set via a where clause.
    if (!haveFromTable && !c.isEmpty()) {
        haveFromTable = true;
        logger.debug("From table defined by a where clause");
    }

    ListOrderedMapCI cMap = getAggregates();
    OrderedMapIterator iMap = cMap.orderedMapIterator();
    while (iMap.hasNext()) {
        String key = (String) iMap.next();
        SQLFunction f = (SQLFunction) iMap.getValue();
        Column col = f.getColumn();
        c.addAsColumn(key, new ColumnImpl(null, col.getTableName(), col.getColumnName(), f.getSqlExpression()));
        if (!haveFromTable) // Last chance. Get it from the func.
        {
            {
                // Kludgy Where table.col = table.col clause to force
                // from table identification.
                c.add(col, (col.getColumnName() + "=" + col.getColumnName()), SqlEnum.CUSTOM);
                haveFromTable = true;

                String table = col.getTableName();
                logger.debug("From table, '" + table + "', defined from aggregate column");
            }
        }
    }
    if (!haveFromTable) {
        throw new TorqueException("No FROM table defined by the GroupBy set, "
                + "criteria.setAlias, or specified function column!");
    }
    return c;
}

From source file:org.apache.torque.util.SummaryHelper.java

/**
 * Builds the criteria to use in summarizing the information.  Note that
 * the criteria passed in will be modified.
 *
 * @param c The base criteria to build the summary criteria from.
 * @return A criteria to use in summarizing the information.
 * @throws TorqueException/*  w ww  .  j  ava 2s.  c om*/
 */
public org.apache.torque.criteria.Criteria buildCriteria(org.apache.torque.criteria.Criteria c)
        throws TorqueException {
    c.getSelectColumns().clear();
    c.getGroupByColumns().clear();

    UniqueList<String> criteriaSelectModifiers;
    criteriaSelectModifiers = c.getSelectModifiers();

    if (criteriaSelectModifiers != null && criteriaSelectModifiers.size() > 0
            && criteriaSelectModifiers.contains(SqlEnum.DISTINCT.toString())) {
        criteriaSelectModifiers.remove(SqlEnum.DISTINCT.toString());
    }
    c.setIgnoreCase(false);

    List<Column> cols = getGroupByColumns();
    boolean haveFromTable = !cols.isEmpty(); // Group By cols define src table.
    for (Column col : cols) {
        c.addGroupByColumn(col);
        c.addSelectColumn(col);
    }
    if (haveFromTable) {
        logger.debug("From table defined by Group By Cols");
    }

    // Check if the from table is set via a where clause.
    if (!haveFromTable && c.getTopLevelCriterion() != null) {
        haveFromTable = true;
        logger.debug("From table defined by a where clause");
    }

    ListOrderedMapCI cMap = getAggregates();
    OrderedMapIterator iMap = cMap.orderedMapIterator();
    while (iMap.hasNext()) {
        String key = (String) iMap.next();
        SQLFunction f = (SQLFunction) iMap.getValue();
        Column col = f.getColumn();
        c.addAsColumn(key, new ColumnImpl(null, col.getTableName(), col.getColumnName(), f.getSqlExpression()));
        if (!haveFromTable) // Last chance. Get it from the func.
        {
            {
                // Kludgy Where table.col = table.col clause to force
                // from table identification.
                c.and(col, (col.getColumnName() + "=" + col.getColumnName()), SqlEnum.CUSTOM);
                haveFromTable = true;

                String table = col.getTableName();
                logger.debug("From table, '" + table + "', defined from aggregate column");
            }
        }
    }
    if (!haveFromTable) {
        throw new TorqueException("No FROM table defined by the GroupBy set, "
                + "criteria.setAlias, or specified function column!");
    }
    return c;
}

From source file:org.apache.torque.util.SummaryHelper.java

/**
 * Convenience method to dump a summary results list to an output writer
 * in a semi-CSV format. E.g., there is no handling of embedded
 * quotes/special characters.//from   w  w w.jav  a2s.  co m
 *
 * @param out
 * @param results
 * @param includeHeader
 * @throws IOException
 */
public void dumpResults(Writer out, List<?> results, boolean includeHeader) throws IOException {
    Iterator<?> i = results.iterator();
    boolean first = includeHeader;

    while (i.hasNext()) {
        ListOrderedMapCI rec = (ListOrderedMapCI) i.next();
        OrderedMapIterator rI = rec.orderedMapIterator();
        StringBuilder heading = new StringBuilder();
        StringBuilder recString = new StringBuilder();
        while (rI.hasNext()) {
            String colId = (String) rI.next();
            if (first) {
                heading.append("\"").append(colId).append("\"");
                if (rI.hasNext()) {
                    heading.append(", ");
                }
            }
            Object v = rI.getValue();
            recString.append(v.toString());
            if (rI.hasNext()) {
                recString.append(", ");
            }
        }
        if (first) {
            first = false;
            out.write(heading.toString());
            out.write("\n");
        }
        out.write(recString.toString());
        out.write("\n");
    }
}

From source file:oscar.oscarEncounter.oscarMeasurements.MeasurementFlowSheet.java

public void loadRuleBase() {
    log.debug("LOADRULEBASE == " + name);
    ArrayList<Element> dsElements = new ArrayList<Element>();

    if (itemList != null) {
        OrderedMapIterator iter = itemList.orderedMapIterator();
        while (iter.hasNext()) {
            String key = (String) iter.next(); //returns the key not the value.  Needed to advance the iterator
            FlowSheetItem fsi = (FlowSheetItem) iter.getValue();
            List<Recommendation> rules = fsi.getRecommendations();
            if (rules != null) {
                log.debug("# OF RULES FOR " + fsi.getItemName() + " " + rules.size() + " key " + key);
                for (Object obj : rules) {
                    Recommendation rec = (Recommendation) obj;
                    dsElements.add(rec.getRuleBaseElement());
                }/*  w w w  . ja  va 2  s  .c o m*/
            } else {
                log.debug("NO RULES FOR " + fsi.getItemName());
            }

        }
    }
    log.debug("LOADING RULES2" + name + " size + " + dsElements.size() + " rulebase " + ruleBase);
    if (dsElements != null && dsElements.size() > 0) {

        log.debug("LOADING RULES21" + dsElements.size());
        RuleBaseCreator rcb = new RuleBaseCreator();
        try {

            log.debug("LOADING RULES22");
            ruleBase = rcb.getRuleBase("rulesetName", dsElements);
            log.debug("LOADING RULES23");
            rulesLoaded = true;
        } catch (Exception e) {
            log.debug("LOADING EXEPTION");

            MiscUtils.getLogger().error("Error", e);
        }
    } else {
        //empty
    }
}