protected static NSArray prepareJournalZPU( Enumeration substitutes, Enumeration variations, SchoolSection section) { NSMutableArray result = new NSMutableArray(); NSMutableSet lessons = new NSMutableSet(); if (variations != null) { while (variations.hasMoreElements()) { Variation var = (Variation) variations.nextElement(); if (section != null && !section.equals(var.valueForKeyPath("course.cycle.section"))) continue; EduLesson lesson = var.relatedLesson(); if (lesson != null) { if (lessons.containsObject(lesson)) continue; lessons.addObject(lesson); } NSMutableDictionary dict = convertEvent(var); NSArray multiply = (NSArray) dict.valueForKey("multiply"); if (multiply != null) { Enumeration mul = multiply.objectEnumerator(); while (mul.hasMoreElements()) { Substitute sub = (Substitute) mul.nextElement(); NSMutableDictionary clon = dict.mutableClone(); clon.takeValueForKey(sub.teacher(), "plusTeacher"); clon.takeValueForKey(sub.value(), "value"); result.addObject(clon); } } else { result.addObject(dict); } } } if (substitutes != null) { while (substitutes.hasMoreElements()) { Substitute sub = (Substitute) substitutes.nextElement(); EduLesson lesson = sub.lesson(); if (lessons.containsObject(lesson)) continue; if (section != null && !section.equals(lesson.valueForKeyPath("course.cycle.section"))) continue; // lessons.addObject(sub.lesson()); NSMutableDictionary dict = convertEvent(sub); result.addObject(dict); } } NSArray sorter = new NSArray( new EOSortOrdering[] { new EOSortOrdering("date", EOSortOrdering.CompareAscending), new EOSortOrdering("minusTeacher", EOSortOrdering.CompareAscending), new EOSortOrdering("grade", EOSortOrdering.CompareAscending), new EOSortOrdering("eduGroup", EOSortOrdering.CompareAscending), new EOSortOrdering("plusTeacher", EOSortOrdering.CompareAscending) }); EOSortOrdering.sortArrayUsingKeyOrderArray(result, sorter); return result; }
protected static NSMutableDictionary convertEvent(Reason.Event event) { NSMutableDictionary dict = new NSMutableDictionary(event.reason(), "reason"); if (event.reason().verification() == null) dict.takeValueForKey("grey", "cellClass"); dict.takeValueForKey(event.date(), "date"); EduCourse course = event.course(); dict.takeValueForKey(course.eduGroup(), "eduGroup"); dict.takeValueForKey(course.cycle().grade(), "grade"); Substitute sub = null; if (event instanceof Variation) { Variation var = (Variation) event; dict.takeValueForKey(var.relatedLesson(), "lesson"); Variation back = var.getPaired(); NSArray subs = (NSArray) var.valueForKeyPath("relatedLesson.substitutes"); if (subs != null && subs.count() > 0) { if (subs.count() == 1) { sub = (Substitute) subs.objectAtIndex(0); } else { dict.takeValueForKey(subs, "multiply"); } } if (var.value().intValue() > 0) { dict.takeValueForKey(var.course(), "plusCourse"); if (back != null) { dict.takeValueForKey(back.course(), "minusCourse"); dict.takeValueForKey(back.course().teacher(), "minusTeacher"); } if (sub == null) { if (var.reason().namedFlags().flagForKey("toReturn")) dict.takeValueForKey("@", "value"); else dict.takeValueForKey(var.value(), "value"); dict.takeValueForKey(var.course().teacher(), "plusTeacher"); } } else { dict.takeValueForKey(var.course(), "minusCourse"); dict.takeValueForKey(var.course().teacher(), "minusTeacher"); if (back != null) { dict.takeValueForKey(back.course(), "plusCourse"); if (sub == null) { dict.takeValueForKey(back.course().teacher(), "plusTeacher"); if (back.reason().namedFlags().flagForKey("toReturn")) dict.takeValueForKey("@", "value"); else dict.takeValueForKey(back.value(), "value"); } } else if (sub == null) { dict.takeValueForKey(new Integer(-var.value().intValue()), "value"); } } } else if (event instanceof Substitute) { sub = (Substitute) event; dict.takeValueForKey(sub.course(), "minusCourse"); dict.takeValueForKey(sub.course(), "plusCourse"); dict.takeValueForKey(sub.course().teacher(), "minusTeacher"); dict.takeValueForKey(sub.lesson(), "lesson"); } if (sub != null) { dict.takeValueForKey(sub.teacher(), "plusTeacher"); dict.takeValueForKey(sub.value(), "value"); } return dict; }
@Override public QueryIterator exec( Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { if (textIndex == null) { if (!warningIssued) { Log.warn(getClass(), "No text index - no text search performed"); warningIssued = true; } // Not a text dataset - no-op return IterLib.result(binding, execCxt); } DatasetGraph dsg = execCxt.getDataset(); argSubject = Substitute.substitute(argSubject, binding); argObject = Substitute.substitute(argObject, binding); Node s = null; Node score = null; Node literal = null; if (argSubject.isList()) { // Length checked in build() s = argSubject.getArg(0); score = argSubject.getArg(1); if (!score.isVariable()) throw new QueryExecException("Hit score is not a variable: " + argSubject); if (argSubject.getArgListSize() > 2) { literal = argSubject.getArg(2); if (!literal.isVariable()) throw new QueryExecException("Hit literal is not a variable: " + argSubject); } } else { s = argSubject.getArg(); } if (s.isLiteral()) // Does not match return IterLib.noResults(execCxt); StrMatch match = objectToStruct(argObject, true); if (match == null) { // can't match return IterLib.noResults(execCxt); } // ---- QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s, score, literal, match, execCxt) : concreteSubject(binding, s, score, literal, match, execCxt); if (match.getLimit() >= 0) qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt); return qIter; }