package net.sourceforge.fenixedu.dataTransferObject.teacher.executionCourse; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import net.sourceforge.fenixedu.domain.Attends; import net.sourceforge.fenixedu.domain.DegreeCurricularPlan; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.ExecutionCourse; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.Shift; import net.sourceforge.fenixedu.domain.accessControl.FixedSetGroup; import net.sourceforge.fenixedu.domain.accessControl.Group; import net.sourceforge.fenixedu.domain.student.StudentStatuteType; import net.sourceforge.fenixedu.util.WorkingStudentSelectionType; import pt.utl.ist.fenix.tools.predicates.AndPredicate; import pt.utl.ist.fenix.tools.predicates.InlinePredicate; import pt.utl.ist.fenix.tools.predicates.Predicate; import pt.utl.ist.fenix.tools.util.StringAppender; import pt.utl.ist.fenix.tools.util.i18n.Language; public class SearchExecutionCourseAttendsBean implements Serializable { private DomainReference executionCourse; private Boolean viewPhoto; private Collection attendsStates; private Collection workingStudentTypes; private Collection> degreeCurricularPlans; private Collection> shifts; private Collection> attendsResult; private transient Map enrolmentsNumberMap; public String getEnumerationResourcesString(String name) { return ResourceBundle.getBundle("resources/EnumerationResources", Language.getLocale()).getString(name); } public String getApplicationResourcesString(String name) { return ResourceBundle.getBundle("resources/ApplicationResources", Language.getLocale()).getString(name); } public SearchExecutionCourseAttendsBean(ExecutionCourse executionCourse) { setExecutionCourse(executionCourse); setViewPhoto(false); setAttendsStates(Arrays.asList(StudentAttendsStateType.values())); setWorkingStudentTypes(Arrays.asList(WorkingStudentSelectionType.values())); setShifts(getExecutionCourse().getAssociatedShifts()); setDegreeCurricularPlans(getExecutionCourse().getAttendsDegreeCurricularPlans()); attendsResult = new ArrayList>(); } public ExecutionCourse getExecutionCourse() { return (this.executionCourse != null) ? this.executionCourse.getObject() : null; } public void setExecutionCourse(ExecutionCourse executionCourse) { this.executionCourse = (executionCourse != null) ? new DomainReference(executionCourse) : null; } public Boolean getViewPhoto() { return viewPhoto; } public void setViewPhoto(Boolean viewPhoto) { this.viewPhoto = viewPhoto; } public enum StudentAttendsStateType { ENROLED, NOT_ENROLED, IMPROVEMENT, SPECIAL_SEASON; public String getQualifiedName() { return StringAppender.append(StudentAttendsStateType.class.getSimpleName(), ".", name()); } } public Collection getAttendsStates() { return attendsStates; } public void setAttendsStates(Collection attendsStates) { this.attendsStates = attendsStates; } public Collection getDegreeCurricularPlans() { Collection dcps = new ArrayList(); for (DomainReference degreeCurricularPlan : degreeCurricularPlans) { dcps.add(degreeCurricularPlan.getObject()); } return dcps; } public void setShifts(Collection shifts) { Collection> drShifts = new ArrayList>(); for (Shift shift : shifts) { drShifts.add(new DomainReference(shift)); } this.shifts = drShifts; } public Collection getShifts() { Collection shifts = new ArrayList(); for (DomainReference shift : this.shifts) { shifts.add(shift.getObject()); } return shifts; } public void setDegreeCurricularPlans(Collection degreeCurricularPlans) { Collection> dcps = new ArrayList>(); for (DegreeCurricularPlan dcp : degreeCurricularPlans) { dcps.add(new DomainReference(dcp)); } this.degreeCurricularPlans = dcps; } public Collection getWorkingStudentTypes() { return workingStudentTypes; } public void setWorkingStudentTypes(Collection workingStudentTypes) { this.workingStudentTypes = workingStudentTypes; } public Collection getAttendsResult() { Collection attends = new ArrayList(); for (DomainReference attendRef : attendsResult) { attends.add(attendRef.getObject()); } return attends; } public void setAttendsResult(Collection atts) { ArrayList> results = new ArrayList>(); for (Attends attend : atts) { results.add(new DomainReference(attend)); } this.attendsResult = results; } public Map getEnrolmentsNumberMap() { return enrolmentsNumberMap; } public void setEnrolmentsNumberMap(Map enrolmentsNumberMap) { this.enrolmentsNumberMap = enrolmentsNumberMap; } public Predicate getFilters() { Collection> filters = new ArrayList>(); if (getAttendsStates().size() < StudentAttendsStateType.values().length) { filters.add(new InlinePredicate>(getAttendsStates()) { @Override public boolean eval(Attends attends) { return getValue().contains(attends.getAttendsStateType()); } }); } if (getWorkingStudentTypes().size() < WorkingStudentSelectionType.values().length) { filters.add(new InlinePredicate>(getWorkingStudentTypes()) { @Override public boolean eval(Attends attends) { return getValue().contains(getWorkingStudentType(attends)); } private WorkingStudentSelectionType getWorkingStudentType(Attends attends) { if (attends.getRegistration().getStudent().hasActiveStatuteInPeriod(StudentStatuteType.WORKING_STUDENT, attends.getExecutionPeriod())) { return WorkingStudentSelectionType.WORKING_STUDENT; } else { return WorkingStudentSelectionType.NOT_WORKING_STUDENT; } } }); } if (shifts.size() < getExecutionCourse().getAssociatedShifts().size()) { filters.add(new InlinePredicate>(getShifts()) { @Override public boolean eval(Attends attends) { for (Shift shift : getValue()) { if (shift.hasStudents(attends.getRegistration())) { return true; } } return false; } }); } if (degreeCurricularPlans.size() < getExecutionCourse().getAttendsDegreeCurricularPlans().size()) { filters.add(new InlinePredicate>(getDegreeCurricularPlans()) { @Override public boolean eval(Attends attends) { return getValue().contains(attends.getStudentCurricularPlanFromAttends().getDegreeCurricularPlan()); } }); } return new AndPredicate(filters); } public Group getAttendsGroup() { List persons = new ArrayList(); for (Attends attends : getAttendsResult()) { persons.add(attends.getRegistration().getStudent().getPerson()); } return new FixedSetGroup(persons); } public String getLabel() { String attendTypeValues = "", degreeNameValues = "", shiftsValues = "", workingStudentsValues = ""; for (StudentAttendsStateType attendType : attendsStates) { if (!attendTypeValues.isEmpty()) { attendTypeValues += ", "; } attendTypeValues += getEnumerationResourcesString(attendType.getQualifiedName()); } for (DomainReference degree : degreeCurricularPlans) { if (!degreeNameValues.isEmpty()) { degreeNameValues += ", "; } degreeNameValues += degree.getObject().getName(); } for (DomainReference shift : shifts) { if (!shiftsValues.isEmpty()) { shiftsValues += ", "; } shiftsValues += shift.getObject().getPresentationName(); } for (WorkingStudentSelectionType workingStudent : workingStudentTypes) { if (!workingStudentsValues.isEmpty()) { workingStudentsValues += ", "; } workingStudentsValues += getEnumerationResourcesString(workingStudent.getQualifiedName()); } return String.format("%s : %s \n%s : %s \n%s : %s \n%s", getApplicationResourcesString("label.selectStudents"), attendTypeValues, getApplicationResourcesString("label.attends.courses"), degreeNameValues, getApplicationResourcesString("label.selectShift"), shiftsValues, workingStudentsValues); } }