package net.sourceforge.fenixedu.presentationTier.renderers.converters; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import net.sourceforge.fenixedu.domain.ExecutionPeriod; import net.sourceforge.fenixedu.domain.enrolment.EnroledCurriculumModuleForImprovementWrapper; import net.sourceforge.fenixedu.domain.enrolment.EnroledCurriculumModuleForSpecialSeasonWrapper; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule; import net.sourceforge.fenixedu.util.DateFormatUtil; import org.joda.time.YearMonthDay; import pt.iscte.ci.metadata.ISCTE; import pt.ist.fenixWebFramework.renderers.components.converters.ConversionException; import pt.ist.fenixWebFramework.renderers.components.converters.Converter; import pt.ist.utl.fenix.utils.Pair; @ISCTE(author = "ajsco") public class SpecialSeasonCurriculumModuleEnroledWrapperConverter extends Converter { @Override public Object convert(Class type, Object value) { if (value == null) { return null; } final DomainObjectKeyConverter converter = new DomainObjectKeyConverter(); final List result = new ArrayList(); final String[] values = (String[]) value; List> errors = new ArrayList>(); for (int i = 0; i < values.length; i++) { String key = values[i]; String[] parts = key.split(","); if (parts.length < 3) { throw new ConversionException("invalid key format: " + key); } final CurriculumModule curriculumModule = (CurriculumModule) converter.convert(type, parts[0]); final ExecutionPeriod executionPeriod = (ExecutionPeriod) converter.convert(type, parts[1]); YearMonthDay enrollmentDate = null; String strDate = parts[2]; try { enrollmentDate = YearMonthDay.fromDateFields(DateFormatUtil.parse(DateFormatUtil.DEFAULT_DATE_FORMAT, strDate)); } catch (ParseException e) { errors.add(new Pair(EnroledCurriculumModuleForImprovementWrapper.ERROR_INVALID_DATE, strDate)); } EnroledCurriculumModuleForSpecialSeasonWrapper wrapper = new EnroledCurriculumModuleForSpecialSeasonWrapper( curriculumModule, executionPeriod, enrollmentDate, errors); result.add(wrapper); } return result; } }