package net.sourceforge.fenixedu.domain.parking; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.ResourceBundle; import net.sourceforge.fenixedu.dataTransferObject.parking.ParkingPartyBean; import net.sourceforge.fenixedu.dataTransferObject.parking.VehicleBean; import net.sourceforge.fenixedu.domain.Employee; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.PartyClassification; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.Teacher; import net.sourceforge.fenixedu.domain.assiduousness.AssiduousnessStatusHistory; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.grant.contract.GrantContract; import net.sourceforge.fenixedu.domain.grant.contract.GrantContractRegime; import net.sourceforge.fenixedu.domain.grant.owner.GrantOwner; import net.sourceforge.fenixedu.domain.organizationalStructure.AccountabilityTypeEnum; import net.sourceforge.fenixedu.domain.organizationalStructure.Invitation; import net.sourceforge.fenixedu.domain.organizationalStructure.Party; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit; import net.sourceforge.fenixedu.domain.parking.ParkingRequest.ParkingRequestFactoryCreator; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.Student; import net.sourceforge.fenixedu.domain.teacher.TeacherProfessionalSituation; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.lang.StringUtils; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import pt.utl.ist.fenix.tools.file.FileManagerFactory; import pt.utl.ist.fenix.tools.util.i18n.Language; public class ParkingParty extends ParkingParty_Base { public static ParkingParty readByCardNumber(Long cardNumber) { for (ParkingParty parkingParty : RootDomainObject.getInstance().getParkingParties()) { if (parkingParty.getCardNumber() != null && parkingParty.getCardNumber().equals(cardNumber)) { return parkingParty; } } return null; } public ParkingParty(Party party) { super(); setRootDomainObject(RootDomainObject.getInstance()); setParty(party); setAuthorized(Boolean.FALSE); setAcceptedRegulation(Boolean.FALSE); } public boolean getHasAllNecessaryPersonalInfo() { return ((getParty().getDefaultPhone() != null && !StringUtils.isEmpty(getParty().getDefaultPhone().getNumber())) || (getParty() .getDefaultMobilePhone() != null && !StringUtils.isEmpty(getParty().getDefaultMobilePhone().getNumber()))) && (isEmployee() || (getParty().getDefaultEmailAddress() != null && getParty().getDefaultEmailAddress().hasValue() && !StringUtils.isEmpty(getParty() .getDefaultEmailAddress().getValue()))); } private boolean isEmployee() { if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher == null) { Employee employee = person.getEmployee(); if (employee != null) { return true; } } } return false; } public List getOrderedParkingRequests() { List requests = new ArrayList(getParkingRequests()); Collections.sort(requests, new BeanComparator("creationDate")); return requests; } public ParkingRequest getFirstRequest() { List requests = getOrderedParkingRequests(); if (requests.size() != 0) { return requests.get(0); } return null; } public ParkingRequest getLastRequest() { List requests = getOrderedParkingRequests(); if (requests.size() != 0) { return requests.get(requests.size() - 1); } return null; } public ParkingRequestFactoryCreator getParkingRequestFactoryCreator() { return new ParkingRequestFactoryCreator(this); } public String getParkingAcceptedRegulationMessage() { ResourceBundle bundle = ResourceBundle.getBundle("resources.ParkingResources", Language.getLocale()); String name = getParty().getName(); String number = ""; if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher == null) { Employee employee = person.getEmployee(); if (employee == null) { Student student = person.getStudent(); if (student != null) { number = student.getNumber().toString(); } } else { number = employee.getEmployeeNumber().toString(); } } else { number = teacher.getTeacherNumber().toString(); } } return MessageFormat.format(bundle.getString("message.acceptedRegulation"), new Object[] { name, number }); } public boolean isStudent() { if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher == null) { Employee employee = person.getEmployee(); if (employee == null) { Student student = person.getStudent(); if (student != null) { return true; } } } } return false; } public String getDriverLicenseFileNameToDisplay() { NewParkingDocument driverLicenseDocument = getDriverLicenseDocument(); if (driverLicenseDocument != null) { return driverLicenseDocument.getParkingFile().getFilename(); } else if (getDriverLicenseDeliveryType() != null) { ResourceBundle bundle = ResourceBundle.getBundle("resources.ParkingResources", Language.getLocale()); return bundle.getString(getDriverLicenseDeliveryType().name()); } return ""; } public String getDeclarationDocumentLink() { NewParkingDocument parkingDocument = getDriverLicenseDocument(); if (parkingDocument != null && parkingDocument.getParkingDocumentType() == NewParkingDocumentType.DRIVER_LICENSE) { ParkingFile parkingFile = parkingDocument.getParkingFile(); return FileManagerFactory.getFactoryInstance().getFileManager().formatDownloadUrl( parkingFile.getExternalStorageIdentification(), parkingFile.getFilename()); } return ""; } public String getParkingGroupToDisplay() { if (getParkingGroup() != null) { return getParkingGroup().getGroupName(); } return null; } public String getWorkPhone() { if (getParty().isPerson()) { return getParty().getDefaultPhone().getNumber(); } return null; } public List getSubmitAsRoles() { List roles = new ArrayList(); if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher != null && person.getPersonRole(RoleType.TEACHER) != null && !teacher.isMonitor(ExecutionSemester.readActualExecutionSemester())) { roles.add(RoleType.TEACHER); } Employee employee = person.getEmployee(); if (employee != null && person.getPersonRole(RoleType.TEACHER) == null && person.getPersonRole(RoleType.EMPLOYEE) != null && employee.getCurrentContractByContractType(AccountabilityTypeEnum.WORKING_CONTRACT) != null) { roles.add(RoleType.EMPLOYEE); } Student student = person.getStudent(); if (student != null && person.getPersonRole(RoleType.STUDENT) != null) { DegreeType degreeType = student.getMostSignificantDegreeType(); Collection registrations = student.getRegistrationsByDegreeType(degreeType); for (Registration registration : registrations) { StudentCurricularPlan scp = registration.getActiveStudentCurricularPlan(); if (scp != null) { roles.add(RoleType.STUDENT); break; } } } GrantOwner grantOwner = person.getGrantOwner(); if (grantOwner != null && person.getPersonRole(RoleType.GRANT_OWNER) != null && grantOwner.hasCurrentContract()) { roles.add(RoleType.GRANT_OWNER); } } if (roles.size() == 0) { roles.add(RoleType.PERSON); } return roles; } public List getOccupations() { List occupations = new ArrayList(); if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher != null) { StringBuilder stringBuilder = new StringBuilder(); String currentDepartment = ""; if (teacher.getCurrentWorkingDepartment() != null) { currentDepartment = teacher.getCurrentWorkingDepartment().getName(); } if (teacher.isMonitor(ExecutionSemester.readActualExecutionSemester())) { stringBuilder.append("Monitor
Nº " + teacher.getTeacherNumber() + "
" + currentDepartment); } else { stringBuilder.append("Docente
Nº " + teacher.getTeacherNumber() + "
" + currentDepartment); } TeacherProfessionalSituation teacherProfessionalSituation = teacher .getCurrentLegalRegimenWithoutSpecialSitutions(); if (teacherProfessionalSituation == null) { teacherProfessionalSituation = teacher.getLastLegalRegimenWithoutSpecialSituations(); } if (teacherProfessionalSituation != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd"); stringBuilder.append("\n (Data inicio: ").append( fmt.print(teacherProfessionalSituation.getBeginDateYearMonthDay())); if (teacherProfessionalSituation.getEndDateYearMonthDay() != null) { stringBuilder.append(" - Data fim: ").append( fmt.print(teacherProfessionalSituation.getEndDateYearMonthDay())); } stringBuilder.append(")
"); } else { stringBuilder.append("(inactivo)
"); } occupations.add(stringBuilder.toString()); } Employee employee = person.getEmployee(); if (employee != null && person.getPersonRole(RoleType.TEACHER) == null && person.getPersonRole(RoleType.EMPLOYEE) != null && employee.getCurrentContractByContractType(AccountabilityTypeEnum.WORKING_CONTRACT) != null && !person.isPersonResearcher()) { StringBuilder stringBuilder = new StringBuilder(); Unit currentUnit = employee.getCurrentWorkingPlace(); if (currentUnit != null) { stringBuilder.append("Funcionário
Nº " + employee.getEmployeeNumber() + "
" + currentUnit.getName() + " - " + currentUnit.getCostCenterCode()); } else { stringBuilder.append("Funcionário
Nº " + employee.getEmployeeNumber()); } if (employee.getAssiduousness() != null) { AssiduousnessStatusHistory assiduousnessStatusHistory = employee.getAssiduousness() .getCurrentOrLastAssiduousnessStatusHistory(); if (assiduousnessStatusHistory != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd"); stringBuilder.append("
(Data inicio: ").append(fmt.print(assiduousnessStatusHistory.getBeginDate())); if (assiduousnessStatusHistory.getEndDate() != null) { stringBuilder.append(" - Data fim: ").append(fmt.print(assiduousnessStatusHistory.getEndDate())); } stringBuilder.append(")
"); } } occupations.add(stringBuilder.toString()); } GrantOwner grantOwner = person.getGrantOwner(); if (grantOwner != null && person.getPersonRole(RoleType.GRANT_OWNER) != null && grantOwner.hasCurrentContract()) { List contractRegimeList = new ArrayList(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Bolseiro
Nº " + grantOwner.getNumber()); for (GrantContract contract : grantOwner.getGrantContracts()) { contractRegimeList.addAll(contract.getContractRegimes()); } Collections.sort(contractRegimeList, new BeanComparator("dateBeginContractYearMonthDay")); for (GrantContractRegime contractRegime : contractRegimeList) { stringBuilder.append("
Início: " + contractRegime.getDateBeginContractYearMonthDay().toString("dd/MM/yyyy")); LocalDate endDate = contractRegime.getDateEndContractYearMonthDay().toLocalDate(); boolean rescinded = false; if (contractRegime.getGrantContract().getRescissionDate() != null && endDate.isAfter(contractRegime.getGrantContract().getRescissionDate())) { endDate = contractRegime.getGrantContract().getRescissionDate(); if (endDate.isBefore(new LocalDate())) { rescinded = true; } } stringBuilder.append("    -   Fim: " + endDate.toString("dd/MM/yyyy")); stringBuilder.append("    -   Activo: "); if (contractRegime.isActive() && !rescinded) { stringBuilder.append("Sim"); } else { stringBuilder.append("Não"); } } occupations.add(stringBuilder.toString()); } if (person.isPersonResearcher()) { String researchUnitNames = person.getWorkingResearchUnitNames(); if (!StringUtils.isEmpty(researchUnitNames) || !person.getPartyClassification().equals(PartyClassification.TEACHER)) { occupations.add("Investigador
Nº " + person.getMostSignificantNumber()); if (!StringUtils.isEmpty(researchUnitNames)) { occupations.add("
" + researchUnitNames); } } } Student student = person.getStudent(); if (student != null && person.getPersonRole(RoleType.STUDENT) != null) { StringBuilder stringBuilder = null; for (Registration registration : student.getActiveRegistrations()) { StudentCurricularPlan scp = registration.getLastStudentCurricularPlan(); if (scp != null) { if (stringBuilder == null) { stringBuilder = new StringBuilder("Estudante
Nº "); stringBuilder.append(student.getNumber()).append("
"); } stringBuilder.append("\n").append(scp.getDegreeCurricularPlan().getName()); stringBuilder.append("\n (").append(registration.getCurricularYear()).append("º ano"); if (isFirstTimeEnrolledInCurrentYear(registration)) { stringBuilder.append(" - 1ª vez)"); } else { stringBuilder.append(")"); } stringBuilder.append("
Média: ").append(registration.getAverage()); stringBuilder.append("
"); } } if (stringBuilder != null) { occupations.add(stringBuilder.toString()); } } List invitations = person.getActiveInvitations(); if (!invitations.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Convidado
"); for (Invitation invitation : invitations) { stringBuilder.append("Por: ").append(invitation.getUnit().getName()).append("
"); stringBuilder.append("Início: " + invitation.getBeginDate().toString("dd/MM/yyyy")); stringBuilder.append("    -   Fim: " + invitation.getEndDate().toString("dd/MM/yyyy")); occupations.add(stringBuilder.toString()); } } } return occupations; } public List getPastOccupations() { List occupations = new ArrayList(); if (getParty().isPerson()) { Person person = (Person) getParty(); Teacher teacher = person.getTeacher(); if (teacher != null) { StringBuilder stringBuilder = new StringBuilder(); String currentDepartment = ""; if (teacher.getCurrentWorkingDepartment() != null) { currentDepartment = teacher.getCurrentWorkingDepartment().getName(); } if (teacher.isMonitor(ExecutionSemester.readActualExecutionSemester())) { stringBuilder.append("Monitor
Nº " + teacher.getTeacherNumber() + "
" + currentDepartment); } else { stringBuilder.append("Docente
Nº " + teacher.getTeacherNumber() + "
" + currentDepartment); } TeacherProfessionalSituation teacherProfessionalSituation = teacher .getCurrentLegalRegimenWithoutSpecialSitutions(); if (teacherProfessionalSituation == null) { teacherProfessionalSituation = teacher.getLastLegalRegimenWithoutSpecialSituations(); } if (teacherProfessionalSituation != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd"); stringBuilder.append("\n (Data inicio: ").append( fmt.print(teacherProfessionalSituation.getBeginDateYearMonthDay())); if (teacherProfessionalSituation.getEndDateYearMonthDay() != null) { stringBuilder.append(" - Data fim: ").append( fmt.print(teacherProfessionalSituation.getEndDateYearMonthDay())); } stringBuilder.append(")
"); } else { stringBuilder.append("(inactivo)
"); } occupations.add(stringBuilder.toString()); } Employee employee = person.getEmployee(); if (employee != null && person.getPersonRole(RoleType.TEACHER) == null && employee.getCurrentContractByContractType(AccountabilityTypeEnum.WORKING_CONTRACT) != null && !person.isPersonResearcher()) { StringBuilder stringBuilder = new StringBuilder(); AssiduousnessStatusHistory assiduousnessStatusHistory = employee.getAssiduousness() .getCurrentOrLastAssiduousnessStatusHistory(); if (assiduousnessStatusHistory != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd"); stringBuilder.append("
(Data inicio: ").append(fmt.print(assiduousnessStatusHistory.getBeginDate())); if (assiduousnessStatusHistory.getEndDate() != null) { stringBuilder.append(" - Data fim: ").append(fmt.print(assiduousnessStatusHistory.getEndDate())); } stringBuilder.append(")
"); } occupations.add(stringBuilder.toString()); } Student student = person.getStudent(); if (student != null) { StringBuilder stringBuilder = null; for (Registration registration : student.getRegistrations()) { StudentCurricularPlan scp = registration.getLastStudentCurricularPlan(); if (scp != null) { if (stringBuilder == null) { stringBuilder = new StringBuilder("Estudante
Nº "); stringBuilder.append(student.getNumber()).append("
"); } stringBuilder.append("\n").append(scp.getDegreeCurricularPlan().getName()); stringBuilder.append("\n (").append(registration.getCurricularYear()).append("º ano"); if (isFirstTimeEnrolledInCurrentYear(registration)) { stringBuilder.append(" - 1ª vez)"); } else { stringBuilder.append(")"); } stringBuilder.append("
Média: ").append(registration.getAverage()); stringBuilder.append("
"); } } if (stringBuilder != null) { occupations.add(stringBuilder.toString()); } } if (person.isPersonResearcher()) { String researchUnitNames = person.getWorkingResearchUnitNames(); if (!StringUtils.isEmpty(researchUnitNames) || !person.getPartyClassification().equals(PartyClassification.TEACHER)) { occupations.add("Investigador
Nº " + person.getMostSignificantNumber()); if (!StringUtils.isEmpty(researchUnitNames)) { occupations.add("
" + researchUnitNames); } } } GrantOwner grantOwner = person.getGrantOwner(); if (grantOwner != null) { List contractRegimeList = new ArrayList(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Bolseiro
Nº " + grantOwner.getNumber()); for (GrantContract contract : grantOwner.getGrantContracts()) { contractRegimeList.addAll(contract.getContractRegimes()); } Collections.sort(contractRegimeList, new BeanComparator("dateBeginContractYearMonthDay")); for (GrantContractRegime contractRegime : contractRegimeList) { stringBuilder.append("
Início: " + contractRegime.getDateBeginContractYearMonthDay().toString("dd/MM/yyyy")); stringBuilder.append("    -   Fim: " + contractRegime.getDateEndContractYearMonthDay().toString("dd/MM/yyyy")); stringBuilder.append("    -   Activo: "); if (contractRegime.isActive()) { stringBuilder.append("Sim"); } else { stringBuilder.append("Não"); } } occupations.add(stringBuilder.toString()); } List invitations = person.getActiveInvitations(); if (!invitations.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Convidado
"); for (Invitation invitation : invitations) { stringBuilder.append("Por: ").append(invitation.getUnit().getName()).append("
"); stringBuilder.append("Início: " + invitation.getBeginDate().toString("dd/MM/yyyy")); stringBuilder.append("    -   Fim: " + invitation.getEndDate().toString("dd/MM/yyyy")); occupations.add(stringBuilder.toString()); } } } return occupations; } public List getDegreesInformation() { List result = new ArrayList(); if (getParty().isPerson()) { Person person = (Person) getParty(); Student student = person.getStudent(); if (student != null && person.getPersonRole(RoleType.STUDENT) != null) { for (Registration registration : student.getActiveRegistrations()) { StringBuilder stringBuilder = new StringBuilder(); StudentCurricularPlan scp = registration.getLastStudentCurricularPlan(); if (scp != null) { stringBuilder.append(scp.getDegreeCurricularPlan().getName()); stringBuilder.append(" ").append(registration.getCurricularYear()).append("º ano"); if (isFirstTimeEnrolledInCurrentYear(registration)) { stringBuilder.append(" - 1ª vez"); } stringBuilder.append(" - ").append(registration.getAverage()); result.add(stringBuilder.toString()); } } } } return result; } public boolean hasVehicleContainingPlateNumber(String plateNumber) { String plateNumberLowerCase = plateNumber.toLowerCase(); for (Vehicle vehicle : getVehicles()) { if (vehicle.getPlateNumber().toLowerCase().contains(plateNumberLowerCase)) { return true; } } return false; } public void delete() { if (canBeDeleted()) { removeParty(); removeParkingGroup(); deleteDriverLicenseDocument(); for (; getVehicles().size() != 0; getVehicles().get(0).delete()) ; for (; getParkingRequests().size() != 0; getParkingRequests().get(0).delete()) ; removeRootDomainObject(); deleteDomainObject(); } } private void deleteDriverLicenseDocument() { NewParkingDocument parkingDocument = getDriverLicenseDocument(); if (parkingDocument != null) { parkingDocument.delete(); } } private boolean canBeDeleted() { return getVehicles().isEmpty(); } public boolean hasFirstTimeRequest() { return getFirstRequest() != null; } public Integer getMostSignificantNumber() { if (getParty().isPerson()) { if (getPhdNumber() != null) { return getPhdNumber(); } final Person person = (Person) getParty(); final Teacher teacher = person.getTeacher(); final boolean isTeachre = teacher != null && teacher.getCurrentWorkingDepartment() != null; final boolean isMonitor = isTeachre && teacher.isMonitor(ExecutionSemester.readActualExecutionSemester()); if (isTeachre && !isMonitor) { return person.getTeacher().getTeacherNumber(); } final Employee employee = person.getEmployee(); if (employee != null && employee.getCurrentWorkingContract() != null && person.getPersonRole(RoleType.TEACHER) == null) { return employee.getEmployeeNumber(); } if (employee != null && getPartyClassification().equals(PartyClassification.RESEARCHER)) { return employee.getEmployeeNumber(); } final Student student = person.getStudent(); if (student != null) { DegreeType degreeType = student.getMostSignificantDegreeType(); Collection registrations = student.getRegistrationsByDegreeType(degreeType); for (Registration registration : registrations) { StudentCurricularPlan scp = registration.getActiveStudentCurricularPlan(); if (scp != null) { return student.getNumber(); } } } final GrantOwner grantOwner = person.getGrantOwner(); if (grantOwner != null && grantOwner.hasCurrentContract()) { return grantOwner.getNumber(); } if (isTeachre && isMonitor) { return teacher.getTeacherNumber(); } } return 0; } public static List getAll() { return RootDomainObject.getInstance().getParkingParties(); } public void edit(ParkingPartyBean parkingPartyBean) { if (!parkingPartyBean.getCardAlwaysValid() && parkingPartyBean.getCardStartDate().isAfter(parkingPartyBean.getCardEndDate())) { throw new DomainException("error.parkingParty.invalidPeriod"); } if (getCardNumber() != null && (changedDates(getCardStartDate(), parkingPartyBean.getCardStartDate(), parkingPartyBean.getCardAlwaysValid()) || changedDates(getCardEndDate(), parkingPartyBean.getCardEndDate(), parkingPartyBean .getCardAlwaysValid()) || changedObject(getCardNumber(), parkingPartyBean.getCardNumber()) || changedObject(getParkingGroup(), parkingPartyBean.getParkingGroup()) || changedObject(getPhdNumber(), parkingPartyBean.getPhdNumber()))) { new ParkingPartyHistory(this, false); } setCardNumber(parkingPartyBean.getCardNumber()); setCardStartDate(parkingPartyBean.getCardStartDate()); setCardEndDate(parkingPartyBean.getCardEndDate()); setPhdNumber(parkingPartyBean.getPhdNumber()); setParkingGroup(parkingPartyBean.getParkingGroup()); for (VehicleBean vehicleBean : parkingPartyBean.getVehicles()) { if (vehicleBean.getVehicle() != null) { if (vehicleBean.getDeleteVehicle()) { vehicleBean.getVehicle().delete(); } else { vehicleBean.getVehicle().edit(vehicleBean); } } else { if (!vehicleBean.getDeleteVehicle()) { new Vehicle(vehicleBean); } } } setNotes(parkingPartyBean.getNotes()); } private boolean changedDates(DateTime oldDate, DateTime newDate, Boolean cardAlwaysValid) { return cardAlwaysValid ? (oldDate == null ? false : true) : ((oldDate == null || (!oldDate.equals(newDate))) ? true : oldDate.equals(newDate)); } private boolean changedObject(Object oldObject, Object newObject) { return oldObject == null && newObject == null ? false : (oldObject != null && newObject != null ? (!oldObject .equals(newObject)) : true); } public void edit(ParkingRequest parkingRequest) { setDriverLicenseDeliveryType(parkingRequest.getDriverLicenseDeliveryType()); parkingRequest.deleteDriverLicenseDocument(); for (Vehicle vehicle : parkingRequest.getVehicles()) { Vehicle partyVehicle = geVehicleByPlateNumber(vehicle.getPlateNumber()); if (partyVehicle != null) { partyVehicle.edit(vehicle); vehicle.deleteDocuments(); } else { addVehicles(new Vehicle(vehicle)); vehicle.deleteDocuments(); } } setRequestedAs(parkingRequest.getRequestedAs()); } private Vehicle geVehicleByPlateNumber(String plateNumber) { for (Vehicle vehicle : getVehicles()) { if (vehicle.getPlateNumber().equalsIgnoreCase(plateNumber)) { return vehicle; } } return null; } public boolean isActiveInHisGroup() { if (getParkingGroup() == null) { return Boolean.FALSE; } if (getParty().isPerson()) { Person person = (Person) getParty(); if (getParkingGroup().getGroupName().equalsIgnoreCase("Docentes")) { return person.getTeacher() != null && person.getTeacher().getCurrentWorkingDepartment() != null; } if (getParkingGroup().getGroupName().equalsIgnoreCase("Não Docentes")) { return person.getEmployee() != null && person.getEmployee().getCurrentWorkingPlace() != null; } if (getParkingGroup().getGroupName().equalsIgnoreCase("Especiais")) { return person.getPartyClassification() != PartyClassification.PERSON; } if (getParkingGroup().getGroupName().equalsIgnoreCase("2º ciclo")) { if (person.hasStudent()) { return canRequestUnlimitedCard(person.getStudent()); } else { return Boolean.FALSE; } } if (getParkingGroup().getGroupName().equalsIgnoreCase("Bolseiros")) { return person.hasGrantOwner() && person.getGrantOwner().hasCurrentContract(); } if (getParkingGroup().getGroupName().equalsIgnoreCase("3º ciclo")) { if (person.hasStudent()) { Registration registration = getRegistrationByDegreeType(person.getStudent(), DegreeType.BOLONHA_ADVANCED_SPECIALIZATION_DIPLOMA); return registration != null && registration.isActive(); } else { return Boolean.FALSE; } } if (getParkingGroup().getGroupName().equalsIgnoreCase("Limitados")) { return person.getPartyClassification() != PartyClassification.PERSON && person.getPartyClassification() != PartyClassification.RESEARCHER; } } return Boolean.FALSE; } public boolean getCanRequestUnlimitedCardAndIsInAnyRequestPeriod() { ParkingRequestPeriod current = ParkingRequestPeriod.getCurrentRequestPeriod(); return current != null && canRequestUnlimitedCard(current); } public boolean canRequestUnlimitedCard() { return canRequestUnlimitedCard(ParkingRequestPeriod.getCurrentRequestPeriod()); } public boolean canRequestUnlimitedCard(ParkingRequestPeriod parkingRequestPeriod) { if (!alreadyRequestParkingRequestTypeInPeriod(ParkingRequestType.RENEW, parkingRequestPeriod)) { return hasRolesToRequestUnlimitedCard(); } return Boolean.FALSE; } public boolean hasRolesToRequestUnlimitedCard() { List roles = getSubmitAsRoles(); if (roles.contains(RoleType.GRANT_OWNER)) { return Boolean.TRUE; } else if (roles.contains(RoleType.STUDENT) && canRequestUnlimitedCard(((Person) getParty()).getStudent())) { return Boolean.TRUE; } return Boolean.FALSE; } public boolean alreadyRequestParkingRequestTypeInPeriod(ParkingRequestType parkingRequestType, ParkingRequestPeriod parkingRequestPeriod) { List requests = getOrderedParkingRequests(); for (ParkingRequest parkingRequest : requests) { if (parkingRequestPeriod.getRequestPeriodInterval().contains(parkingRequest.getCreationDate()) && parkingRequest.getParkingRequestType().equals(parkingRequestType)) { return true; } } return false; } public boolean canRequestUnlimitedCard(Student student) { List degreeTypes = new ArrayList(); degreeTypes.add(DegreeType.DEGREE); degreeTypes.add(DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA); degreeTypes.add(DegreeType.BOLONHA_MASTER_DEGREE); degreeTypes.add(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE); for (DegreeType degreeType : degreeTypes) { Registration registration = getRegistrationByDegreeType(student, degreeType); if (registration != null && registration.isInFinalDegreeYear()) { return degreeType.equals(DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA) ? Boolean.TRUE : isFirstTimeEnrolledInCurrentYear(registration); } } return false; // DEGREE=Licenciatura (5 anos) - 5º ano // MASTER_DEGREE=Mestrado = 2ciclo - não tem // BOLONHA_DEGREE=Licenciatura Bolonha - não podem // BOLONHA_MASTER_DEGREE=Mestrado Bolonha - só no 5+ ano 1º vez // BOLONHA_INTEGRATED_MASTER_DEGREE=Mestrado Integrado // BOLONHA_ADVANCED_FORMATION_DIPLOMA =Diploma Formação Avançada = cota // pos grad // BOLONHA_PHD_PROGRAM=Programa Doutoral - não estão no fénix // BOLONHA_SPECIALIZATION_DEGREE=Curso de Especialização - não estão no // fénix } public boolean isFirstTimeEnrolledInCurrentYear(Registration registration) { ExecutionYear executionYear = ExecutionYear.readCurrentExecutionYear(); return registration.getCurricularYear(executionYear.getPreviousExecutionYear()) != registration .getCurricularYear(executionYear); } private Registration getRegistrationByDegreeType(Student student, DegreeType degreeType) { for (Registration registration : student.getRegistrationsByDegreeType(degreeType)) { if (registration.isActive()) { StudentCurricularPlan scp = registration.getActiveStudentCurricularPlan(); if (scp != null) { return registration; } } } return null; } public PartyClassification getPartyClassification() { return getParty().isPerson() ? ((Person) getParty()).getPartyClassification() : null; } public DateTime getCardEndDateToCompare() { if (getCardEndDate() == null) { return new DateTime(9999, 9, 9, 9, 9, 9, 9); } else { return getCardEndDate(); } } public DateTime getCardStartDateToCompare() { if (getCardStartDate() == null) { return new DateTime(9999, 9, 9, 9, 9, 9, 9); } else { return getCardStartDate(); } } public void renewParkingCard(DateTime newBeginDate, DateTime newEndDate, ParkingGroup newParkingGroup) { new ParkingPartyHistory(this, false); if (newBeginDate != null) { setCardStartDate(newBeginDate); } setCardEndDate(newEndDate); if (newParkingGroup != null) { setParkingGroup(newParkingGroup); } } }