Search in sources :

Example 6 with FunctionPersistent

use of com.ramussoft.eval.FunctionPersistent in project ramus by Vitaliy-Yakovchuk.

the class EvalQualifierSetupEditor method recCheck.

private void recCheck(FunctionPersistent fp, Hashtable<FunctionPersistent, Eval> hash, ArrayList<FunctionPersistent> auto, ArrayList<Attribute> recList, ArrayList<String> list) {
    for (Attribute attr : recList) {
        if (fp.getQualifierAttributeId() == attr.getId()) {
            String message = GlobalResourcesManager.getString("Recursive.Link");
            if (list.indexOf(message) < 0)
                list.add(message);
            return;
        }
    }
    Attribute attribute = null;
    for (Attribute a : qualifier.getAttributes()) if (fp.getQualifierAttributeId() == a.getId())
        attribute = a;
    recList.add(attribute);
    Eval eval = getEval(fp, hash);
    for (String value : eval.getValues()) for (Attribute a : qualifier.getAttributes()) if (a.getName().equals(value)) {
        FunctionPersistent inAuto = null;
        for (FunctionPersistent fp1 : auto) if (fp1.getQualifierAttributeId() == a.getId()) {
            inAuto = fp1;
            break;
        }
        if (inAuto != null) {
            recCheck(inAuto, hash, auto, recList, list);
        }
    }
    recList.remove(attribute);
}
Also used : Attribute(com.ramussoft.common.Attribute) FunctionPersistent(com.ramussoft.eval.FunctionPersistent) Eval(com.ramussoft.eval.Eval)

Example 7 with FunctionPersistent

use of com.ramussoft.eval.FunctionPersistent in project ramus by Vitaliy-Yakovchuk.

the class EvalQualifierSetupEditor method load.

@SuppressWarnings("unchecked")
@Override
public void load(Engine engine, Qualifier qualifier) {
    this.engine = engine;
    this.qualifier = qualifier;
    Element element = StandardAttributesPlugin.getElement(engine, qualifier.getId());
    List<FunctionPersistent> list = EvalPlugin.getFunctionAttribute(engine, element);
    if (list == null)
        list = new ArrayList<FunctionPersistent>(0);
    Util utils = Util.getUtils(engine);
    Hashtable<Attribute, ArrayList<Attribute>> attrs = new Hashtable<Attribute, ArrayList<Attribute>>();
    int lentgh = 0;
    for (Attribute attr : qualifier.getAttributes()) {
        if (attr.getAttributeType().toString().equals("Core.Table")) {
            ArrayList<Attribute> aList = new ArrayList<Attribute>();
            attrs.put(attr, aList);
            Qualifier q = StandardAttributesPlugin.getTableQualifierForAttribute(engine, attr);
            aList.addAll(q.getAttributes());
            lentgh += q.getAttributes().size();
        } else {
            attrs.put(attr, new ArrayList<Attribute>(0));
            lentgh++;
        }
    }
    functions = new FunctionPersistent[lentgh];
    names = new String[lentgh];
    attributes = new Attribute[lentgh];
    tableAttributes = new Attribute[lentgh];
    int i = 0;
    for (Attribute attribute : attrs.keySet()) {
        if (attribute.getAttributeType().toString().equals("Core.Table")) {
            for (Attribute tableAttribute : attrs.get(attribute)) {
                attributes[i] = attribute;
                tableAttributes[i] = tableAttribute;
                names[i] = Util.toCanonicalValue(attribute.getName() + "." + tableAttribute.getName());
                functions[i] = getFunction(list, attribute, tableAttribute, utils);
                i++;
            }
        } else {
            attributes[i] = attribute;
            names[i] = Util.toCanonicalValue(attribute.getName());
            functions[i] = getFunction(list, attribute, null, utils);
            i++;
        }
    }
    if (this.qualifier != null) {
        this.fireTableDataChanged();
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Util(com.ramussoft.eval.Util) Qualifier(com.ramussoft.common.Qualifier) FunctionPersistent(com.ramussoft.eval.FunctionPersistent)

Example 8 with FunctionPersistent

use of com.ramussoft.eval.FunctionPersistent in project ramus by Vitaliy-Yakovchuk.

the class EvalQualifierSetupEditor method getErrors.

@Override
public String[] getErrors() {
    ArrayList<String> list = new ArrayList<String>();
    ArrayList<FunctionPersistent> auto = new ArrayList<FunctionPersistent>();
    for (FunctionPersistent fp : functions) if (fp != null) {
        if (fp.getAutochange() != 0)
            auto.add(fp);
    }
    Hashtable<FunctionPersistent, Eval> hash = new Hashtable<FunctionPersistent, Eval>();
    for (FunctionPersistent fp : functions) if (fp != null) {
        try {
            getEval(fp, hash);
        } catch (Exception e) {
            list.add(MessageFormat.format(GlobalResourcesManager.getString("Eval.Error"), fp.getFunction()));
        }
    }
    if (list.size() == 0)
        for (FunctionPersistent fp : functions) if (fp != null) {
            check(list, fp, auto, hash);
        }
    return list.toArray(new String[list.size()]);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FunctionPersistent(com.ramussoft.eval.FunctionPersistent) Eval(com.ramussoft.eval.Eval)

Example 9 with FunctionPersistent

use of com.ramussoft.eval.FunctionPersistent in project ramus by Vitaliy-Yakovchuk.

the class EvalPlugin method getFunctions.

@SuppressWarnings("unchecked")
public static List<FunctionPersistent> getFunctions(Engine engine, Qualifier qualifier) {
    Element element = StandardAttributesPlugin.getElement(engine, qualifier.getId());
    List<FunctionPersistent> res = getFunctionAttribute(engine, element);
    if (res == null)
        return new ArrayList<FunctionPersistent>(0);
    return res;
}
Also used : Element(com.ramussoft.common.Element) FunctionPersistent(com.ramussoft.eval.FunctionPersistent)

Example 10 with FunctionPersistent

use of com.ramussoft.eval.FunctionPersistent in project ramus by Vitaliy-Yakovchuk.

the class EvalPlugin method calculate.

public static void calculate(Engine engine, Qualifier qualifier, List<FunctionPersistent> functions) {
    Util utils = Util.getUtils(engine);
    Eval[] evals = utils.sort(functions);
    List<Attribute> sources = new ArrayList<Attribute>();
    for (Eval eval : evals) {
        utils.addAttributes(sources, eval, qualifier.getAttributes());
    }
    Hashtable<Element, Object[]> hash = engine.getElements(qualifier, sources);
    for (Entry<Element, Object[]> entry : hash.entrySet()) {
        Element element = entry.getKey();
        Object[] values = entry.getValue();
        int i = 0;
        for (Eval eval : evals) {
            utils.fillAttributes(eval, element, sources, values, true);
            FunctionPersistent fp = functions.get(i);
            if (fp.getQualifierTableAttributeId() == -1l) {
                try {
                    Object object = utils.fillResult(fp.getQualifierAttributeId(), eval, element);
                    for (int j = 0; j < values.length; j++) {
                        if (sources.get(j).getId() == fp.getQualifierAttributeId())
                            values[j] = object;
                    }
                } catch (Exception e) {
                    utils.fillResult(fp.getQualifierAttributeId(), e, element);
                }
            } else {
                Attribute tableAttribute = engine.getAttribute(fp.getQualifierAttributeId());
                Qualifier tableQualifier = StandardAttributesPlugin.getTableQualifierForAttribute(engine, tableAttribute);
                List<Element> tableElements = StandardAttributesPlugin.getTableElements(engine, tableAttribute, element);
                List<Attribute> tableAttributes = utils.getTableAttributes(tableQualifier, fp.getQualifierAttributeId(), eval);
                for (Element tableElement : tableElements) {
                    for (Attribute attr : tableAttributes) {
                        Object value = engine.getAttribute(tableElement, attr);
                        eval.setValue(Util.tableAttributeToValue(fp.getQualifierAttributeId(), attr.getId()), new EObject(value, tableElement, attr, engine));
                    }
                    try {
                        utils.fillResult(fp.getQualifierTableAttributeId(), eval, tableElement);
                    } catch (Exception e) {
                        utils.fillResult(fp.getQualifierTableAttributeId(), e, tableElement);
                    }
                }
            }
            i++;
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Util(com.ramussoft.eval.Util) SQLException(java.sql.SQLException) EObject(com.ramussoft.eval.EObject) EObject(com.ramussoft.eval.EObject) Qualifier(com.ramussoft.common.Qualifier) FunctionPersistent(com.ramussoft.eval.FunctionPersistent) Eval(com.ramussoft.eval.Eval)

Aggregations

FunctionPersistent (com.ramussoft.eval.FunctionPersistent)10 Attribute (com.ramussoft.common.Attribute)7 Element (com.ramussoft.common.Element)7 Eval (com.ramussoft.eval.Eval)7 Util (com.ramussoft.eval.Util)6 ArrayList (java.util.ArrayList)6 Qualifier (com.ramussoft.common.Qualifier)5 EObject (com.ramussoft.eval.EObject)3 SQLException (java.sql.SQLException)3 MetaValue (com.ramussoft.eval.MetaValue)2 Replacementable (com.ramussoft.eval.Replacementable)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 AttributeType (com.ramussoft.common.AttributeType)1 CalculateInfo (com.ramussoft.common.CalculateInfo)1 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 AttributeEvent (com.ramussoft.common.event.AttributeEvent)1 ElementAdapter (com.ramussoft.common.event.ElementAdapter)1 ElementAttributeListener (com.ramussoft.common.event.ElementAttributeListener)1