Example usage for org.apache.commons.collections4 MapUtils isNotEmpty

List of usage examples for org.apache.commons.collections4 MapUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 MapUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(final Map<?, ?> map) 

Source Link

Document

Null-safe check if the specified map is not empty.

Usage

From source file:fr.landel.utils.assertor.utils.AssertorMap.java

/**
 * Prepare the next step to validate if the {@link Map} is NOT {@code null}
 * and NOT empty/*from www .  j av  a 2  s.c  o  m*/
 * 
 * <p>
 * precondition: none
 * </p>
 * 
 * @param step
 *            the current step
 * @param message
 *            the message if invalid
 * @param <M>
 *            the {@link Map} type
 * @param <K>
 *            the {@link Map} key elements type
 * @param <V>
 *            the {@link Map} value elements type
 * @return the next step
 */
public static <M extends Map<K, V>, K, V> StepAssertor<M> isNotEmpty(final StepAssertor<M> step,
        final MessageAssertor message) {

    final BiPredicate<M, Boolean> checker = (map, not) -> MapUtils.isNotEmpty(map);

    return new StepAssertor<>(step, checker, false, message, MSG.MAP.EMPTY, true);
}

From source file:io.github.swagger2markup.internal.document.builder.MarkupDocumentBuilder.java

/**
 * Build a generic property table/*w w w  .  j a  v a 2 s .  c o  m*/
 *
 * @param properties                 properties to display
 * @param uniquePrefix               unique prefix to prepend to inline object names to enforce unicity
 * @param definitionDocumentResolver definition document resolver to apply to property type cross-reference
 * @param docBuilder                 the docbuilder do use for output
 * @return a list of inline schemas referenced by some properties, for later display
 */
protected List<ObjectType> buildPropertiesTable(Map<String, Property> properties, String uniquePrefix,
        DefinitionDocumentResolver definitionDocumentResolver, MarkupDocBuilder docBuilder) {
    List<ObjectType> inlineDefinitions = new ArrayList<>();
    List<List<String>> cells = new ArrayList<>();
    List<MarkupTableColumn> cols = Arrays.asList(
            new MarkupTableColumn(NAME_COLUMN).withWidthRatio(3).withHeaderColumn(false)
                    .withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"),
            new MarkupTableColumn(DESCRIPTION_COLUMN).withWidthRatio(11)
                    .withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^11"),
            new MarkupTableColumn(SCHEMA_COLUMN).withWidthRatio(4).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC,
                    ".^4"));
    if (MapUtils.isNotEmpty(properties)) {
        Set<String> propertyNames = toKeySet(properties, config.getPropertyOrdering());
        for (String propertyName : propertyNames) {
            Property property = properties.get(propertyName);
            Type propertyType = PropertyUtils.getType(property, definitionDocumentResolver);

            propertyType = createInlineType(propertyType, propertyName, uniquePrefix + " " + propertyName,
                    inlineDefinitions);

            Object example = PropertyUtils.getExample(config.isGeneratedExamplesEnabled(), property,
                    markupDocBuilder);

            Object defaultValue = PropertyUtils.getDefaultValue(property);

            MarkupDocBuilder propertyNameContent = copyMarkupDocBuilder();
            propertyNameContent.boldTextLine(propertyName, true);
            if (BooleanUtils.isTrue(property.getRequired()))
                propertyNameContent.italicText(FLAGS_REQUIRED.toLowerCase());
            else
                propertyNameContent.italicText(FLAGS_OPTIONAL.toLowerCase());
            if (BooleanUtils.isTrue(property.getReadOnly())) {
                propertyNameContent.newLine(true);
                propertyNameContent.italicText(FLAGS_READ_ONLY.toLowerCase());
            }

            MarkupDocBuilder descriptionContent = copyMarkupDocBuilder();
            String description = defaultString(swaggerMarkupDescription(property.getDescription()));
            if (isNotBlank(description))
                descriptionContent.text(description);
            if (defaultValue != null) {
                if (isNotBlank(description))
                    descriptionContent.newLine(true);
                descriptionContent.boldText(DEFAULT_COLUMN).text(COLON).literalText(Json.pretty(defaultValue));
            }
            if (example != null) {
                if (isNotBlank(description) || defaultValue != null)
                    descriptionContent.newLine(true);
                descriptionContent.boldText(EXAMPLE_COLUMN).text(COLON).literalText(Json.pretty(example));
            }

            List<String> content = Arrays.asList(propertyNameContent.toString(), descriptionContent.toString(),
                    propertyType.displaySchema(docBuilder));
            cells.add(content);
        }
        docBuilder.tableWithColumnSpecs(cols, cells);
    } else {
        docBuilder.textLine(NO_CONTENT);
    }

    return inlineDefinitions;
}

From source file:de.yaio.commons.http.HttpUtils.java

/** 
 * execute POST-Request for url with params
 * @param baseUrl                the url to call
 * @param username               username for auth
 * @param password               password for auth
 * @param params                 params for the request
 * @param textFileParams         text-files to upload
 * @param binFileParams          bin-files to upload
 * @return                       HttpResponse
 * @throws IOException           possible Exception if Request-state <200 > 299 
 *///from   w w w .  j  a va  2  s . c om
public static HttpResponse callPatchUrlPure(final String baseUrl, final String username, final String password,
        final Map<String, String> params, final Map<String, String> textFileParams,
        final Map<String, String> binFileParams) throws IOException {
    // create request
    HttpPatch request = new HttpPatch(baseUrl);

    // map params
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    if (MapUtils.isNotEmpty(params)) {
        for (String key : params.keySet()) {
            builder.addTextBody(key, params.get(key), ContentType.TEXT_PLAIN);
        }
    }

    // map files
    if (MapUtils.isNotEmpty(textFileParams)) {
        for (String key : textFileParams.keySet()) {
            File file = new File(textFileParams.get(key));
            builder.addBinaryBody(key, file, ContentType.DEFAULT_TEXT, textFileParams.get(key));
        }
    }
    // map files
    if (MapUtils.isNotEmpty(binFileParams)) {
        for (String key : binFileParams.keySet()) {
            File file = new File(binFileParams.get(key));
            builder.addBinaryBody(key, file, ContentType.DEFAULT_BINARY, binFileParams.get(key));
        }
    }

    // set request
    HttpEntity multipart = builder.build();
    request.setEntity(multipart);

    // add request header
    request.addHeader("User-Agent", "YAIOCaller");

    // call url
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Sending 'PATCH' request to URL : " + baseUrl);
    }
    HttpResponse response = executeRequest(request, username, password);

    // get response
    int retCode = response.getStatusLine().getStatusCode();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Response Code : " + retCode);
    }
    return response;
}

From source file:io.github.swagger2markup.internal.document.builder.PathsDocumentBuilder.java

/**
 * Converts the Swagger paths into a list PathOperations.
 *
 * @param paths the Swagger paths/*from   w  ww.j  a  v a2 s .com*/
 * @return the path operations
 */
private Set<PathOperation> toPathOperationsSet(Map<String, Path> paths) {
    Set<PathOperation> pathOperations;
    if (config.getOperationOrdering() != null) {
        pathOperations = new TreeSet<>(config.getOperationOrdering());
    } else {
        pathOperations = new LinkedHashSet<>();
    }
    for (Map.Entry<String, Path> path : paths.entrySet()) {
        Map<HttpMethod, Operation> operations = path.getValue().getOperationMap(); // TODO AS_IS does not work because of https://github.com/swagger-api/swagger-core/issues/1696
        if (MapUtils.isNotEmpty(operations)) {
            for (Map.Entry<HttpMethod, Operation> operation : operations.entrySet()) {
                pathOperations.add(new PathOperation(operation.getKey(), path.getKey(), operation.getValue()));
            }
        }
    }
    return pathOperations;
}

From source file:com.kumarvv.setl.core.Loader.java

/**
 * returns columnValue from Row, Value or Sql
 * also processes system variables/*from  ww w.  ja va2s. com*/
 *
 * @param load
 * @param row
 * @param column
 * @return
 */
protected Object getColumnValue(Load load, Row row, Column column) {
    if (load == null || column == null) {
        return null;
    }

    Object val = null;
    if (isNotEmpty(column.getValue())) {
        val = column.getValue();
    } else if (isNotEmpty(column.getRef()) && row != null && MapUtils.isNotEmpty(row.getData())) {
        val = row.get(column.getRef());
    } else if (isNotEmpty(column.getSql()) && row != null && MapUtils.isNotEmpty(row.getData())) {
        String sql = interpolator.interpolate(column.getSql(), row.getData());
        val = sqlRunner.getSingleValue(sql, def.getToDS());
    }

    if (val == null) {
        return null;
    }
    val = systemVar.process(val);

    SqlType sqlType = SqlType.forValue(load.getToColumnType(column.getName()));
    if (sqlType != null) {
        return sqlType.convert(val);
    }
    return val.toString();
}

From source file:fr.landel.utils.assertor.utils.AssertorMap.java

private static <M extends Map<K, V>, K, V> StepAssertor<M> match(final StepAssertor<M> step,
        final Predicate<Entry<K, V>> predicate, final boolean all, final String messageKey,
        final MessageAssertor message) {

    final Predicate<M> preChecker = (map) -> MapUtils.isNotEmpty(map) && predicate != null;

    final BiPredicate<M, Boolean> checker = (object, not) -> AssertorMap.match(object, predicate, all,
            step.getAnalysisMode());/*from   w  w  w . java2  s.c  o  m*/

    return new StepAssertor<>(step, preChecker, checker, false, message, messageKey, false,
            new ParameterAssertor<>(predicate, EnumType.UNKNOWN));
}

From source file:com.kumarvv.setl.core.Loader.java

/**
 * initialize load TO columns - from datasource if not found already
 *
 * @param load//from  w w w .  ja v a 2 s. c  o m
 * @param jrs
 */
protected void initLoadToColumns(Load load, JdbcRowSet jrs) {
    if (load == null || MapUtils.isNotEmpty(load.getToColumns())) {
        return;
    }
    Map<String, Integer> mcs = rowSetUtil.getMetaColumns(jrs);
    Map<String, Integer> lcs = new HashMap<>();
    for (String c : MapUtils.emptyIfNull(mcs).keySet()) {
        lcs.put(c, mcs.get(c));
    }
    load.setToColumns(lcs);
}

From source file:io.cloudslang.lang.systemtests.EventDataTest.java

private void validateSensitiveDataNotReveiledInContext(List<ScoreEvent> events) {
    for (ScoreEvent scoreEvent : events) {
        LanguageEventData eventDataAsMap = getData(scoreEvent);
        Map<String, Serializable> context = eventDataAsMap.getContext();
        if (MapUtils.isNotEmpty(context)) {
            for (Serializable value : context.values()) {
                if (value.toString().contains(SENSITIVE_VALUE_STRING)) {
                    fail(SENSITIVE_VALUE_STRING + " string should not be in event data");
                }//from   ww w .  j  a v  a2 s .  co m
            }
        }
    }
}

From source file:com.jkoolcloud.tnt4j.streams.utils.StreamsCache.java

private static void loadPersisted() {
    try {/*from w w  w. j  av a  2  s.  c  om*/
        JAXBContext jc = JAXBContext.newInstance(CacheRoot.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        File persistedFile = new File(DEFAULT_FILE_NAME);
        LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                "StreamsCache.loading.file", persistedFile.getAbsolutePath());
        if (!persistedFile.exists()) {
            LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                    "StreamsCache.loading.file.not.found");
            return;
        }

        CacheRoot root = (CacheRoot) unmarshaller.unmarshal(persistedFile);

        Map<String, CacheValue> mapProperty = root.getEntriesMap();
        if (MapUtils.isNotEmpty(mapProperty)) {
            for (Map.Entry<String, CacheValue> entry : mapProperty.entrySet()) {
                valuesCache.put(entry.getKey(), entry.getValue());
            }
        }
        LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                "StreamsCache.loading.done", mapProperty == null ? 0 : mapProperty.size(),
                persistedFile.getAbsolutePath());
    } catch (JAXBException exc) {
        Utils.logThrowable(LOGGER, OpLevel.ERROR,
                StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                "StreamsCache.loading.failed", exc);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivitySyslogEventParser.java

/**
 * Extract Syslog structured data if available (part of RFC 5424).
 *
 * @param sMessage//  w  w  w  .  ja va2 s .c o m
 *            Syslog structured message
 * @param dataMap
 *            log entry fields map to update
 * @return map of structured Syslog message data
 */
protected static Map<String, Map<String, String>> extractStructuredData(StructuredSyslogMessage sMessage,
        Map<String, Object> dataMap) {
    Map<String, Map<String, String>> map = sMessage.getStructuredData();
    if (MapUtils.isNotEmpty(map)) {
        // PropertySnapshot snap = new PropertySnapshot(FIELD_SYSLOG_MAP,
        // sEvent.getApplicationName(),
        // (OpLevel) dataMap.get(Severity.name()));
        // snap.addAll(map);
        dataMap.put(FIELD_SYSLOG_MAP, map);
    }
    return map;
}