package net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.equivalencyPlan; import java.io.Serializable; import java.util.HashSet; import java.util.Set; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.DCPTransitionPlan; import net.sourceforge.fenixedu.domain.DCPTransitionPlanRule; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.ExecutionPeriod; import net.sourceforge.fenixedu.domain.DCPTransitionPlanRule.RuleType; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import pt.iscte.ci.metadata.ISCTE; @ISCTE public class DCPTransitionPlanRuleBean implements Serializable { private static final long serialVersionUID = 1L; private DCPTransitionPlanBean dcpTransitionPlanBean; private DomainReference dcpTransitionPlan; private DomainReference dcpTransitionPlanRule; private Set origins = new HashSet(); private Set destinies = new HashSet(); private RuleType ruleType = RuleType.TRANSITION; public DCPTransitionPlanRuleBean(final DCPTransitionPlan dcpTransitionPlan) { setDcpTransitionPlan(dcpTransitionPlan); } public DCPTransitionPlanRuleBean(DCPTransitionPlanRule dcpTransitionPlanRule) { setDcpTransitionPlanRule(dcpTransitionPlanRule); setDcpTransitionPlan(dcpTransitionPlanRule.getDcpTransitionPlan()); } public boolean hasAnyOrigins() { return !origins.isEmpty(); } public SelectedContext getOriginEntry() { return null; } public void setOriginEntry(SelectedContext entry) { if (entry != null && !origins.contains(entry)) { origins.add(entry); } } public void removeOriginEntry(Integer entryId) { for (SelectedContext origin : origins) { if (origin.getContext().getIdInternal().equals(entryId)) { origins.remove(origin); break; } } } public void removeOriginEntry(SelectedContext entry) { origins.remove(entry); } public Set getSelectedOriginEntries() { return origins; } public boolean hasAnyDestinies() { return !destinies.isEmpty(); } public SelectedContext getDestinyEntry() { return null; } public void setDestinyEntry(SelectedContext entry) { if (entry != null && !destinies.contains(entry)) { destinies.add(entry); } } public void removeDestinyEntry(Integer entryId) { for (SelectedContext destiny : destinies) { if (destiny.getContext().getIdInternal().equals(entryId)) { destinies.remove(destiny); break; } } } public void removeDestinyEntry(SelectedContext entry) { destinies.remove(entry); } public Set getSelectedDestinyEntries() { return destinies; } /** * @return the dcpTransitionPlanBean */ public DCPTransitionPlanBean getDcpTransitionPlanBean() { return dcpTransitionPlanBean; } /** * @param dcpTransitionPlanBean * the dcpTransitionPlanBean to set */ public void setDcpTransitionPlanBean(DCPTransitionPlanBean dcpTransitionPlanBean) { this.dcpTransitionPlanBean = dcpTransitionPlanBean; } /** * @return the dcpTransitionPlan */ public DCPTransitionPlan getDcpTransitionPlan() { return dcpTransitionPlan == null ? null : dcpTransitionPlan.getObject(); } /** * @param dcpTransitionPlan * the dcpTransitionPlan to set */ public void setDcpTransitionPlan(DCPTransitionPlan dcpTransitionPlan) { this.dcpTransitionPlan = dcpTransitionPlan == null ? null : new DomainReference(dcpTransitionPlan); } /** * @return the dcpTransitionPlanRule */ public DCPTransitionPlanRule getDcpTransitionPlanRule() { return dcpTransitionPlanRule == null ? null : dcpTransitionPlanRule.getObject(); } /** * @param dcpTransitionPlanRule * the dcpTransitionPlanRule to set */ private void setDcpTransitionPlanRule(DCPTransitionPlanRule dcpTransitionPlanRule) { this.dcpTransitionPlanRule = dcpTransitionPlanRule == null ? null : new DomainReference( dcpTransitionPlanRule); } public RuleType getRuleType() { return ruleType; } public void setRuleType(RuleType ruleType) { this.ruleType = ruleType; } public static class SelectedContext implements Serializable { private DomainReference context; private DomainReference executionPeriod; private Double weigth; private Double creditsEcts; private Integer studentCurricularYear; public SelectedContext(final Context context) { this(context, null); } public SelectedContext(final Context context, final ExecutionPeriod executionPeriod) { setContext(context); setExecutionPeriod(executionPeriod); } public CurricularCourse getCurricularCourse() { return (CurricularCourse) (getContext() == null ? null : getContext().getChildDegreeModule()); } public CourseGroup getCourseGroup() { return getContext() == null ? null : getContext().getParentCourseGroup(); } public Context getContext() { return (this.context != null) ? this.context.getObject() : null; } public void setContext(Context context) { this.context = (context != null) ? new DomainReference(context) : null; } /** * @return the executionPeriod */ public ExecutionPeriod getExecutionPeriod() { return executionPeriod == null ? null : executionPeriod.getObject(); } /** * @param executionPeriod * the executionPeriod to set */ public void setExecutionPeriod(ExecutionPeriod executionPeriod) { this.executionPeriod = executionPeriod == null ? null : new DomainReference(executionPeriod); } /** * @return the weigth */ public Double getWeigth() { return weigth; } /** * @param weigth * the weigth to set */ public void setWeigth(Double weigth) { this.weigth = weigth; } /** * @return the creditsEcts */ public Double getCreditsEcts() { return creditsEcts; } /** * @param creditsEcts * the creditsEcts to set */ public void setCreditsEcts(Double creditsEcts) { this.creditsEcts = creditsEcts; } public Double getCurricularCourseEctsCredits() { return getCurricularCourse().getEctsCredits(getExecutionPeriod()); } @Override public boolean equals(Object obj) { if (!(obj instanceof SelectedContext)) { return false; } return equals((SelectedContext) obj); } public boolean equals(final SelectedContext other) { return getContext() == other.getContext(); } @Override public int hashCode() { return getContext().hashCode(); } public Integer getStudentCurricularYear() { return studentCurricularYear; } public void setStudentCurricularYear(Integer studentCurricularYear) { this.studentCurricularYear = studentCurricularYear; } } }