use of com.ramussoft.common.Attribute 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.Attribute 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.Attribute in project ramus by Vitaliy-Yakovchuk.
the class HTTPParser method printClasificator.
private void printClasificator() throws IOException {
final Row row = loadRowById();
if (row == null) {
printError(RES.getString("cantLoatClasificator"));
return;
}
if (row instanceof Function) {
htmlTitle = MovingFunction.getIDEF0Kod((com.ramussoft.database.common.Row) row) + " " + row.getName();
} else
htmlTitle = row.getKod() + ". " + row.getName();
printStartD();
printRowBase(row);
if (row instanceof Function) {
boolean b = true;
if (!row.isLeaf()) {
b = false;
htmlStream.println("<br>");
printStartATeg("idef0/index.html?id=" + row.getGlobalId().toString());
htmlStream.print(RES.getString("idef0Model"));
printEndATeg();
}
if (row.isElement()) {
if (b)
htmlStream.println("<br>");
else
htmlStream.print(" ");
printStartATeg("idef0/index.html?id=" + row.getParentRow().getGlobalId().toString());
htmlStream.print(RES.getString("ParentIDEF0Model"));
printEndATeg();
}
htmlStream.println("<br>");
} else if (row instanceof Stream && !dataPlugin.getBaseStream().equals(row)) {
printStreamsRows((Stream) row);
}
boolean haveTable = false;
Vector<Row> v = dataPlugin.getChilds(row, row.isElement());
if (v.size() > 0) {
if (haveTable)
htmlStream.println("<br>");
printElements(RES.getString("childElements"), v.toArray(), row.isElement() ? "rows" : "clasificators");
haveTable = true;
}
if (!row.isElement()) {
if (haveTable)
htmlStream.println("<br>");
v = dataPlugin.getRecChilds(row, true);
htmlStream.println("<hr>");
String var = params.get("var");
String attr = params.get("attr");
if (var != null) {
Engine engine = dataPlugin.getEngine();
long attrId = Long.parseLong(attr);
long varId = Long.parseLong(var);
Attribute attribute = engine.getAttribute(attrId);
List<VariantPropertyPersistent> list = (List<VariantPropertyPersistent>) engine.getAttribute(null, attribute);
VariantPropertyPersistent vpp = null;
for (VariantPropertyPersistent vp : list) if (vp.getVariantId() == varId) {
vpp = vp;
break;
}
if ((vpp != null) && (vpp.getValue() != null)) {
String value = vpp.getValue();
ArrayList list1 = new ArrayList();
for (Row r : v) {
if (value.equals(((NRow) r).getAttribute(attribute)))
list1.add(r);
}
htmlStream.println("(" + value + ")");
htmlStream.println("<br>");
printElements(RES.getString("childElements"), list1.toArray(), row.isElement() ? "rows" : "clasificators");
}
} else
printElements(RES.getString("clasificatorElements"), v.toArray());
} else
printRowAttributes(row);
if (row instanceof Function && (row.isElement())) {
printFunctionsArrows((Function) row);
} else if (!(row instanceof Stream)) {
printArrowFunctionss(row);
}
printEndD();
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class HTTPParser method printMatrixProjectionsList.
protected void printMatrixProjectionsList() throws IOException {
final Attribute[] attrs = StandardAttributesPlugin.getElementLists(dataPlugin.getEngine());
if (attrs.length <= 0)
return;
printMainTableTitle(RES.getString("matrixProjectionsTitle"));
for (Attribute attr : attrs) {
String name = attr.getName();
htmlStream.println("<tr><td colspan=2>");
printStartATeg("matrixprojections/index.html?matrixid=" + attr.getId());
htmlStream.print(name);
printEndATeg();
htmlStream.println("</td></tr>");
}
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class Row method getNameObject.
public Object getNameObject() {
if (element == null) {
return "No element in this row";
}
long id = rowSet.getQualifier().getAttributeForName();
for (Attribute attr : attributes) {
if (attr.getId() == id) {
return getAttribute(attr);
}
}
Attribute attribute = engine.getAttribute(id);
if (attribute != null)
return engine.getAttribute(element, attribute);
return element.getName();
}
Aggregations