![JAR search and dependency download from the Maven repository](/logo.png)
de.tsl2.nano.specification.SpecificationExchange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.specification Show documentation
Show all versions of tsl2.nano.specification Show documentation
TSL2 Framework Specification (Pools of descripted and runnable Actions and Rules, Generic Tree)
The newest version!
package de.tsl2.nano.specification;
import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import de.tsl2.nano.bean.def.BeanDefinition;
import de.tsl2.nano.bean.def.IAttributeDefinition;
import de.tsl2.nano.bean.def.IBeanDefinitionSaver;
import de.tsl2.nano.core.ENV;
import de.tsl2.nano.core.log.LogFactory;
import de.tsl2.nano.core.util.FileUtil;
import de.tsl2.nano.core.util.StringUtil;
/**
* provides a mechanism to read all specifications (rules, queries, actions etc.) and their use in the
* bean-presentations or workflows from a single property, csv or markdown file.
* as convenience, each new bean writes all possible attribute properties to be used for a specification
* definition to a file inside the applications configuration directory.
*
* @author ts
*/
public class SpecificationExchange implements IBeanDefinitionSaver {
private static final String SPECIFICATION_README_TXT = "specification-readme.txt";
private static final Log LOG = LogFactory.getLog(SpecificationExchange.class);
public static final String EXT_CSV = ".csv";
public static final String EXT_MARKDOWN = ".md.html";
protected static final String SEP = "\t";
public static final String FILENAME_SPEC_PROPERTIES = "specification.properties";
public static final String PATH_POSTIFX = "*";
public static final String PATH_LAYOUTCONSTRAINTS = "presentable.layoutConstraints";
public static final String PATH_COLDEF_LAYOUTCONSTRAINTS = "columnDefinition." + PATH_LAYOUTCONSTRAINTS;
public enum Change {valueexpression, attributefilter, icon, addattribute, addaction, enabler, listener, rulecover,
createstatistics, createquery, createcompositor, createcontroller, createsheet};
protected boolean exists;
static final String doc = "##############################################################################\n"
+ "# Tsl2Nano H5 Specification Properties (Thomas Schneider / 2022)\n"
+ "# \n"
+ "# Syntax:\n"
+ "# |\n"
+ "#\n"
+ "# with:\n"
+ "# create-property : =\n"
+ "# create-user : createuser=:::\n"
+ "# create-rule : <=\n"
+ "# bean-change : [..[|]] | [bean-change-ex]\n"
+ "# with: \n"
+ "# bean-name : \n"
+ "# bean-attribute: \n"
+ "# prop-change : <|||type|id|unique|temporalType|description|doValidation>*=\n"
+ "# attr-change :\n"
+ "# enabler=\n"
+ "# | listener=:\n"
+ "# | rulecover=:\n"
+ "# bean-change-ex:\n"
+ "# \n"
+ "# | addattribute=\n"
+ "# | addaction=\n"
+ "# | attributefilter=\n"
+ "# | icon=\n"
+ "# | createcompositor=,,\n"
+ "# | createcontroller=,,\n"
+ "# | createquery=\n"
+ "# | createstatistics\n"
+ "# | createsheet=,,\n"
+ "#\n"
+ "# with:\n"
+ "# rule : \n"
+ "# constraint : constraint.\n"
+ "# presentable: presentable.\n"
+ "# columndef : columndefinition.|minsearch|maxsearch|standardSummary>\n"
+ "#\n"
+ "# The character ':' can be replaced by one of ';:,\\s'. The character '=' can be\n"
+ "# replaced by a tab character.\n"
+ "##############################################################################\n"
+ "\n";
public String loadDocumentation() {
// TODO: load from file, when resource provided inside jar file.
// ENV.extractResource(SPECIFICATION_README_TXT);
// return FileUtil.getFileString(SPECIFICATION_README_TXT);
return doc;
}
/**
* generates resource entries for each attribute+tooltip and each action to be edited later.
*/
public void saveResourceEntries(BeanDefinition bean) {
saveSpecificationEntries(bean, ENV.getSortedProperties(FILENAME_SPEC_PROPERTIES));
}
public void saveSpecificationEntries(BeanDefinition bean, Properties p) {
if (exists || p.contains(bean.getId()))
return;
// p.put(bean.getId(), bean.getName());
Collection> attributes = bean.getBeanAttributes();
String keyPrefix = "#" + bean.getId() + ".";
p.put(keyPrefix + Change.attributefilter, "");
p.put(keyPrefix + Change.valueexpression, "");
p.put(keyPrefix + Change.icon, "");
p.put(keyPrefix + Change.addaction + "XXX", "");
p.put(keyPrefix + Change.addattribute + "XXX", "");
String id;
for (IAttributeDefinition> a : attributes) {
id = a.getId();
if (p.getProperty(id) == null) {
//TODO: listener (rulecover -> attributecover) are unknown here (-> specification)
keyPrefix = "#" + id + ".";
p.put(keyPrefix + Change.enabler, "");
p.put(keyPrefix + Change.listener, ":");
p.put(keyPrefix + Change.rulecover, ":");
}
}
FileUtil.saveProperties(ENV.getConfigPath() + FILENAME_SPEC_PROPERTIES, p, loadDocumentation());
saveAsTSV(ENV.getConfigPath() + FILENAME_SPEC_PROPERTIES + EXT_CSV, p);
}
/** converts the given properties to csv (objectname, rule, optional-parameter) */
public String saveAsTSV(String filename, Properties p) {
StringBuilder buf = new StringBuilder();
//TODO: performance: don't write whole properties on each bean...
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy