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);
}
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();
}
}
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()]);
}
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;
}
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++;
}
}
}
Aggregations