use of jodd.props.Props in project jmeter by apache.
the class ReportGeneratorConfiguration method loadFromProperties.
/**
* Load a configuration from the specified properties.
*
* @param properties
* the properties
* @return the report generator configuration
* @throws ConfigurationException
* when mandatory properties are missing
*/
public static ReportGeneratorConfiguration loadFromProperties(Properties properties) throws ConfigurationException {
log.debug("Report generator properties loading");
ReportGeneratorConfiguration configuration = new ReportGeneratorConfiguration();
// Use jodd.Props to ease property handling
final Props props = new Props();
log.debug("Loading properties:\r\n{}", properties);
props.load(properties);
// Load temporary directory property
final File tempDirectory = getRequiredProperty(props, REPORT_GENERATOR_KEY_TEMP_DIR, REPORT_GENERATOR_KEY_TEMP_DIR_DEFAULT, File.class);
configuration.setTempDirectory(tempDirectory);
// Load apdex satisfied threshold
final long apdexSatisfiedThreshold = getRequiredProperty(props, REPORT_GENERATOR_KEY_APDEX_SATISFIED_THRESHOLD, REPORT_GENERATOR_KEY_APDEX_SATISFIED_THRESHOLD_DEFAULT, long.class).longValue();
configuration.setApdexSatisfiedThreshold(apdexSatisfiedThreshold);
// Load apdex tolerated threshold
final long apdexToleratedThreshold = getRequiredProperty(props, REPORT_GENERATOR_KEY_APDEX_TOLERATED_THRESHOLD, REPORT_GENERATOR_KEY_APDEX_TOLERATED_THRESHOLD_DEFAULT, long.class).longValue();
configuration.setApdexToleratedThreshold(apdexToleratedThreshold);
// Load apdex per transactions, overridden by user
final String apdexPerTransaction = getOptionalProperty(props, REPORT_GENERATOR_KEY_APDEX_PER_TRANSACTION, String.class);
configuration.setApdexPerTransaction(getApdexPerTransactionParts(apdexPerTransaction));
final boolean ignoreTCFromTop5ErrorsBySampler = getRequiredProperty(props, REPORT_GENERATOR_KEY_EXCLUDE_TC_FROM_TOP5_ERRORS_BY_SAMPLER, Boolean.TRUE, Boolean.class).booleanValue();
configuration.setIgnoreTCFromTop5ErrorsBySampler(ignoreTCFromTop5ErrorsBySampler);
// Load sample filter
final String sampleFilter = getOptionalProperty(props, REPORT_GENERATOR_KEY_SAMPLE_FILTER, String.class);
configuration.setSampleFilter(sampleFilter);
final String reportTitle = getOptionalProperty(props, REPORT_GENERATOR_KEY_REPORT_TITLE, String.class);
configuration.setReportTitle(reportTitle);
Date reportStartDate = null;
Date reportEndDate = null;
final String startDateValue = getOptionalProperty(props, REPORT_GENERATOR_KEY_START_DATE, String.class);
final String endDateValue = getOptionalProperty(props, REPORT_GENERATOR_KEY_END_DATE, String.class);
String rangeDateFormat = getOptionalProperty(props, REPORT_GENERATOR_KEY_RANGE_DATE_FORMAT, String.class);
if (StringUtils.isEmpty(rangeDateFormat)) {
rangeDateFormat = RANGE_DATE_FORMAT_DEFAULT;
}
SimpleDateFormat dateFormat = new SimpleDateFormat(rangeDateFormat, Locale.ENGLISH);
try {
if (!StringUtils.isEmpty(startDateValue)) {
reportStartDate = dateFormat.parse(startDateValue);
configuration.setStartDate(reportStartDate);
}
} catch (ParseException e) {
log.error("Error parsing property {} with value: {} using format: {}", REPORT_GENERATOR_KEY_START_DATE, startDateValue, rangeDateFormat, e);
}
try {
if (!StringUtils.isEmpty(endDateValue)) {
reportEndDate = dateFormat.parse(endDateValue);
configuration.setEndDate(reportEndDate);
}
} catch (ParseException e) {
log.error("Error parsing property {} with value: {} using format: {}", REPORT_GENERATOR_KEY_END_DATE, endDateValue, rangeDateFormat, e);
}
log.info("Will use date range start date: {}, end date: {}", startDateValue, endDateValue);
// Find graph identifiers and load a configuration for each
final Map<String, GraphConfiguration> graphConfigurations = configuration.getGraphConfigurations();
loadSubConfiguration(graphConfigurations, props, REPORT_GENERATOR_GRAPH_KEY_PREFIX, false, new GraphConfigurationFactory(props));
if (graphConfigurations.isEmpty()) {
log.info("No graph configuration found.");
}
// Find exporter identifiers and load a configuration for each
final Map<String, ExporterConfiguration> exportConfigurations = configuration.getExportConfigurations();
loadSubConfiguration(exportConfigurations, props, REPORT_GENERATOR_EXPORTER_KEY_PREFIX, false, new ExporterConfigurationFactory(props));
if (exportConfigurations.isEmpty()) {
log.warn("No export configuration found. No report will be generated.");
}
log.debug("End of report generator properties loading");
return configuration;
}
Aggregations