Search in sources :

Example 46 with Element

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);
    }
}
Also used : SQLException(java.sql.SQLException) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) ExecutionCallback(com.ramussoft.jdbc.ExecutionCallback)

Example 47 with Element

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);
    }
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 48 with Element

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;
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Element(com.ramussoft.common.Element) MessageFormatter(com.ramussoft.report.data.MessageFormatter) Source(net.htmlparser.jericho.Source) Qualifier(com.ramussoft.common.Qualifier) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine) ReportQuery(com.ramussoft.report.ReportQuery) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Code(com.ramussoft.report.Code) DataException(com.ramussoft.report.data.DataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReportQueryImpl(com.ramussoft.report.ReportQueryImpl) Out(com.ramussoft.report.data.Out) DataException(com.ramussoft.report.data.DataException) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow)

Example 49 with Element

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));
}
Also used : Element(com.ramussoft.common.Element)

Example 50 with Element

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++;
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) Row(com.ramussoft.database.common.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

Element (com.ramussoft.common.Element)142 Attribute (com.ramussoft.common.Attribute)70 Qualifier (com.ramussoft.common.Qualifier)59 ArrayList (java.util.ArrayList)48 Engine (com.ramussoft.common.Engine)27 SQLException (java.sql.SQLException)14 List (java.util.List)14 Hashtable (java.util.Hashtable)13 Row (com.ramussoft.database.common.Row)12 ElementEvent (com.ramussoft.common.event.ElementEvent)11 HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)11 Eval (com.ramussoft.eval.Eval)9 AttributeEvent (com.ramussoft.common.event.AttributeEvent)8 ElementListPersistent (com.ramussoft.core.attribute.simple.ElementListPersistent)8 Row (com.ramussoft.pb.Row)8 Journaled (com.ramussoft.common.journal.Journaled)7 FunctionPersistent (com.ramussoft.eval.FunctionPersistent)7 Util (com.ramussoft.eval.Util)7 EObject (com.ramussoft.eval.EObject)6 IOException (java.io.IOException)6