Search in sources :

Example 1 with TextStringBuilder

use of org.apache.commons.text.TextStringBuilder in project cuba by cuba-platform.

the class PersistenceManager method findUpdateDatabaseScripts.

@Override
public String findUpdateDatabaseScripts() {
    try {
        List<String> list = AppBeans.getPrototype(DbUpdater.class, Stores.MAIN).findUpdateDatabaseScripts();
        if (!list.isEmpty()) {
            File dbDir = new File(serverConfig.getDbDir());
            String indent = "\t";
            TextStringBuilder sb = new TextStringBuilder();
            sb.append(dbDir.getPath().replace('\\', '/')).append("/").append("\n");
            for (String path : list) {
                sb.append(indent).append(path).append("\n");
            }
            return sb.toString();
        } else
            return "No updates available";
    } catch (DbInitializationException e) {
        return e.getMessage();
    } catch (Throwable e) {
        return ExceptionUtils.getStackTrace(e);
    }
}
Also used : DbInitializationException(com.haulmont.cuba.core.sys.DbInitializationException) DbUpdater(com.haulmont.cuba.core.sys.DbUpdater) File(java.io.File) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 2 with TextStringBuilder

use of org.apache.commons.text.TextStringBuilder in project cuba by cuba-platform.

the class PersistenceManager method jpqlLoadList.

@Authenticated
@Override
public String jpqlLoadList(String queryString) {
    try {
        Transaction tx = persistence.createTransaction();
        try {
            EntityManager em = persistence.getEntityManager();
            Query query = em.createQuery(queryString);
            QueryParser parser = QueryTransformerFactory.createParser(queryString);
            Set<String> paramNames = parser.getParamNames();
            for (String paramName : paramNames) {
                security.setQueryParam(query, paramName);
            }
            List resultList = query.getResultList();
            tx.commit();
            TextStringBuilder sb = new TextStringBuilder();
            for (Object element : resultList) {
                if (element instanceof Object[]) {
                    sb.appendWithSeparators((Object[]) element, " | ");
                } else {
                    sb.append(element);
                }
                sb.append("\n");
            }
            return sb.toString();
        } finally {
            tx.end();
        }
    } catch (Throwable e) {
        log.error("jpqlLoadList error", e);
        return ExceptionUtils.getStackTrace(e);
    }
}
Also used : List(java.util.List) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Authenticated(com.haulmont.cuba.security.app.Authenticated)

Example 3 with TextStringBuilder

use of org.apache.commons.text.TextStringBuilder in project cuba by cuba-platform.

the class AttributeEditor method openConstraintWizard.

public void openConstraintWizard() {
    CategoryAttribute attribute = getItem();
    Class entityClass = attribute.getJavaClassForEntity();
    if (entityClass == null) {
        showNotification(getMessage("selectEntityType"));
        return;
    }
    MetaClass metaClass = metadata.getClassNN(entityClass);
    FakeFilterSupport filterSupport = new FakeFilterSupport(this, metaClass);
    Filter fakeFilter = filterSupport.createFakeFilter();
    FilterEntity filterEntity = filterSupport.createFakeFilterEntity(attribute.getFilterXml());
    ConditionsTree conditionsTree = filterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
    Map<String, Object> params = new HashMap<>();
    params.put("filter", fakeFilter);
    params.put("filterEntity", filterEntity);
    params.put("conditionsTree", conditionsTree);
    params.put("useShortConditionForm", true);
    FilterEditor filterEditor = (FilterEditor) openWindow("filterEditor", OpenType.DIALOG, params);
    filterEditor.addCloseListener(actionId -> {
        if (!COMMIT_ACTION_ID.equals(actionId)) {
            return;
        }
        filterEntity.setXml(filterParser.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);
            String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
            attribute.setWhereClause(jpql);
            Set<String> joins = filterParser.getRoot().getJoins();
            if (!joins.isEmpty()) {
                String joinsStr = new TextStringBuilder().appendWithSeparators(joins, " ").toString();
                attribute.setJoinClause(joinsStr);
            }
            attribute.setFilterXml(filterEntity.getXml());
        }
    });
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Element(org.dom4j.Element) 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) FakeFilterSupport(com.haulmont.cuba.gui.components.filter.FakeFilterSupport) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) 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 4 with TextStringBuilder

use of org.apache.commons.text.TextStringBuilder in project cuba by cuba-platform.

the class DesktopAppContextLoader method initAppProperties.

protected void initAppProperties() {
    AppContext.setProperty(AppConfig.CLIENT_TYPE_PROP, ClientType.DESKTOP.toString());
    String appPropertiesConfig = System.getProperty(APP_PROPERTIES_CONFIG_SYS_PROP);
    if (StringUtils.isBlank(appPropertiesConfig))
        appPropertiesConfig = defaultAppPropertiesConfig;
    final Properties properties = new Properties();
    StringTokenizer tokenizer = new StringTokenizer(appPropertiesConfig);
    for (String str : tokenizer.getTokenArray()) {
        InputStream stream = null;
        try {
            stream = getClass().getResourceAsStream(str);
            if (stream != null) {
                Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
                properties.load(reader);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }
    for (String arg : args) {
        arg = arg.trim();
        int pos = arg.indexOf('=');
        if (pos > 0) {
            String key = arg.substring(0, pos);
            String value = arg.substring(pos + 1);
            properties.setProperty(key, value);
        }
    }
    for (Object key : properties.keySet()) {
        AppContext.setProperty((String) key, properties.getProperty((String) key).trim());
    }
    List<String> list = new ArrayList<>();
    for (String key : AppContext.getPropertyNames()) {
        list.add(key + "=" + AppContext.getProperty(key));
    }
    Collections.sort(list);
    log.info(new TextStringBuilder("AppProperties:\n").appendWithSeparators(list, "\n").toString());
}
Also used : ArrayList(java.util.ArrayList) Properties(java.util.Properties) TextStringBuilder(org.apache.commons.text.TextStringBuilder) StringTokenizer(org.apache.commons.text.StringTokenizer)

Example 5 with TextStringBuilder

use of org.apache.commons.text.TextStringBuilder in project configuration-as-code-plugin by jenkinsci.

the class SecretSourceResolver method resolve.

/**
 * Resolve string with potential secrets
 *
 * @param toInterpolate potential variables that need to revealed
 * @return original string with any secrets that could be resolved if secrets could not be
 * resolved they will be defaulted to default value defined by ':-', otherwise default to empty
 * String. Secrets are defined as anything enclosed by '${}'
 */
public String resolve(String toInterpolate) {
    if (StringUtils.isBlank(toInterpolate) || !toInterpolate.contains(enclosedBy)) {
        return toInterpolate;
    }
    final TextStringBuilder buf = new TextStringBuilder(toInterpolate);
    substitutor.replaceIn(buf);
    nullSubstitutor.replaceIn(buf);
    return buf.toString();
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Aggregations

TextStringBuilder (org.apache.commons.text.TextStringBuilder)34 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 List (java.util.List)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 Issue (org.apache.gobblin.runtime.troubleshooter.Issue)2