use of com.ramussoft.common.Element 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.Element in project ramus by Vitaliy-Yakovchuk.
the class AnyToAnyPlugin method copyAttribute.
@SuppressWarnings("unchecked")
@Override
public void copyAttribute(Engine sourceEngine, Engine destinationEngine, Attribute sourceAttribute, Attribute destinationAttribute, Element sourceElement, Element destinationElement, EngineParalleler paralleler) {
if (sourceElement != null) {
List<AnyToAnyPersistent> list = (List<AnyToAnyPersistent>) sourceEngine.getAttribute(sourceElement, sourceAttribute);
List<AnyToAnyPersistent> dest = new ArrayList<AnyToAnyPersistent>(list.size());
for (AnyToAnyPersistent s : list) {
AnyToAnyPersistent d = new AnyToAnyPersistent();
Element element = paralleler.getElement(s.getOtherElement());
if (element != null) {
d.setOtherElement(getId(element));
d.setElementStatus(s.getElementStatus());
dest.add(d);
}
}
destinationEngine.setAttribute(destinationElement, destinationAttribute, dest);
}
}
use of com.ramussoft.common.Element 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.Element in project ramus by Vitaliy-Yakovchuk.
the class AbstractAttributePlugin method syncElement.
@Override
public void syncElement(Engine engine, QualifierImporter importer, Element sourceElement, Attribute sourceAttribute) {
Element dest = importer.getDestination(sourceElement);
engine.setAttribute(dest, importer.getDestination(sourceAttribute), importer.getSourceValue(sourceElement, sourceAttribute));
}
use of com.ramussoft.common.Element in project ramus by Vitaliy-Yakovchuk.
the class ComplexImport method importDromSheet.
public void importDromSheet(Sheet sheet, String sheetName, int startFrom, ImportRule[] rules) {
this.sheetName = sheetName;
Attribute name = rowSet.getEngine().getAttribute(rowSet.getQualifier().getAttributeForName());
Row current = null;
int row = startFrom;
while (true) {
org.apache.poi.ss.usermodel.Row row2 = sheet.getRow(row);
if (row2 == null)
break;
for (ImportRule rule : rules) {
if (rule.getAttribute().equals(name)) {
String s = null;
if (rule.getColumn() >= 0) {
Cell cell = row2.getCell(rule.getColumn());
if (cell != null) {
s = cell.getStringCellValue();
}
} else
s = sheetName;
if ((s != null) && (!"".equals(s))) {
Element element = null;
if (uniqueName)
element = rowSet.getEngine().getElement(s, rowSet.getQualifier().getId());
if (element != null)
current = null;
else {
current = rowSet.createRow(null);
}
for (ImportRule rule2 : rules) rule2.setObject(null);
}
}
}
Hashtable<Attribute, Element> tableElements = new Hashtable<Attribute, Element>(1);
if (current != null)
for (ImportRule rule : rules) {
if (rule.getColumn() == -1) {
if (rule.getTableAttribute() == null) {
fill(current.getElement(), null, rule.getAttribute(), rule);
} else {
Element tableElement = tableElements.get(rule.getAttribute());
if (tableElement == null) {
tableElement = StandardAttributesPlugin.createTableElement(rowSet.getEngine(), rule.getAttribute(), current.getElement());
tableElements.put(rule.getAttribute(), tableElement);
}
fill(tableElement, null, rule.getTableAttribute(), rule);
}
} else {
Cell cell = row2.getCell(rule.getColumn());
if (cell != null) {
if (rule.getTableAttribute() == null) {
fill(current.getElement(), cell, rule.getAttribute(), rule);
} else {
if (!isNull(cell)) {
Element tableElement = tableElements.get(rule.getAttribute());
if (tableElement == null) {
tableElement = StandardAttributesPlugin.createTableElement(rowSet.getEngine(), rule.getAttribute(), current.getElement());
tableElements.put(rule.getAttribute(), tableElement);
}
fill(tableElement, cell, rule.getTableAttribute(), rule);
}
}
}
}
}
row++;
}
}
Aggregations