Search in sources :

Example 16 with TextStringBuilder

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() + ")";
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 17 with TextStringBuilder

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);
        }
    };
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 18 with TextStringBuilder

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());
        }
    });
}
Also used : Constraint(com.haulmont.cuba.security.entity.Constraint) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Element(org.dom4j.Element) GroovyGenerator(com.haulmont.cuba.core.global.filter.GroovyGenerator) FilterEditor(com.haulmont.cuba.gui.components.filter.edit.FilterEditor) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) TextStringBuilder(org.apache.commons.text.TextStringBuilder) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) FakeFilterSupport(com.haulmont.cuba.gui.components.filter.FakeFilterSupport) FilterParser(com.haulmont.cuba.gui.components.filter.FilterParser) SecurityJpqlGenerator(com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree)

Example 19 with TextStringBuilder

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;
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Nullable(javax.annotation.Nullable)

Example 20 with TextStringBuilder

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);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(nl.nn.adapterframework.stream.Message) ArrayList(java.util.ArrayList) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Date(java.util.Date)

Aggregations

TextStringBuilder (org.apache.commons.text.TextStringBuilder)36 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Issue (org.apache.gobblin.runtime.troubleshooter.Issue)4 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)3 Test (org.junit.jupiter.api.Test)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 SecurityJpqlGenerator (com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator)2 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)2 FakeFilterSupport (com.haulmont.cuba.gui.components.filter.FakeFilterSupport)2 FilterParser (com.haulmont.cuba.gui.components.filter.FilterParser)2 FilterEditor (com.haulmont.cuba.gui.components.filter.edit.FilterEditor)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 Nullable (javax.annotation.Nullable)2 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)2 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)2 StringTokenizer (org.apache.commons.text.StringTokenizer)2