use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class IDEF0Plugin method checkModelTree.
private void checkModelTree(Qualifier modelTree) {
List<Qualifier> models = new ArrayList<Qualifier>();
List<Qualifier> qList = engine.getQualifiers();
for (Qualifier qualifier : qList) {
if (IDEF0Plugin.isFunction(qualifier)) {
models.add(qualifier);
}
}
Collections.sort(models, new Comparator<Qualifier>() {
@Override
public int compare(Qualifier o1, Qualifier o2) {
return StringCollator.compare(o1.getName(), o2.getName());
}
});
Attribute attribute = StandardAttributesPlugin.getAttributeQualifierId(engine);
RowSet rowSet = new RowSet(engine, modelTree, new Attribute[] { attribute }, null, true);
for (Row row : rowSet.getAllRows()) {
for (int i = models.size() - 1; i >= 0; --i) {
Qualifier model = models.get(i);
Long id = (Long) row.getAttribute(attribute);
if (id != null && model.getId() == id.longValue()) {
models.remove(i);
break;
}
}
}
for (Qualifier model : models) {
Row row = rowSet.createRow(null);
row.setName(model.getName());
row.setAttribute(attribute, model.getId());
}
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class AnyToAnyPlugin method replaceElements.
@SuppressWarnings("unchecked")
@Override
public void replaceElements(Engine engine, Element[] oldElements, Element newElement) {
if (engine.getDeligate() instanceof IEngineImpl) {
IEngineImpl engineImpl = (IEngineImpl) engine.getDeligate();
JDBCTemplate template = engineImpl.getTemplate();
String prefix = engineImpl.getPrefix();
long[] elementIds = new long[oldElements.length];
for (int i = 0; i < oldElements.length; i++) {
elementIds[i] = oldElements[i].getId();
}
String sql = "SELECT element_id FROM " + prefix + "attribute_any_to_any_elements WHERE other_element IN(" + JDBCTemplate.toSqlArray(elementIds) + ")";
if (!(Boolean) template.query(sql, new ExecutionCallback() {
@Override
public Object execute(PreparedStatement statement) throws SQLException {
ResultSet rs = statement.executeQuery();
boolean has = rs.next();
rs.close();
return has;
}
}, false))
return;
}
Qualifier qualifier = IDEF0Plugin.getBaseStreamQualifier(engine);
Attribute added = IDEF0Plugin.getStreamAddedAttribute(engine);
List<Attribute> attributes = new ArrayList<Attribute>(1);
attributes.add(added);
Hashtable<Element, Object[]> res = engine.getElements(qualifier, attributes);
Enumeration<Element> keys = res.keys();
while (keys.hasMoreElements()) {
Element key = keys.nextElement();
Object[] value = res.get(key);
updateElements(engine, key, (List<AnyToAnyPersistent>) value[0], oldElements, newElement, added);
}
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class AnyToAnyPlugin method getElementsDeleteStatus.
@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, final IEngine engine) {
final HashMap<Long, Attribute> attributesCache = new HashMap<Long, Attribute>();
final HashMap<Long, Qualifier> qualifiersCache = new HashMap<Long, Qualifier>();
JDBCTemplate template = ((IEngineImpl) engine).getTemplate();
String prefix = ((IEngineImpl) engine).getPrefix();
StringBuffer sb = JDBCTemplate.toSqlArray(elementIds);
String sql = "SELECT element_id FROM " + prefix + "attribute_any_to_any_elements WHERE other_element in(" + sb.toString() + ")";
String gSQL;
final List<String> functions = new ArrayList<String>();
gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sql + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
if (elementName.trim().length() > 0 && !functions.contains(elementName))
functions.add(elementName);
return null;
}
}, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sb + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
if (elementName.trim().length() > 0 && !functions.contains(elementName))
functions.add(elementName);
return null;
}
}, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
gSQL = "SELECT * FROM {0}elements WHERE element_id IN(SELECT parent_element_id FROM {0}attribute_hierarchicals WHERE element_id IN(" + "SELECT element_id FROM {0}attribute_longs WHERE value in(" + sql + ")AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true) " + ")) ORDER BY element_name";
template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
if (elementName.trim().length() > 0 && !functions.contains(elementName))
functions.add(elementName);
return null;
}
}, new Object[] { IDEF0Plugin.F_LINK }, true);
if (functions.size() > 0) {
Collections.sort(functions, new Comparator<String>() {
@Override
public int compare(String arg0, String arg1) {
return StringCollator.compare(arg0, arg1);
}
});
DeleteStatus deleteStatus = new DeleteStatus();
deleteStatus.setPluginName(getName());
StringBuffer buffer = new StringBuffer();
for (String s : functions) if (!s.trim().equals("")) {
buffer.append("<br>");
buffer.append(s);
}
deleteStatus.setPluginAnswer("{Warning.ElementsUsedAtFunctions}" + buffer.toString());
return deleteStatus;
}
return null;
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class HTTPParser method getReportHTMLText.
protected Source getReportHTMLText(Engine engine, Element report, Query query) {
String page = null;
try {
HashMap<String, Object> map = new HashMap<String, Object>();
ReportQuery impl;
if (dataPlugin.getEngine().getDeligate() instanceof IEngineImpl)
impl = new ReportQueryImpl(engine) {
@Override
protected Out createOut(OutputStream stream) {
try {
return new Out(stream) {
@Override
public void print(Object object) {
if (!printVersion) {
if (object instanceof Qualifier) {
Engine engine = dataPlugin.getEngine();
Element element = StandardAttributesPlugin.getElement(engine, ((Qualifier) object).getId());
if (element == null) {
print(object.toString());
} else {
String href = "rows/index.html?id=" + element.getId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
}
} else if (object instanceof Code) {
String href = "rows/index.html?id=" + ((Code) object).getElement().getId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
} else if (object instanceof com.ramussoft.database.common.Row) {
String href = "rows/index.html?id=" + ((com.ramussoft.database.common.Row) object).getElementId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
} else
super.print(object);
} else
super.print(object);
}
};
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
};
else
impl = (ReportQuery) dataPlugin.getEngine();
if (query != null)
map.put("query", query);
page = impl.getHTMLReport(report, map);
} catch (Exception e1) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
java.io.PrintStream s = null;
try {
s = new java.io.PrintStream(stream, true, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (e1 instanceof DataException)
s.println(((DataException) e1).getMessage(new MessageFormatter() {
@Override
public String getString(String key, Object[] arguments) {
return MessageFormat.format(ReportResourceManager.getString(key), arguments);
}
}));
else {
s.println("<pre>");
e1.printStackTrace(s);
s.println("</pre>");
}
s.flush();
try {
page = new String(stream.toByteArray(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
htmlStream.println(page);
return null;
}
if (!printVersion) {
htmlStream.println("<H4>" + report.getName() + "</H4>");
}
Source source = new Source(page);
source.fullSequentialParse();
htmlStream.println(source);
return source;
}
use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.
the class Util method decompile.
public String decompile(Qualifier qualifier, String function) {
List<Attribute> attrs = qualifier.getAttributes();
final Hashtable<String, String> hash = new Hashtable<String, String>(attrs.size());
for (Attribute attr : attrs) {
if (attr.getAttributeType().toString().equals("Core.Table")) {
Qualifier table = engine.getSystemQualifier("TableQualifier_" + attr.getId());
for (Attribute tAttr : table.getAttributes()) {
hash.put(getAttributeEId(attr.getId(), tAttr.getId()), toCanonicalValue(attr.getName() + "." + tAttr.getName()));
}
}
hash.put(getAttributeEId(attr.getId()), toCanonicalValue(attr.getName()));
}
Eval eval = new Eval(function);
eval.replaceValueNames(new Replacementable() {
@Override
public String getNewName(String oldName) {
if ("ELEMENT".equals(oldName))
return oldName;
String name = hash.get(oldName);
if (name == null) {
if (oldName.startsWith(ELEMENT_PREFIX)) {
MetaValue metaValue = toMetaValue(oldName);
Element element = engine.getElement(metaValue.getElementId());
Attribute attribute = engine.getAttribute(metaValue.getAttributeId());
Qualifier qualifier = engine.getQualifier(element.getQualifierId());
return toCanonicalValue(qualifier.getName() + "." + element.getName() + "." + attribute.getName());
}
}
return name;
}
});
return eval.toString();
}
Aggregations