use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class ExtensionUUIDsInGroupQuery method buildSQL.
private static String buildSQL(Collection<String> inGroups) {
TextStringBuilder dynamicInClauseAllocation = new TextStringBuilder();
dynamicInClauseAllocation.appendWithSeparators(inGroups.stream().map(group -> "?").toArray(), ",");
return SELECT + DISTINCT + ExtensionGroupsTable.USER_UUID + FROM + ExtensionGroupsTable.TABLE_NAME + WHERE + ExtensionGroupsTable.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID + AND + ExtensionGroupsTable.GROUP_NAME + " IN (" + dynamicInClauseAllocation.build() + ")";
}
use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class UserInfoQueries method uuidsOfPlayersWithJoinAddresses.
public static Query<Set<UUID>> uuidsOfPlayersWithJoinAddresses(List<String> joinAddresses) {
String selectLowercaseJoinAddresses = SELECT + UserInfoTable.USER_UUID + ',' + "LOWER(COALESCE(" + UserInfoTable.JOIN_ADDRESS + ", ?)) as address" + FROM + UserInfoTable.TABLE_NAME;
String sql = SELECT + DISTINCT + UserInfoTable.USER_UUID + FROM + '(' + selectLowercaseJoinAddresses + ") q1" + WHERE + "address IN (" + new TextStringBuilder().appendWithSeparators(joinAddresses.stream().map(item -> '?').iterator(), ",") + // Don't append addresses directly, SQL injection hazard
')';
return new QueryStatement<Set<UUID>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, "unknown");
for (int i = 1; i <= joinAddresses.size(); i++) {
String address = joinAddresses.get(i - 1);
statement.setString(i + 1, address);
}
}
@Override
public Set<UUID> processResults(ResultSet set) throws SQLException {
return extractUUIDs(set);
}
};
}
use of org.apache.commons.text.TextStringBuilder in project cuba by cuba-platform.
the class ConstraintEditor method openWizard.
public void openWizard() {
String entityNameValue = entityName.getValue();
if (StringUtils.isBlank(entityNameValue)) {
showNotification(getMessage("notification.entityIsEmpty"), NotificationType.HUMANIZED);
entityName.focus();
return;
}
FakeFilterSupport fakeFilterSupport = new FakeFilterSupport(this, metadata.getSession().getClass(entityNameValue));
WindowInfo windowInfo = windowConfig.getWindowInfo("filterEditor");
Map<String, Object> params = new HashMap<>();
Constraint constraint = getItem();
final Filter fakeFilter = fakeFilterSupport.createFakeFilter();
final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(constraint.getFilterXml());
final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
params.put("filter", fakeFilter);
params.put("filterEntity", filterEntity);
params.put("conditionsTree", conditionsTree);
params.put("useShortConditionForm", true);
params.put("hideDynamicAttributes", constraint.getCheckType() != ConstraintCheckType.DATABASE);
params.put("hideCustomConditions", constraint.getCheckType() != ConstraintCheckType.DATABASE);
FilterEditor filterEditor = (FilterEditor) getWindowManager().openWindow(windowInfo, OpenType.DIALOG, params);
filterEditor.addCloseListener(actionId -> {
if (!COMMIT_ACTION_ID.equals(actionId))
return;
FilterParser filterParser1 = AppBeans.get(FilterParser.class);
// todo eude rename com.haulmont.cuba.gui.components.filter.FilterParser
filterEntity.setXml(filterParser1.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE));
if (filterEntity.getXml() != null) {
Element element = dom4JTools.readDocument(filterEntity.getXml()).getRootElement();
com.haulmont.cuba.core.global.filter.FilterParser filterParser = new com.haulmont.cuba.core.global.filter.FilterParser(element);
Constraint item = getItem();
if (item.getCheckType().database()) {
String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
constraint.setWhereClause(jpql);
Set<String> joins = filterParser.getRoot().getJoins();
if (!joins.isEmpty()) {
String joinsStr = new TextStringBuilder().appendWithSeparators(joins, " ").toString();
constraint.setJoinClause(joinsStr);
}
}
if (item.getCheckType().memory()) {
String groovy = new GroovyGenerator().generateGroovy(filterParser.getRoot());
constraint.setGroovyScript(groovy);
}
constraint.setFilterXml(filterEntity.getXml());
}
});
}
use of org.apache.commons.text.TextStringBuilder in project cuba by cuba-platform.
the class AbstractMessages method searchMessage.
@Nullable
protected String searchMessage(String packs, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
StringTokenizer tokenizer = new StringTokenizer(packs);
// noinspection unchecked
List<String> list = tokenizer.getTokenList();
Collections.reverse(list);
for (String pack : list) {
if (!enterPack(pack, locale, truncatedLocale, passedPacks))
continue;
String msg = searchOnePack(pack, key, locale, truncatedLocale, passedPacks);
if (msg != null)
return msg;
Locale tmpLocale = truncatedLocale;
while (tmpLocale != null) {
tmpLocale = truncateLocale(tmpLocale);
msg = searchOnePack(pack, key, locale, tmpLocale, passedPacks);
if (msg != null)
return msg;
}
}
if (log.isTraceEnabled()) {
String packName = new TextStringBuilder().appendWithSeparators(list, ",").toString();
log.trace("Resource '{}' not found", makeCacheKey(packName, key, locale, locale));
}
return null;
}
use of org.apache.commons.text.TextStringBuilder in project iaf by ibissource.
the class MessageStoreSender method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
try {
Message messageToStore = message;
if (sessionKeys != null) {
List<String> list = new ArrayList<>();
list.add(StringEscapeUtils.escapeCsv(message.asString()));
StringTokenizer tokenizer = new StringTokenizer(sessionKeys, ",");
while (tokenizer.hasMoreElements()) {
String sessionKey = (String) tokenizer.nextElement();
Message msg = session.getMessage(sessionKey);
if (!msg.isEmpty()) {
list.add(StringEscapeUtils.escapeCsv(msg.asString()));
}
}
TextStringBuilder sb = new TextStringBuilder();
sb.appendWithSeparators(list, ",");
messageToStore = Message.asMessage(sb.toString());
}
// the messageId to be inserted in the messageStore defaults to the messageId of the session
String messageId = session.getMessageId();
String correlationID = messageId;
if (paramList != null && paramList.findParameter(PARAM_MESSAGEID) != null) {
try {
// the messageId to be inserted can also be specified via the parameter messageId
messageId = paramList.getValues(message, session).get(PARAM_MESSAGEID).asStringValue();
} catch (ParameterException e) {
throw new SenderException("Could not resolve parameter messageId", e);
}
}
return new Message(storeMessage(messageId, correlationID, new Date(), null, null, messageToStore.asString()));
} catch (IOException e) {
throw new SenderException(getLogPrefix(), e);
}
}
Aggregations