Example usage for org.springframework.util StringUtils collectionToDelimitedString

List of usage examples for org.springframework.util StringUtils collectionToDelimitedString

Introduction

In this page you can find the example usage for org.springframework.util StringUtils collectionToDelimitedString.

Prototype

public static String collectionToDelimitedString(@Nullable Collection<?> coll, String delim) 

Source Link

Document

Convert a Collection into a delimited String (e.g.

Usage

From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java

private boolean verifyAttributesExist(PrefabGraph query, String type, List<String> requiredList,
        Set<String> availableRrdAttributes) {
    if (availableRrdAttributes.containsAll(requiredList)) {
        return true;
    } else {/*from   w  w w .  ja  va2  s .  c om*/
        LOG.debug(
                "not adding {} to prefab graph list because the required list of {} attributes ({}) is not in the list of {} attributes on the resource ({})",
                query.getName(), type, StringUtils.collectionToDelimitedString(requiredList, ", "), type,
                StringUtils.collectionToDelimitedString(availableRrdAttributes, ", "));
        return false;
    }
}

From source file:no.dusken.momus.controller.DevController.java

@RequestMapping("/test2")
public @ResponseBody List<Source> test22() {
    String baseQuery = "select distinct s from Source s";

    List<String> conditions = new ArrayList<>();
    Map<String, String> params = new HashMap<>();

    if (true) {/*w  ww  . j  a  v a 2 s  .  c om*/
        conditions.add("s.name like :name");
        params.put("name", "%Mats%");
    }

    if (true) {
        conditions.add("s.email like :email");
        params.put("email", "mats.svensson@gmail.rart.com");
    }

    String conditionsString = StringUtils.collectionToDelimitedString(conditions, " AND ");
    String fullQuery;

    if (conditionsString.equals("")) {
        fullQuery = baseQuery;
    } else {
        fullQuery = baseQuery + " WHERE " + conditionsString;
    }

    logger.debug(fullQuery);

    TypedQuery<Source> query = entityManager.createQuery(fullQuery, Source.class);

    for (Map.Entry<String, String> e : params.entrySet()) {
        query.setParameter(e.getKey(), e.getValue());
    }

    //        query.setFirstResult(1);
    //        query.setMaxResults(2);

    return query.getResultList();
}

From source file:com.netflix.genie.web.controllers.Snippets.java

private static Attributes.Attribute getConstraintsForField(final ConstraintDescriptions constraints,
        final String fieldName) {
    return Attributes.key(CONSTRAINTS).value(
            StringUtils.collectionToDelimitedString(constraints.descriptionsForProperty(fieldName), ". "));
}

From source file:de.ecm4u.alfresco.bugpatches.org.alfresco.web.scripts.forms.FormUIGet.java

/**
 * Processes the given constraint to ensure the field's control
 * adheres to the constraint.//  w w w. j  a v  a 2  s  .com
 * 
 * @param context The context
 * @param field The field to be processed
 * @param fieldConfig The configuration of the field to be processed
 * @param constraint The constraint
 * @throws JSONException
 */
protected void processFieldConstraintControl(ModelContext context, Field field, FormField fieldConfig,
        Constraint constraint) throws JSONException {
    // process special constraint behaviour
    if (CONSTRAINT_LIST.equals(constraint.getId())) {
        // if the constraint is the list of values constraint, force the control
        // template to be selectone.ftl or selectmany.ftl depending on whether
        // the field has multiple values, but only if an overridden control has
        // not been supplied
        if (fieldConfig == null || fieldConfig.getControl() == null
                || fieldConfig.getControl().getTemplate() == null) {
            if (field.isRepeating()) {
                field.getControl().setTemplate(CONTROL_SELECT_MANY);
            } else {
                field.getControl().setTemplate(CONTROL_SELECT_ONE);
            }
        }

        // setup the options string and set as control params, but only if the control
        // does not already have an "options" parameter
        if (field.getControl().getParams().containsKey(CONTROL_PARAM_OPTIONS) == false) {
            JSONArray options = constraint.getJSONParams().getJSONArray("allowedValues");
            List<String> optionsList = new ArrayList<String>(options.length());
            for (int x = 0; x < options.length(); x++) {
                optionsList.add(options.getString(x));
            }

            // Sort the options based on the label...
            if (fieldConfig != null && fieldConfig.isSorted()) {
                Collections.sort(optionsList, new OptionsComparator());
            }

            // ALF-7961: don't use a comma as the list separator
            field.getControl().getParams().put(CONTROL_PARAM_OPTIONS,
                    StringUtils.collectionToDelimitedString(optionsList, DELIMITER));
            field.getControl().getParams().put(CONTROL_PARAM_OPTION_SEPARATOR, DELIMITER);
        }
    } else if (CONSTRAINT_LENGTH.equals(constraint.getId())) {
        int maxLength = -1;
        if (constraint.getJSONParams().has(MODEL_MAX_LENGTH)) {
            maxLength = constraint.getJSONParams().getInt(MODEL_MAX_LENGTH);
        }

        // if the constraint is the length constraint, pass the maxLength
        // parameter to the control if appropriate
        if (maxLength != -1) {
            field.getControl().getParams().put("maxLength", Integer.toString(maxLength));

            // set the crop argument to true so that textareas also restrict characters 
            constraint.getJSONParams().put("crop", true);
        }
    } else if (CONSTRAINT_REGEX.equals(constraint.getId())) {
        // if the cm:name property is being processed switch the validation handler
        // to the JavaScript specific nodeName handler.
        if (CM_NAME_PROP.equals(field.getName())) {
            constraint.setValidationHandler(CONSTRAINT_FILE_NAME_HANDLER);
            constraint.setJSONParams(new JSONObject());
        }
    }
}

From source file:com.ut.healthelink.service.impl.transactionInManagerImpl.java

@Override
public Integer processMultiValueCWData(Integer configId, Integer batchId, configurationDataTranslations cdt,
        List<CrosswalkData> cwdList, boolean foroutboundProcessing, Integer transactionId) {
    try {//from   www. ja v  a2 s  .c om
        Integer error = 0;
        List<IdAndFieldValue> idAndValues = getIdAndValuesForConfigField(configId, batchId, cdt,
                foroutboundProcessing, transactionId);
        //we turn cwdList into a map
        Map<String, String> cwMap = new HashMap<String, String>();
        for (CrosswalkData cw : cwdList) {
            cwMap.put(cw.getSourceValue(), cw.getTargetValue());
        }

        //1. we get list of ids for field
        for (IdAndFieldValue idAndValue : idAndValues) {
            Integer invalidCount = 0;
            Integer blankListLength = 0;
            List<String> values = new ArrayList<String>();

            List<String> fieldValues = Arrays.asList(idAndValue.getFieldValue().split("\\^\\^\\^\\^\\^", -1));
            //we loop through value and compare to cw
            for (String fieldValue : fieldValues) {
                //sometimes user need to pass blank list, should not be count as an error
                if (cwMap.containsKey(fieldValue.trim())) {
                    values.add(cwMap.get(fieldValue.trim()));
                } else {
                    //we pass value
                    if (cdt.getPassClear() == 1) {
                        values.add(fieldValue.trim());
                        invalidCount = invalidCount + 1;
                        if (fieldValue.trim().length() != 0) {
                            blankListLength = blankListLength + 1;
                        }
                    }
                }
            }

            String newValue = StringUtils.collectionToDelimitedString(values, "^^^^^");
            error = updateFieldValue(newValue, cdt.getFieldNo(), idAndValue.getTransactionId(),
                    foroutboundProcessing);

            //we insert error if no valid values were replaced
            if (invalidCount > 0 && blankListLength > 0) {
                insertProcessingError(3, cdt.getconfigId(), batchId, cdt.getFieldNo(), null,
                        cdt.getCrosswalkId(), null, false, foroutboundProcessing, "",
                        idAndValue.getTransactionId());
            }
        }

        return error;
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("processMultiValueCWData " + ex.toString());
        return 1;

    }

}

From source file:com.wavemaker.studio.StudioService.java

private String tail(File file, int maxSize) throws IOException {
    List<String> lines = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(file.getContent().asReader());
    try {//from  w ww .  java  2s  .c o  m
        String line = reader.readLine();
        while (line != null) {
            lines.add(line);
            if (lines.size() > maxSize) {
                lines.remove(0);
            }
            line = reader.readLine();
        }
        return StringUtils.collectionToDelimitedString(lines, "\n");
    } finally {
        reader.close();
    }
}

From source file:de.escalon.hypermedia.spring.Affordance.java

public String asHeader() {
    StringBuilder result = new StringBuilder();
    for (Map.Entry<String, List<String>> linkParamEntry : linkParams.entrySet()) {
        if (result.length() != 0) {
            result.append("; ");
        }/*from  w  w  w  . ja  va2 s  .  c  om*/
        if ("rel".equals(linkParamEntry.getKey())) {
            result.append(linkParamEntry.getKey()).append("=");
            result.append("\"").append(StringUtils.collectionToDelimitedString(linkParamEntry.getValue(), " "))
                    .append("\"");
        } else {
            StringBuilder linkParams = new StringBuilder();
            for (String value : linkParamEntry.getValue()) {
                if (linkParams.length() != 0) {
                    linkParams.append("; ");
                }
                linkParams.append(linkParamEntry.getKey()).append("=");
                linkParams.append("\"").append(value).append("\"");
            }
            result.append(linkParams);

        }

    }

    String linkHeader = "<" + getHref() + ">; ";

    return result.insert(0, linkHeader).toString();
}

From source file:de.uzk.hki.da.grid.IrodsGridFacade.java

/**
 * Start replications.//from   w w w .  ja  va2  s .c  o  m
 *
 * @param file the file
 * @param targetLogically the target logically
 * @param gridfile the gridfile
 * @return true, if successful
 * @author Jens Peters
 * @author Daniel M. de Oliveira
 */

private boolean startReplications(File file, String targetLogically, File gridfile, StoragePolicy sp) {
    logger.debug("starting replications for " + targetLogically);
    List<String> targetResgroups = Arrays.asList(sp.getReplDestinations().split(","));
    irodsSystemConnector.saveOrUpdateAVUMetadataDataObject(targetLogically, "replicate_to",
            sp.getReplDestinations().replace("cp_", ""));
    String srcResc = sp.getWorkingResource();
    if (sp.getWorkingResource() == null)
        srcResc = irodsSystemConnector.getDefaultStorage();
    logger.debug("Starting threads for Replication to "
            + StringUtils.collectionToDelimitedString(targetResgroups, "|") + " from " + srcResc);

    Thread re = new ReplicationExecutor(irodsSystemConnector, targetLogically, sp, srcResc);
    re.start();
    return true;
}

From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java

protected void addWhereClauses(final StringBuilder query, final Collection<Filter> filters) {
    final List<String> whereSql = new ArrayList<String>();

    if (!CollectionUtils.isEmpty(baseWhereClauses)) {
        whereSql.addAll(baseWhereClauses);
    }/*from  www.ja  va2  s  . c  om*/

    if (!CollectionUtils.isEmpty(filters)) {
        for (final Filter filter : filters) {
            final String sqlSnippet = ((SqlGeneratingFilter) filter).getSqlSnippet(this);
            if (sqlSnippet != null) {
                whereSql.add(sqlSnippet);
            }
        }
    }

    if (!CollectionUtils.isEmpty(whereSql)) {
        query.append(" WHERE ");
        query.append(StringUtils.collectionToDelimitedString(whereSql, " AND "));
    }
}

From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java

protected void addHavingClauses(final StringBuilder query) {
    if (!CollectionUtils.isEmpty(baseHavingClauses)) {
        query.append(" HAVING ");
        query.append(StringUtils.collectionToDelimitedString(baseHavingClauses, " AND "));
    }//from   w w  w . j  a  v  a  2s  .c  o m
}