package net.sourceforge.fenixedu.domain; import java.util.Comparator; import java.util.ResourceBundle; import net.sourceforge.fenixedu.domain.curricularPeriod.CurricularPeriod; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.util.LanguageUtils; import pt.iscte.ci.metadata.ISCTE; @ISCTE(author = "Paulo Zenida") public abstract class DCPTransitionPlanRuleWrapper extends DCPTransitionPlanRuleWrapper_Base { static private final String NAME_SEPARATOR = " > "; static public final Comparator COMPARE_BY_FULL_PATH_AND_NAME = new Comparator() { public int compare(DCPTransitionPlanRuleWrapper o1, DCPTransitionPlanRuleWrapper o2) { return o1.getFullPathWithName().compareTo(o2.getFullPathWithName()); } }; public DCPTransitionPlanRuleWrapper() { super(); setRootDomainObject(RootDomainObject.getInstance()); } public String getFullPath() { if (!hasContext()) { return ResourceBundle.getBundle("resources.DomainExceptionResources", LanguageUtils.getLocale()).getString( "error.DCPTransitionPlanRuleWrapper.context.removed"); } return getPathUntilCycle(getContext().getParentCourseGroup()); } private String getPathUntilCycle(CourseGroup courseGroup) { final Context context = !courseGroup.hasAnyParentContexts() ? null : courseGroup.getParentContexts().get(0); return ((context == null || context.getParentCourseGroup().isCycleCourseGroup()) ? "" : getPathUntilCycle(context .getParentCourseGroup()) + NAME_SEPARATOR) + courseGroup.getName(); } public String getName() { return hasContext() ? getContext().getChildDegreeModule().getName() : null; } public String getFullPathWithName() { return getFullPath() + (hasContext() ? NAME_SEPARATOR + getName() : ""); } public String getContextDescription() { if (!hasContext()) { return ""; } final CurricularPeriod curricularPeriod = getContext().getCurricularPeriod(); return (curricularPeriod != null ? curricularPeriod.getFullLabel(true) : "") + " (I: " + getAbbreviatedDescription(getContext().getBeginExecutionPeriod()) + (getContext().hasEndExecutionPeriod() ? " - F: " + getAbbreviatedDescription(getContext().getEndExecutionPeriod()) : "") + ")"; } private String getAbbreviatedDescription(ExecutionPeriod period) { return String.format("%sēS %s", period.getSemester(), period.getExecutionYear().getName()); } public void delete() { removeContext(); removeRootDomainObject(); deleteDomainObject(); } public CourseGroup getParentCourseGroup() { return getContext().getParentCourseGroup(); } public CurricularCourse getCurricularCourse() { return (getContext() != null && getContext().getChildDegreeModule().isLeaf()) ? (CurricularCourse) getContext() .getChildDegreeModule() : null; } public boolean hasStudentCurricularYear() { return getStudentCurricularYear() != null; } abstract public DCPTransitionPlanRule getDcpTransitionPlanRule(); public DegreeCurricularPlan getOriginDcp() { return getDcpTransitionPlanRule().getOriginDcp(); } public DegreeCurricularPlan getDestinyDcp() { return getDcpTransitionPlanRule().getDestinyDcp(); } public String getDcpTransitionPlanName() { return getDcpTransitionPlanRule().getDcpTransitionPlanName(); } }