Search in sources :

Example 21 with Element

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

the class EvalPlugin method recalculate.

private void recalculate(final Engine engine, CalculateInfo info) {
    if (info.getFormula() != null) {
        Util utils = Util.getUtils(engine);
        Element element = engine.getElement(info.getElementId());
        Eval eval = utils.createAndFillEval(info, true);
        try {
            utils.fillResult(info.getAttributeId(), eval, element);
        } catch (Exception e) {
            utils.fillResult(info.getAttributeId(), e, element);
        }
    }
}
Also used : Element(com.ramussoft.common.Element) Util(com.ramussoft.eval.Util) Eval(com.ramussoft.eval.Eval) SQLException(java.sql.SQLException)

Example 22 with Element

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

the class StandardAttributesPlugin method getOrderedTableElements.

public static List<Element> getOrderedTableElements(Engine engine, Attribute attribute, Element element) {
    List<Element> elements = getTableElements(engine, attribute, element);
    String path = getTablePath(element.getId(), attribute.getId());
    byte[] bs = engine.getStream(path);
    if (bs == null)
        return elements;
    List<Element> res = new ArrayList<Element>(elements.size());
    try {
        StringTokenizer st = new StringTokenizer(new String(bs, "UTF-8"));
        while (st.hasMoreTokens()) {
            String s = st.nextToken();
            long id = Long.parseLong(s);
            Element e = null;
            for (Element element2 : elements) {
                if (element2.getId() == id) {
                    e = element2;
                    break;
                }
            }
            if (e != null) {
                res.add(e);
                elements.remove(e);
            }
        }
        res.addAll(elements);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return res;
}
Also used : StringTokenizer(java.util.StringTokenizer) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 23 with Element

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

the class StandardAttributesPlugin method hasHistory.

public static boolean hasHistory(Engine engine, Element element, Attribute attribute) {
    StandardAttributesPlugin plugin = getStandardPlugin(engine);
    List<Element> elements = engine.findElements(plugin.historyQualifier.getId(), plugin.historyElement, element.getId());
    for (Element element2 : elements) {
        Long id = (Long) engine.getAttribute(element2, plugin.historyAttribute);
        if (id.longValue() == attribute.getId())
            return true;
    }
    return false;
}
Also used : Element(com.ramussoft.common.Element)

Example 24 with Element

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

the class StandardAttributesPlugin method getHistory.

public static List<Record> getHistory(Engine engine, Element element, Attribute attribute) {
    StandardAttributesPlugin plugin = getStandardPlugin(engine);
    List<Element> elements = engine.findElements(plugin.historyQualifier.getId(), plugin.historyElement, element.getId());
    List<Record> res = new ArrayList<Record>();
    for (Element element2 : elements) {
        Long id = (Long) engine.getAttribute(element2, plugin.historyAttribute);
        if (id.longValue() == attribute.getId()) {
            Record record = new Record();
            record.setDate((Date) engine.getAttribute(element2, plugin.historyTime));
            record.setValue(engine.getAttribute(element2, attribute));
            record.setElement(element2);
            res.add(record);
        }
    }
    Collections.sort(res);
    return res;
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Record(com.ramussoft.core.history.Record)

Example 25 with Element

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

the class OtherElementPlugin method replaceElements.

@Override
public void replaceElements(Engine engine, Element[] oldElements, Element newElement) {
    for (Qualifier qualifier : getAllNotSystemQualifiers(engine)) {
        List<Attribute> attributes = new ArrayList<Attribute>();
        for (Attribute attribute : qualifier.getAttributes()) {
            if ((attribute.getAttributeType().getPluginName().equals(getName())) && (attribute.getAttributeType().getTypeName().equals(getTypeName()))) {
                OtherElementPropertyPersistent p = (OtherElementPropertyPersistent) engine.getAttribute(null, attribute);
                if (p.getQualifier() == newElement.getQualifierId())
                    attributes.add(attribute);
            }
        }
        Hashtable<Element, Object[]> hash = engine.getElements(qualifier, attributes);
        Enumeration<Element> keys = hash.keys();
        while (keys.hasMoreElements()) {
            Element key = keys.nextElement();
            Object[] objects = hash.get(key);
            int aIndex = 0;
            for (Object object : objects) if (object != null) {
                Long l = (Long) object;
                for (Element element : oldElements) {
                    if (element.getId() == l.longValue()) {
                        engine.setAttribute(key, attributes.get(aIndex), newElement.getId());
                        break;
                    }
                }
                aIndex++;
            }
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) FindObject(com.ramussoft.common.attribute.FindObject)

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