Search in sources :

Example 46 with Qualifier

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

the class IDEF0Plugin method checkModelTree.

private void checkModelTree(Qualifier modelTree) {
    List<Qualifier> models = new ArrayList<Qualifier>();
    List<Qualifier> qList = engine.getQualifiers();
    for (Qualifier qualifier : qList) {
        if (IDEF0Plugin.isFunction(qualifier)) {
            models.add(qualifier);
        }
    }
    Collections.sort(models, new Comparator<Qualifier>() {

        @Override
        public int compare(Qualifier o1, Qualifier o2) {
            return StringCollator.compare(o1.getName(), o2.getName());
        }
    });
    Attribute attribute = StandardAttributesPlugin.getAttributeQualifierId(engine);
    RowSet rowSet = new RowSet(engine, modelTree, new Attribute[] { attribute }, null, true);
    for (Row row : rowSet.getAllRows()) {
        for (int i = models.size() - 1; i >= 0; --i) {
            Qualifier model = models.get(i);
            Long id = (Long) row.getAttribute(attribute);
            if (id != null && model.getId() == id.longValue()) {
                models.remove(i);
                break;
            }
        }
    }
    for (Qualifier model : models) {
        Row row = rowSet.createRow(null);
        row.setName(model.getName());
        row.setAttribute(attribute, model.getId());
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) ArrayList(java.util.ArrayList) RowSet(com.ramussoft.database.common.RowSet) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.database.common.Row)

Example 47 with Qualifier

use of com.ramussoft.common.Qualifier 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 48 with Qualifier

use of com.ramussoft.common.Qualifier 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 49 with Qualifier

use of com.ramussoft.common.Qualifier 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 50 with Qualifier

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

the class Util method decompile.

public String decompile(Qualifier qualifier, String function) {
    List<Attribute> attrs = qualifier.getAttributes();
    final Hashtable<String, String> hash = new Hashtable<String, String>(attrs.size());
    for (Attribute attr : attrs) {
        if (attr.getAttributeType().toString().equals("Core.Table")) {
            Qualifier table = engine.getSystemQualifier("TableQualifier_" + attr.getId());
            for (Attribute tAttr : table.getAttributes()) {
                hash.put(getAttributeEId(attr.getId(), tAttr.getId()), toCanonicalValue(attr.getName() + "." + tAttr.getName()));
            }
        }
        hash.put(getAttributeEId(attr.getId()), toCanonicalValue(attr.getName()));
    }
    Eval eval = new Eval(function);
    eval.replaceValueNames(new Replacementable() {

        @Override
        public String getNewName(String oldName) {
            if ("ELEMENT".equals(oldName))
                return oldName;
            String name = hash.get(oldName);
            if (name == null) {
                if (oldName.startsWith(ELEMENT_PREFIX)) {
                    MetaValue metaValue = toMetaValue(oldName);
                    Element element = engine.getElement(metaValue.getElementId());
                    Attribute attribute = engine.getAttribute(metaValue.getAttributeId());
                    Qualifier qualifier = engine.getQualifier(element.getQualifierId());
                    return toCanonicalValue(qualifier.getName() + "." + element.getName() + "." + attribute.getName());
                }
            }
            return name;
        }
    });
    return eval.toString();
}
Also used : Attribute(com.ramussoft.common.Attribute) Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier)

Aggregations

Qualifier (com.ramussoft.common.Qualifier)157 Attribute (com.ramussoft.common.Attribute)72 Element (com.ramussoft.common.Element)59 ArrayList (java.util.ArrayList)45 Engine (com.ramussoft.common.Engine)22 Row (com.ramussoft.database.common.Row)17 Row (com.ramussoft.pb.Row)14 List (java.util.List)12 Hashtable (java.util.Hashtable)11 QualifierEvent (com.ramussoft.common.event.QualifierEvent)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 AttributeType (com.ramussoft.common.AttributeType)8 RowSet (com.ramussoft.database.common.RowSet)8 DataPlugin (com.ramussoft.pb.DataPlugin)8 NFunction (com.ramussoft.pb.data.negine.NFunction)8 AttributeEvent (com.ramussoft.common.event.AttributeEvent)7 Journaled (com.ramussoft.common.journal.Journaled)7 RowMapper (com.ramussoft.jdbc.RowMapper)7 IEngine (com.ramussoft.common.IEngine)6