package net.sourceforge.fenixedu.domain.student; import net.sourceforge.fenixedu.dataTransferObject.student.MobilityAgreementBean; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit; import org.joda.time.YearMonthDay; public class MobilityAgreement extends MobilityAgreement_Base { public MobilityAgreement() { super(); setRootDomainObject(RootDomainObject.getInstance()); } public MobilityAgreement(final Registration registration, final MobilityProgram mobilityProgram, final YearMonthDay startDate, final YearMonthDay endDate, final Unit institution) { this(); init(registration, mobilityProgram, startDate, endDate, institution); } public MobilityAgreement(MobilityAgreementBean mobilityAgreementBean) { this(mobilityAgreementBean.getRegistration(), mobilityAgreementBean.getMobilityProgram(), mobilityAgreementBean .getStartDate(), mobilityAgreementBean.getEndDate(), mobilityAgreementBean.getInstitution()); } private void init(final Registration registration, final MobilityProgram mobilityProgram, final YearMonthDay startDate, final YearMonthDay endDate, final Unit institution) { checkParameters(registration, mobilityProgram, startDate, endDate, institution); setRegistration(registration); setMobilityProgram(mobilityProgram); setStartDate(startDate); setEndDate(endDate); setInstitution(institution); } private void checkParameters(final Registration registration, final MobilityProgram mobilityProgram, final YearMonthDay startDate, final YearMonthDay endDate, final Unit institution) { if (registration == null) { throw new DomainException("error.registration.is.mandatory"); } if (mobilityProgram == null) { throw new DomainException("error.mobilityProgram.is.mandatory"); } if (startDate == null) { throw new DomainException("error.startDate.is.mandatory"); } if (endDate != null && endDate.isBefore(startDate)) { throw new DomainException("error.endDate.cannot.be.before.startDate"); } if (institution == null) { throw new DomainException("error.institution.is.mandatory"); } } public void edit(MobilityAgreementBean mobilityAgreementBean) { setMobilityProgram(mobilityAgreementBean.getMobilityProgram()); setStartDate(mobilityAgreementBean.getStartDate()); setEndDate(mobilityAgreementBean.getEndDate()); setInstitution(mobilityAgreementBean.getInstitution()); } public void delete() { removeRegistration(); removeInstitution(); removeRootDomainObject(); super.deleteDomainObject(); } }