Created
July 29, 2016 14:17
-
-
Save ricardorcr/2d5bc9e9f3b10146fcd048760c420946 to your computer and use it in GitHub Desktop.
Invert First Year Shifts Capacity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright © 2013 Instituto Superior Técnico | |
* | |
* This file is part of FenixEdu IST Integration. | |
* | |
* FenixEdu IST Integration is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU Lesser General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* FenixEdu IST Integration is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public License | |
* along with FenixEdu IST Integration. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
package pt.ist.fenixedu.integration.task.updateData.enrolment; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
import org.fenixedu.academic.domain.Degree; | |
import org.fenixedu.academic.domain.DegreeCurricularPlan; | |
import org.fenixedu.academic.domain.ExecutionDegree; | |
import org.fenixedu.academic.domain.ExecutionSemester; | |
import org.fenixedu.academic.domain.ExecutionYear; | |
import org.fenixedu.academic.domain.SchoolClass; | |
import org.fenixedu.academic.domain.Shift; | |
import org.fenixedu.academic.domain.degree.DegreeType; | |
import org.fenixedu.bennu.scheduler.custom.CustomTask; | |
public class InvertFirstYearShiftsCapacity extends CustomTask { | |
static private final Integer FIRST_CURRICULAR_YEAR = Integer.valueOf(1); | |
@Override | |
public void runTask() throws Exception { | |
final ExecutionSemester executionSemester = ExecutionYear.readCurrentExecutionYear().getFirstExecutionPeriod(); | |
final List<Degree> degrees = readDegrees(); | |
taskLog("Degrees: " + degrees.size()); | |
taskLog("Period: " + executionSemester.getQualifiedName()); | |
final Set<Shift> shifts = new HashSet<Shift>(); | |
for (final Degree degree : readDegrees()) { | |
for (final DegreeCurricularPlan degreeCurricularPlan : degree.getActiveDegreeCurricularPlans()) { | |
final ExecutionDegree executionDegree = | |
degreeCurricularPlan.getExecutionDegreeByAcademicInterval(executionSemester.getExecutionYear() | |
.getAcademicInterval()); | |
if (executionDegree != null) { | |
for (final SchoolClass schoolClass : executionDegree.getSchoolClassesSet()) { | |
if (schoolClass.getAnoCurricular().equals(FIRST_CURRICULAR_YEAR) | |
&& schoolClass.getExecutionPeriod() == executionSemester) { | |
for (final Shift shift : schoolClass.getAssociatedShiftsSet()) { | |
shifts.add(shift); | |
} | |
} | |
} | |
} | |
} | |
} | |
taskLog("Found: " + shifts.size() + " shifts"); | |
int modified = 0; | |
for (final Shift shift : shifts) { | |
int capacity = shift.getLotacao().intValue(); | |
taskLog(String.format("For shift[%s] Capacity is %s: ", shift.getNome(), capacity)); | |
if (capacity > 0) { | |
shift.setLotacao(capacity * -1); | |
modified++; | |
} | |
} | |
taskLog("Modified: " + modified); | |
} | |
private List<Degree> readDegrees() { | |
return Degree.readAllMatching(DegreeType.oneOf(DegreeType::isBolonhaDegree, DegreeType::isIntegratedMasterDegree)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment