package net.sourceforge.fenixedu.applicationTier.Servico.manager; import java.util.List; import net.sourceforge.fenixedu.applicationTier.FenixService; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.InvalidArgumentsServiceException; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.GradeScale; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicPeriod; import pt.ist.fenixWebFramework.security.accessControl.Checked; import pt.ist.fenixWebFramework.services.Service; import pt.utl.ist.fenix.tools.util.i18n.Language; import com.linkare.commons.metainfo.Linkare; public class InsertDegree extends FenixService { @Linkare(author = "Paulo Zenida", comments = "Included the parameter academicPeriod") @Checked("RolePredicates.MANAGER_PREDICATE") @Service public static void run(final String code, final String name, final String nameEn, final DegreeType degreeType, final GradeScale gradeScale, final AcademicPeriod academicPeriod) throws FenixServiceException { if (name == null || nameEn == null || code == null || degreeType == null) { throw new InvalidArgumentsServiceException(); } final List degrees = Degree.readOldDegrees(); // assert unique degree code and unique pair name/type for (Degree degree : degrees) { if (degree.getSigla().equalsIgnoreCase(code)) { throw new FenixServiceException("error.existing.code"); } ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); if ((degree.getNameFor(currentExecutionYear).getContent(Language.pt).equalsIgnoreCase(name) || degree.getNameFor( currentExecutionYear).getContent(Language.en).equalsIgnoreCase(nameEn)) && degree.getDegreeType().equals(degreeType)) { throw new FenixServiceException("error.existing.name.and.type"); } } new Degree(name, nameEn, code, degreeType, gradeScale, academicPeriod); } }