Search in sources :

Example 61 with Attribute

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);
    }
}
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 62 with Attribute

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

Example 63 with Attribute

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();
}
Also used : Attribute(com.ramussoft.common.Attribute) ArrayList(java.util.ArrayList) VariantPropertyPersistent(com.ramussoft.core.attribute.simple.VariantPropertyPersistent) Function(com.ramussoft.pb.Function) MovingFunction(com.ramussoft.pb.idef.visual.MovingFunction) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Stream(com.ramussoft.pb.Stream) InputStream(java.io.InputStream) List(java.util.List) ArrayList(java.util.ArrayList) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine)

Example 64 with Attribute

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

Example 65 with Attribute

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

Aggregations

Attribute (com.ramussoft.common.Attribute)203 Qualifier (com.ramussoft.common.Qualifier)72 Element (com.ramussoft.common.Element)70 ArrayList (java.util.ArrayList)53 Engine (com.ramussoft.common.Engine)32 List (java.util.List)20 Row (com.ramussoft.database.common.Row)19 Hashtable (java.util.Hashtable)19 SQLException (java.sql.SQLException)16 AttributeType (com.ramussoft.common.AttributeType)15 FindObject (com.ramussoft.common.attribute.FindObject)11 AttributeEvent (com.ramussoft.common.event.AttributeEvent)11 ResultSet (java.sql.ResultSet)11 AttributePlugin (com.ramussoft.gui.common.AttributePlugin)10 AccessRules (com.ramussoft.common.AccessRules)9 Transaction (com.ramussoft.common.persistent.Transaction)9 HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)9 RowMapper (com.ramussoft.jdbc.RowMapper)9 Row (com.ramussoft.pb.Row)9 ImageIcon (javax.swing.ImageIcon)9