Search in sources :

Example 31 with StringSubstitutor

use of org.apache.commons.text.StringSubstitutor in project Insights by CognizantOneDevOps.

the class PDFKPIVisualizationProcesser method addFieldInVQuery.

private String addFieldInVQuery(String vQuery, int kpiId) {
    Map<String, String> dateReplaceMap = new HashMap<>();
    dateReplaceMap.put("assessmentId", String.valueOf(assessmentReportDTO.getConfigId()));
    dateReplaceMap.put("executionId", String.valueOf(assessmentReportDTO.getExecutionId()));
    dateReplaceMap.put(AssessmentReportAndWorkflowConstants.KPIID, String.valueOf(kpiId));
    dateReplaceMap.put("assessmentReportName", "'" + assessmentReportDTO.getAsseementreportname() + "'");
    StringSubstitutor sub = new StringSubstitutor(dateReplaceMap, "{", "}");
    return sub.replace(vQuery);
}
Also used : HashMap(java.util.HashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor)

Example 32 with StringSubstitutor

use of org.apache.commons.text.StringSubstitutor in project Insights by CognizantOneDevOps.

the class InsightsKPIProcessor method getQueryWithScheduleDates.

protected void getQueryWithScheduleDates(long nextRuntime, WorkflowTaskEnum.WorkflowSchedule schedule, String neo4jQuery, long oneTimeEndDate, List<QueryModel> queryModelList) {
    long startTime = System.nanoTime();
    QueryModel queryModel = new QueryModel();
    Map<String, Long> dateReplaceMap = new HashMap<>();
    long fromDate = InsightsUtils.getStartFromTime(nextRuntime, schedule.name()) - 1;
    long toDate;
    if (schedule.name().equalsIgnoreCase(WorkflowTaskEnum.WorkflowSchedule.ONETIME.name())) {
        toDate = oneTimeEndDate;
    } else {
        // minus 2 sec to get time 23:59:59
        toDate = nextRuntime - 2;
    }
    dateReplaceMap.put(ReportEngineUtils.START_TIME_FIELD, fromDate);
    dateReplaceMap.put(ReportEngineUtils.END_TIME_FIELD, toDate);
    StringSubstitutor sub = new StringSubstitutor(dateReplaceMap, "{", "}");
    queryModel.setRecordDate(fromDate);
    queryModel.setQuery(sub.replace(neo4jQuery));
    queryModelList.add(queryModel);
    long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", kpiConfigDTO.getExecutionId(), kpiConfigDTO.getWorkflowId(), kpiConfigDTO.getReportId(), "-", kpiConfigDTO.getKpiId(), kpiConfigDTO.getCategory(), processingTime, "queryStartTime: " + fromDate + "queryEndTime: " + toDate + "schedule: " + kpiConfigDTO.getSchedule());
}
Also used : HashMap(java.util.HashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor) QueryModel(com.cognizant.devops.platformreports.assessment.datamodel.QueryModel)

Example 33 with StringSubstitutor

use of org.apache.commons.text.StringSubstitutor in project Insights by CognizantOneDevOps.

the class TraceabilitySummaryUtil method calCount.

public static String calCount(String operandName, JsonArray operandValue, List<JsonObject> toolRespPayload, String message) {
    String returnMessage = "";
    try {
        int totalCount = toolRespPayload.size();
        Map<String, Integer> valueMap = new HashMap<>();
        List<String> operanValueList = StreamSupport.stream(operandValue.spliterator(), false).map(e -> e.getAsString()).collect(Collectors.toList());
        if (totalCount >= 0) {
            for (int i = 0; i < operanValueList.size(); i++) {
                String operandSingleValue = operanValueList.get(i);
                int count = (int) toolRespPayload.stream().filter(payload -> payload.has(operandName) && operandSingleValue.contains(payload.get(operandName).getAsString())).count();
                valueMap.put(String.valueOf(i), count);
            }
            StringSubstitutor sub = new StringSubstitutor(valueMap, "{", "}");
            returnMessage = sub.replace(message);
        }
    } catch (Exception e) {
        log.error(e);
    }
    return returnMessage;
}
Also used : JsonObject(com.google.gson.JsonObject) Date(java.util.Date) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) InsightsUtils(com.cognizant.devops.platformcommons.core.util.InsightsUtils) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) StringSubstitutor(org.apache.commons.text.StringSubstitutor) JsonElement(com.google.gson.JsonElement) List(java.util.List) JsonArray(com.google.gson.JsonArray) Logger(org.apache.logging.log4j.Logger) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) StreamSupport(java.util.stream.StreamSupport) ParseException(java.text.ParseException) LogManager(org.apache.logging.log4j.LogManager) DateFormat(java.text.DateFormat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor) ParseException(java.text.ParseException)

Example 34 with StringSubstitutor

use of org.apache.commons.text.StringSubstitutor in project metersphere by metersphere.

the class AbstractNoticeSender method getContent.

protected String getContent(String template, Map<String, Object> context) {
    // 处理 null
    context.forEach((k, v) -> {
        if (v == null) {
            context.put(k, "");
        }
    });
    // 处理时间格式的数据
    handleTime(context);
    StringSubstitutor sub = new StringSubstitutor(context);
    return sub.replace(template);
}
Also used : StringSubstitutor(org.apache.commons.text.StringSubstitutor)

Example 35 with StringSubstitutor

use of org.apache.commons.text.StringSubstitutor in project alf.io by alfio-event.

the class LocationDescriptor method getMapUrl.

public static String getMapUrl(String lat, String lng, Map<ConfigurationKeys, ConfigurationManager.MaybeConfiguration> geoConf) {
    Map<String, String> params = new HashMap<>();
    params.put("latitude", lat);
    params.put("longitude", lng);
    ConfigurationKeys.GeoInfoProvider provider = getProvider(geoConf);
    String mapUrl = mapUrl(provider);
    fillParams(provider, geoConf, params);
    return new StringSubstitutor(params).replace(mapUrl);
}
Also used : ConfigurationKeys(alfio.model.system.ConfigurationKeys) HashMap(java.util.HashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor)

Aggregations

StringSubstitutor (org.apache.commons.text.StringSubstitutor)71 HashMap (java.util.HashMap)24 Test (org.junit.jupiter.api.Test)19 IOException (java.io.IOException)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 File (java.io.File)8 List (java.util.List)8 InputStream (java.io.InputStream)6 Collectors (java.util.stream.Collectors)6 StringLookup (org.apache.commons.text.lookup.StringLookup)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)5 SubstitutingSourceProvider (io.dropwizard.configuration.SubstitutingSourceProvider)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 JsonObject (com.google.gson.JsonObject)4 URL (java.net.URL)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Scanner (java.util.Scanner)4