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);
}
}
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);
}
}
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());
}
});
}
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());
}
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();
}
Aggregations