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:com.mirth.connect.plugins.httpauth.RequestInfo.java

public void populateMap(Map<String, Object> map) {
    map.put("remoteAddress", remoteAddress);
    map.put("remotePort", remotePort);
    map.put("localAddress", localAddress);
    map.put("localPort", localPort);
    map.put("protocol", protocol);
    map.put("method", method);
    map.put("uri", requestURI);
    map.put("headers", new MessageHeaders(headers));
    map.put("parameters", new MessageParameters(queryParameters));

    if (MapUtils.isNotEmpty(extraProperties)) {
        map.putAll(extraProperties);//from   w  ww.jav a 2 s  .c  o m
    }
}

From source file:com.haulmont.cuba.desktop.sys.JXErrorPaneExt.java

private void sendSupportEmail(ErrorInfo jXErrorPaneInfo) {

    Configuration configuration = AppBeans.get(Configuration.NAME);
    ExceptionReportService reportService = AppBeans.get(ExceptionReportService.NAME);
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    TopLevelFrame mainFrame = App.getInstance().getMainFrame();
    Messages messages = AppBeans.get(Messages.NAME);
    Locale locale = App.getInstance().getLocale();

    try {/*from   w  w  w.j  av  a 2  s .c o  m*/
        TimeSource timeSource = AppBeans.get(TimeSource.NAME);
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timeSource.currentTimestamp());

        UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
        User user = userSessionSource.getUserSession().getUser();

        Map<String, Object> binding = new HashMap<>();
        binding.put("timestamp", date);
        binding.put("errorMessage", jXErrorPaneInfo.getBasicErrorMessage());
        binding.put("stacktrace", getStackTrace(jXErrorPaneInfo.getErrorException()));
        binding.put("systemId", clientConfig.getSystemID());
        binding.put("userLogin", user.getLogin());

        if (MapUtils.isNotEmpty(additionalExceptionReportBinding)) {
            binding.putAll(additionalExceptionReportBinding);
        }

        reportService.sendExceptionReport(clientConfig.getSupportEmail(), MapUtils.unmodifiableMap(binding));

        mainFrame.showNotification(messages.getMainMessage("errorPane.emailSent", locale),
                Frame.NotificationType.TRAY);
    } catch (Throwable e) {
        mainFrame.showNotification(messages.getMainMessage("errorPane.emailSendingErr", locale),
                Frame.NotificationType.ERROR);
    }
}

From source file:io.cloudslang.lang.cli.services.SyncTriggerEventListener.java

public static Map<String, Serializable> extractNotEmptyOutputs(Map<String, Serializable> data) {

    Map<String, Serializable> originalOutputs = (Map<String, Serializable>) data.get(LanguageEventData.OUTPUTS);
    Map<String, Serializable> extractedOutputs = new HashMap<>();

    if (MapUtils.isNotEmpty(originalOutputs)) {
        for (Map.Entry<String, Serializable> output : originalOutputs.entrySet()) {
            if (output.getValue() != null && !(StringUtils.isEmpty(output.getValue().toString()))) {
                extractedOutputs.put(output.getKey(),
                        StringUtils.abbreviate(output.getValue().toString(), 0, OUTPUT_VALUE_LIMIT));
            }/*  www .j  a  va2 s  .c  om*/
        }
        return extractedOutputs;
    }
    return new HashMap<>();
}

From source file:io.cloudslang.lang.cli.SlangCli.java

@CliCommand(value = "run", help = RUN_HELP)
public String run(@CliOption(key = { "", "f", "file" }, mandatory = true, help = FILE_HELP) final File file,
        @CliOption(key = { "cp",
                "classpath" }, mandatory = false, help = CLASSPATH_HELP) final List<String> classPath,
        @CliOption(key = { "i",
                "inputs" }, mandatory = false, help = INPUTS_HELP) final Map<String, ? extends Serializable> inputs,
        @CliOption(key = { "if",
                "input-file" }, mandatory = false, help = INPUT_FILE_HELP) final List<String> inputFiles,
        @CliOption(key = { "v",
                "verbose" }, mandatory = false, help = "default, quiet, debug(print each step outputs). e.g. run --f c:/.../your_flow.sl --v quiet", specifiedDefaultValue = "debug", unspecifiedDefaultValue = "default") final String verbose,
        @CliOption(key = { "spf",
                "system-property-file" }, mandatory = false, help = SYSTEM_PROPERTY_FILE_HELP) final List<String> systemPropertyFiles) {

    if (invalidVerboseInput(verbose)) {
        throw new IllegalArgumentException("Verbose argument is invalid.");
    }// ww w.  j av  a  2s .com

    CompilationArtifact compilationArtifact = compilerHelper.compile(file.getAbsolutePath(), classPath);
    Set<SystemProperty> systemProperties = compilerHelper.loadSystemProperties(systemPropertyFiles);
    Map<String, Value> inputsFromFile = compilerHelper.loadInputsFromFile(inputFiles);
    Map<String, Value> mergedInputs = new HashMap<>();

    if (MapUtils.isNotEmpty(inputsFromFile)) {
        mergedInputs.putAll(inputsFromFile);
    }
    if (MapUtils.isNotEmpty(inputs)) {
        mergedInputs.putAll(io.cloudslang.lang.entities.utils.MapUtils.convertMapNonSensitiveValues(inputs));
    }
    boolean quiet = QUIET.equalsIgnoreCase(verbose);
    boolean debug = DEBUG.equalsIgnoreCase(verbose);

    Long id;
    if (!triggerAsync) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        id = scoreServices.triggerSync(compilationArtifact, mergedInputs, systemProperties, quiet, debug);
        stopWatch.stop();
        return quiet ? StringUtils.EMPTY : triggerSyncMsg(id, stopWatch.toString());
    }
    id = scoreServices.trigger(compilationArtifact, mergedInputs, systemProperties);
    return quiet ? StringUtils.EMPTY : triggerAsyncMsg(id, compilationArtifact.getExecutionPlan().getName());
}

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

/**
 * Builds the paths MarkupDocument.//from   w w w .j a va 2s  .c  om
 *
 * @return the paths MarkupDocument
 */
@Override
public MarkupDocument build() {
    Map<String, Path> paths = globalContext.getSwagger().getPaths();
    if (MapUtils.isNotEmpty(paths)) {
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
        buildPathsTitle();
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
        buildsPathsSection(paths);
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
    }
    return new MarkupDocument(markupDocBuilder);
}

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 
 *//* www  .j a v  a  2  s.  c o  m*/
public static HttpResponse callPostUrlPure(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
    HttpPost request = new HttpPost(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 'POST' 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.MarkupDocumentBuilder.java

protected Type createInlineObjectType(Type type, String name, String uniqueName,
        List<ObjectType> inlineDefinitions) {
    if (type instanceof ObjectType) {
        ObjectType objectType = (ObjectType) type;
        if (MapUtils.isNotEmpty(objectType.getProperties())) {
            if (objectType.getName() == null) {
                objectType.setName(name);
                objectType.setUniqueName(uniqueName);
            }//from w  w  w  . jav a2 s .com
            inlineDefinitions.add(objectType);
            return new RefType(objectType);
        } else
            return type;
    } else
        return type;
}

From source file:io.cloudslang.lang.cli.utils.CompilerHelperImpl.java

private Map<String, Value> loadMapsFromFiles(List<File> files, String[] extensions, String directory) {
    Collection<File> fileCollection;
    if (CollectionUtils.isEmpty(files)) {
        fileCollection = loadDefaultFiles(extensions, directory, false);
        if (CollectionUtils.isEmpty(fileCollection)) {
            return null;
        }/*from ww  w .  j  av  a  2  s  .c om*/
    } else {
        fileCollection = files;
    }
    Map<String, Value> result = new HashMap<>();
    for (File inputFile : fileCollection) {
        logger.info("Loading file: " + inputFile);
        try {
            String inputsFileContent = SlangSource.fromFile(inputFile).getContent();
            Boolean emptyContent = true;
            if (StringUtils.isNotEmpty(inputsFileContent)) {
                @SuppressWarnings("unchecked")
                Map<String, ? extends Serializable> inputFileYamlContent = (Map<String, ? extends Serializable>) yaml
                        .load(inputsFileContent);
                if (MapUtils.isNotEmpty(inputFileYamlContent)) {
                    emptyContent = false;
                    result.putAll(
                            slangSourceService.convertInputFromMap(inputFileYamlContent, inputFile.getName()));
                }
            }
            if (emptyContent) {
                throw new RuntimeException(
                        "Inputs file: " + inputFile + " is empty or does not contain valid YAML content.");
            }
        } catch (RuntimeException ex) {
            logger.error("Error loading file: " + inputFile + ". Nested exception is: " + ex.getMessage(), ex);
            throw new RuntimeException(ex);
        }
    }
    return result;
}

From source file:monasca.log.api.app.LogService.java

private String buildKey(String tenantId, Log log) {
    final StringBuilder key = new StringBuilder();

    key.append(tenantId);//from ww w. j a va 2  s. c o m

    if (StringUtils.isNotEmpty(log.getApplicationType())) {
        key.append(log.getApplicationType());
    }

    if (MapUtils.isNotEmpty(log.getDimensions())) {
        for (final Map.Entry<String, String> dim : this.buildSortedDimSet(log.getDimensions())) {
            key.append(dim.getKey());
            key.append(dim.getValue());
        }
    }

    return key.toString();
}

From source file:com.jkoolcloud.tnt4j.streams.format.FactPathValueFormatter.java

/**
 * Returns name for provided {@code trackable} instance.
 * <p>/* w  w w . ja  v a  2s.c om*/
 * Builds path using user configured ({@code "PathLevelAttributes"} property) path of trackable values.
 *
 * @param trackable
 *            trackable instance to get name for
 * @return name of provided trackable
 */
@Override
protected String getTrackableName(Trackable trackable) {
    StringBuilder pathBuilder = new StringBuilder(128);
    Object pv;

    if (MapUtils.isNotEmpty(pathLevelAttrKeys)) {
        for (Map.Entry<Condition, String[][]> entry : pathLevelAttrKeys.entrySet()) {
            pv = trackable.getFieldValue(entry.getKey().variable);
            if (entry.getKey().evaluate(Utils.toString(pv))) {
                for (String[] levelAttrKeys : entry.getValue()) {
                    inner: for (String pKey : levelAttrKeys) {
                        pv = trackable.getFieldValue(pKey);
                        if (pv != null) {
                            appendPath(pathBuilder, pv);
                            break inner;
                        }
                    }
                }
                break; // handle first
            }
        }
    } else {
        pathBuilder.append(trackable.getName());
    }

    return pathBuilder.toString();
}