Search in sources :

Example 56 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class HTTPParser method printMatrixProjection.

private void printMatrixProjection() throws IOException {
    final String sId = (String) params.get("matrixid");
    if (sId == null) {
        printMatrixError();
        return;
    }
    final Long id = Long.parseLong(sId);
    if (id == null) {
        printMatrixError();
        return;
    }
    Engine engine = dataPlugin.getEngine();
    Attribute mp = engine.getAttribute(id);
    if (mp == null) {
        printMatrixError();
        return;
    }
    htmlTitle = RES.getString("matrixProjection") + " " + mp.getName();
    printStartD();
    boolean rotate = "true".equals(params.get("rotate"));
    htmlStream.print("<center><h2 class=\"Ramus\">" + RES.getString("matrixProjection") + ": " + mp.getName() + "</h2></center>");
    htmlStream.println("<table width=100%>");
    htmlStream.println("<tr>");
    htmlStream.println("<td  valign=top align=center width=50%>");
    ElementListPropertyPersistent pp = (ElementListPropertyPersistent) engine.getAttribute(null, mp);
    Qualifier qualifier1 = engine.getQualifier(pp.getQualifier1());
    Qualifier qualifier2 = engine.getQualifier(pp.getQualifier2());
    if (rotate) {
        Qualifier tmp = qualifier1;
        qualifier1 = qualifier2;
        qualifier2 = tmp;
    }
    htmlStream.println("<table border=1 width=100%>");
    List<Row> rows = (List) dataPlugin.getRowSet(qualifier1.getId()).getAllRows();
    printMainTableTitle(qualifier1.getName());
    final Row leftRow = loadRowById();
    for (int i = 0; i < rows.size(); i++) {
        final Row row = (Row) rows.get(i);
        final boolean gray = i % 2 == 0;
        String sGray = "";
        String bs = "";
        String be = "";
        if (row.equals(leftRow)) {
            bs = "<i>";
            be = "</i>";
        }
        if (gray)
            sGray = " bgcolor=" + GRAY;
        String href = "matrixprojections/index.html?id=" + row.getGlobalId().toString() + "&matrixid=" + sId + (rotate ? "&rotate=true" : "");
        htmlStream.print("<tr>");
        htmlStream.print("<td" + sGray + ">");
        printStartATeg("rows/index.html?id=" + row.getElement().getId());
        htmlStream.print("^");
        printEndATeg();
        printStartATeg(href);
        htmlStream.print(bs);
        printRowKod(row, false, IDEF0Plugin.isFunction(qualifier1));
        htmlStream.print(be);
        if (href != null)
            printEndATeg();
        htmlStream.print("</td>");
        htmlStream.print("<td" + sGray + ">");
        printStartATeg(href);
        htmlStream.print(bs);
        printRowName(row, false);
        htmlStream.print(be);
        if (href != null)
            printEndATeg();
        htmlStream.print("</td>");
        htmlStream.println("</tr>");
    }
    htmlStream.println("</table>");
    htmlStream.println("</td>");
    htmlStream.println("<td valign=top align=center width=50%>");
    final String row2Name = qualifier2.getName() + " (" + RES.getString("addedElements") + (leftRow == null ? "" : " " + leftRow.getKod() + ". " + leftRow.getName()) + ")";
    if (leftRow != null) {
        List<ElementListPersistent> left = (List<ElementListPersistent>) engine.getAttribute(leftRow.getElement(), mp);
        final Vector v = new Vector();
        for (ElementListPersistent p : left) {
            if (rotate) {
                v.add(dataPlugin.findRowByGlobalId(p.getElement1Id()));
            } else {
                v.add(dataPlugin.findRowByGlobalId(p.getElement2Id()));
            }
        }
        printElements(row2Name, v.toArray(), null);
    } else {
        htmlStream.println("<table width=100%>");
        htmlStream.println("<caption>");
        printSmallTitle(row2Name);
        htmlStream.println("</caption>");
        htmlStream.println("</table>");
    }
    htmlStream.println("</td>");
    htmlStream.println("</tr>");
    htmlStream.println("</table>");
    String href = "matrixprojections/index.html?matrixid=" + sId;
    if (!rotate)
        href += "&rotate=" + "true";
    htmlStream.println("<p align=right>");
    printStartATeg(href);
    htmlStream.println(RES.getString("rotate"));
    printEndATeg();
    htmlStream.println("</p>");
    printEndD();
}
Also used : ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) Attribute(com.ramussoft.common.Attribute) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) Qualifier(com.ramussoft.common.Qualifier) List(java.util.List) ArrayList(java.util.ArrayList) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow) Vector(java.util.Vector) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine)

Example 57 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class VariantAttributeViewer method printAttribute.

@Override
public void printAttribute(PrintStream printStream, DataPlugin dataPlugin, Element element, Attribute attribute, HTTPParser parser, AttributeViewerCallback callback) throws IOException {
    Engine engine = dataPlugin.getEngine();
    String value = (String) engine.getAttribute(element, attribute);
    if (value != null) {
        List<VariantPropertyPersistent> list = (List<VariantPropertyPersistent>) engine.getAttribute(null, attribute);
        VariantPropertyPersistent vp = null;
        for (VariantPropertyPersistent persistent : list) {
            if (persistent.getValue().equals(value))
                vp = persistent;
        }
        if (vp != null) {
            long id = StandardAttributesPlugin.getElement(engine, element.getQualifierId()).getId();
            callback.beforePrint(printStream);
            parser.printStartATeg("rows/index.html?id=" + id + "&var=" + vp.getVariantId() + "&attr=" + attribute.getId());
            printStream.print(value);
            parser.printEndATeg();
            callback.afterPrint(printStream);
        }
    }
}
Also used : VariantPropertyPersistent(com.ramussoft.core.attribute.simple.VariantPropertyPersistent) List(java.util.List) Engine(com.ramussoft.common.Engine)

Example 58 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class SuperEngineFactory method createTransactionalEngine.

@SuppressWarnings("unchecked")
public static Object createTransactionalEngine(Engine engine, Journaled journal) {
    String[] classes = engine.getAllImplementationClasseNames();
    Class[] clazzes = new Class[classes.length];
    for (int i = 0; i < classes.length; i++) {
        try {
            clazzes[i] = Class.forName(classes[i]);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    SuperInvoker invoker = null;
    if (engine instanceof AbstractJournaledEngine) {
        AbstractJournaledEngine abstractJournaledEngine = (AbstractJournaledEngine) engine;
        invoker = abstractJournaledEngine.createSuperInvoker(classes, clazzes, journal);
    } else if (engine instanceof CachedEngine) {
        Object[] objects = new Object[classes.length];
        Engine engine2 = ((CachedEngine) engine).getSource();
        AbstractJournaledEngine abstractJournaledEngine = null;
        if (engine2 instanceof AbstractJournaledEngine) {
            abstractJournaledEngine = (AbstractJournaledEngine) engine2;
            invoker = abstractJournaledEngine.createSuperInvoker(classes, clazzes, journal);
        }
        for (int i = 0; i < objects.length; i++) {
            String className = classes[i];
            if (className.equals(Engine.class.getName())) {
                objects[i] = engine;
            } else if (className.equals(Journaled.class.getName())) {
                objects[i] = new UserTransactional(journal);
            } else {
                for (Plugin plugin : abstractJournaledEngine.pluginFactory.getPlugins()) {
                    Class class1 = plugin.getFunctionalInterface();
                    if (class1 != null)
                        if (class1.equals(clazzes[i])) {
                            objects[i] = plugin.createFunctionalInterfaceObject(engine, engine.getDeligate());
                        }
                }
            }
        }
        invoker = new SuperInvoker(classes, clazzes, objects);
    }
    return Proxy.newProxyInstance(SuperEngineFactory.class.getClassLoader(), clazzes, new Caller(invoker));
}
Also used : CachedEngine(com.ramussoft.common.cached.CachedEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin)

Example 59 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class RolesConnection method getConnected.

@Override
public Rows getConnected(final Data data, Row row) {
    Integer type = (Integer) row.getAttribute(IDEF0Plugin.getFunctionTypeAttribute(row.getEngine()));
    if (type != null && type.intValue() == 1003) {
        Long id = (Long) row.getAttribute(IDEF0Plugin.getLinkAttribute(row.getEngine()));
        Rows rows = new Rows(row.getRowSet(), data, false);
        if (id != null) {
            Row row2 = data.findRow(id);
            if (row2 != null) {
                List<AnyToAnyPersistent> list = (List) row2.getAttribute(IDEF0Plugin.getStreamAddedAttribute(row2.getEngine()));
                for (AnyToAnyPersistent anyPersistent : list) {
                    Row row3 = data.findRow(anyPersistent.getOtherElement());
                    row3.setElementStatus(anyPersistent.getElementStatus());
                    rows.add(row3);
                }
            }
        }
        return rows;
    }
    RolesConnection connection = (RolesConnection) data.get("RolesConnection");
    if (connection != null)
        return connection.getRoles(data, row);
    final Engine engine = data.getEngine();
    ArrayList<Long> ounerQualifierIds = loadOunerIDs(engine);
    roles = new Hashtable<Row, List<Row>>();
    final Hashtable<Row, List<Row>> mech = new Hashtable<Row, List<Row>>();
    RowMapper mapper = new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(1));
            Row row = (Row) rowSet.findRow(rs.getLong(2));
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row role = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (row == null || role == null)
                return null;
            List<Row> rows = mech.get(row);
            if (rows == null) {
                rows = new ArrayList<Row>(5);
                mech.put(row, rows);
            }
            if (!rows.contains(role))
                rows.add(role);
            return null;
        }
    };
    if (ounerQualifierIds.size() > 0) {
        data.getTemplate().queryWithoutResults("SELECT b.qualifier_id, function, ramus_elements.qualifier_id, ramus_elements.element_id FROM\n" + "ramus_attribute_sector_borders, ramus_attribute_other_elements, ramus_attribute_any_to_any_elements, ramus_elements, ramus_elements b\n" + "WHERE ramus_attribute_any_to_any_elements.element_id=ramus_attribute_other_elements.other_element\n" + "AND ramus_elements.element_id=ramus_attribute_any_to_any_elements.other_element\n" + "AND ramus_attribute_sector_borders.element_id = ramus_attribute_other_elements.element_id\n" + "AND function_type=1 AND ramus_attribute_sector_borders.attribute_id in\n" + "(SELECT attribute_id FROM ramus_attributes WHERE attribute_system=true AND attribute_name='F_SECTOR_BORDER_END')\n" + "AND b.element_id=function\n" + "AND ramus_elements.qualifier_id in " + toIns(ounerQualifierIds), mapper, true);
    }
    data.getTemplate().queryWithoutResults("SELECT (SELECT qualifier_id FROM ramus_elements WHERE element_id=ouner_id) as function_qualifier_id, " + "ouner_id AS function,  " + "(SELECT qualifier_id FROM ramus_elements WHERE element_id=other_element) as ouner_qualifier_id, " + "other_element as ouner_id FROM ramus_attribute_any_to_any_elements, ramus_attribute_function_ouners " + "WHERE ramus_attribute_any_to_any_elements.element_id IN " + "(SELECT value FROM ramus_attribute_longs WHERE ramus_attribute_longs.element_id=ramus_attribute_function_ouners.element_id)", mapper, true);
    data.getTemplate().queryWithoutResults("SELECT ramus_attribute_function_ouners.element_id,\n" + "(SELECT MAX(ramus_elements.qualifier_id) FROM ramus_elements WHERE ramus_elements.element_id=ramus_attribute_function_ouners.element_id),\n" + "ramus_elements.qualifier_id,\n" + " ouner_id FROM ramus_elements, ramus_attribute_function_ouners WHERE ramus_elements.element_id=ouner_id " + "AND ramus_attribute_function_ouners.ouner_id IN (SELECT element_id FROM ramus_attribute_function_types WHERE type<1001)", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(2));
            Row row = (Row) rowSet.findRow(rs.getLong(1));
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (ouner != null && row != null) {
                List<Row> rows = roles.get(row);
                if (rows == null) {
                    rows = new ArrayList<Row>();
                    roles.put(row, rows);
                }
                if (!rows.contains(ouner))
                    rows.add(ouner);
            }
            return null;
        }
    }, true);
    RowSet rowSet = data.getRowSet(row.getQualifier());
    setRecOuners(rowSet.getRoot(), mech, null);
    data.put("RolesConnection", this);
    return getRoles(data, row);
}
Also used : SQLException(java.sql.SQLException) Hashtable(java.util.Hashtable) RowSet(com.ramussoft.report.data.RowSet) ArrayList(java.util.ArrayList) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Row(com.ramussoft.report.data.Row) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.report.data.Rows) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 60 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class ElementListAttributeViewer method printAttribute.

@Override
public void printAttribute(PrintStream printStream, DataPlugin dataPlugin, Element element, Attribute attribute, HTTPParser parser, AttributeViewerCallback callback) throws IOException {
    Engine engine = dataPlugin.getEngine();
    Qualifier qualifier = engine.getQualifier(element.getQualifierId());
    List<ElementListPersistent> list = (List<ElementListPersistent>) engine.getAttribute(element, attribute);
    ElementListPropertyPersistent pp = (ElementListPropertyPersistent) engine.getAttribute(null, attribute);
    boolean left = qualifier.getId() == pp.getQualifier2();
    if (list.size() > 0) {
        callback.beforePrint(printStream);
        printStream.println("<br>");
        for (ElementListPersistent p : list) {
            long id;
            if (left)
                id = p.getElement1Id();
            else
                id = p.getElement2Id();
            Element element2 = engine.getElement(id);
            if (element2 != null) {
                printLinkToElement(element2, parser, printStream);
                printStream.println("<br>");
            }
        }
        callback.afterPrint(printStream);
    }
}
Also used : ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) Element(com.ramussoft.common.Element) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) Qualifier(com.ramussoft.common.Qualifier) List(java.util.List) Engine(com.ramussoft.common.Engine)

Aggregations

Engine (com.ramussoft.common.Engine)85 Attribute (com.ramussoft.common.Attribute)32 ArrayList (java.util.ArrayList)30 Element (com.ramussoft.common.Element)27 Qualifier (com.ramussoft.common.Qualifier)22 AccessRules (com.ramussoft.common.AccessRules)21 List (java.util.List)19 IEngine (com.ramussoft.common.IEngine)15 Row (com.ramussoft.database.common.Row)13 IOException (java.io.IOException)11 SQLException (java.sql.SQLException)11 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)8 Journaled (com.ramussoft.common.journal.Journaled)8 CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Hashtable (java.util.Hashtable)7 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)6 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)5 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5