use of org.apache.commons.text.StringSubstitutor in project dhis2-core by dhis2.
the class AttributeOptionComboLoader method loadCategoryOptionCombo.
/**
* Fetches a {@see CategoryOptionCombo} by "id" (based on the provided
* IdScheme)
*
* The {@see CategoryOptionCombo} contains tha associated
* {@see CategoryCombo} and all the associated {@see CategoryOption}
*
* @param idScheme a {@see IdScheme}
* @param id the {@see CategoryOptionCombo} id to use
* @return a {@see CategoryOptionCombo} or null
*/
private CategoryOptionCombo loadCategoryOptionCombo(IdScheme idScheme, String id) {
String key = "categoryoptioncomboid";
StringSubstitutor sub = new StringSubstitutor(ImmutableMap.<String, String>builder().put("key", key).put("resolvedScheme", Objects.requireNonNull(resolveId(idScheme, key, id))).build());
try {
return jdbcTemplate.queryForObject(sub.replace(SQL_GET_CATEGORYOPTIONCOMBO), (rs, i) -> bind(key, rs));
} catch (EmptyResultDataAccessException e) {
return null;
}
}
use of org.apache.commons.text.StringSubstitutor in project dhis2-core by dhis2.
the class RelationshipTypeJoinGenerator method addRelationshipWhereClause.
private static String addRelationshipWhereClause(Long relationshipTypeId, RelationshipEntity relationshipEntity) {
String sql = new StringSubstitutor(ImmutableMap.<String, Long>builder().put("relationshipid", relationshipTypeId).build()).replace(RELATIONSHIP_JOIN);
sql += " AND ";
switch(relationshipEntity) {
case TRACKED_ENTITY_INSTANCE:
return sql + "tei.uid = ax.tei ";
case PROGRAM_STAGE_INSTANCE:
return sql + "psi.uid = ax.psi ";
case PROGRAM_INSTANCE:
return sql + "pi.uid = ax.pi ";
default:
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E7227, relationshipEntity.name()));
}
}
use of org.apache.commons.text.StringSubstitutor in project workbench by all-of-us.
the class MailServiceImpl method buildHtml.
private String buildHtml(final String resource, final Map<EmailSubstitutionField, String> replacementMap) throws MessagingException {
final String emailContent;
try {
emailContent = String.join("\n", Resources.readLines(Resources.getResource(resource), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new MessagingException("Error reading in email");
}
final Map<String, String> stringMap = replacementMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), Map.Entry::getValue));
return new StringSubstitutor(stringMap).replace(emailContent);
}
use of org.apache.commons.text.StringSubstitutor in project commons by craftercms.
the class DefaultEntitlementValidatorImpl method getDescription.
@Override
public String getDescription() {
String decoded = new String(Base64.getDecoder().decode(DESCRIPTION));
StringSubstitutor stringSubstitutor = new StringSubstitutor(Collections.singletonMap("version", getPackageVersion()));
return stringSubstitutor.replace(decoded);
}
use of org.apache.commons.text.StringSubstitutor in project connectors-workspace-one by vmware.
the class TimeOffTaskService method getTaskActionRequestBody.
private String getTaskActionRequestBody(final String inboxTaskId, final String actionUrl, final String comments) {
try (InputStream stream = timeOffTaskActionTemplate.getInputStream()) {
final Map<String, String> paramMap = Maps.newHashMap();
paramMap.put(TIMEOFF_TASK_ID, inboxTaskId);
paramMap.put(TIMEOFF_TASK_DESCRIPTOR, TIMEOFF_TASK_DESCRIPTOR_VALUE);
paramMap.put(TIMEOFF_TASK_URL, actionUrl);
paramMap.put(TIMEOFF_TASK_ACTION_COMMENTS, HtmlUtils.htmlEscape(defaultIfBlank(comments, EMPTY)));
final StringSubstitutor stringSubstitutor = new StringSubstitutor(paramMap);
return stringSubstitutor.replace(IOUtils.toString(stream, UTF_8));
} catch (IOException e) {
LOGGER.error("Error occurred in building inbox task action body from template", e);
throw new TimeOffTaskActionRequestCreationFailedException(e);
}
}
Aggregations