Skip to content

Commit

Permalink
Merge pull request #1144 from eralmeida/ACDM-1250
Browse files Browse the repository at this point in the history
Student Statutes are now Editable in the Academic Office Portal ACDM-1250 #resolve
  • Loading branch information
sergiofbsilva committed Apr 4, 2017
2 parents 16df62e + 3e21b22 commit ecf7587
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.fenixedu.academic.domain.exceptions;

import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.ws.rs.core.Response.Status;
Expand All @@ -37,6 +38,10 @@ public DomainException(final String key, final String... args) {
super(DEFAULT_BUNDLE, key, args);
}

public DomainException(Optional<String> bundle, final String key, final String... args) {
super(bundle == null ? DEFAULT_BUNDLE : bundle.orElse(DEFAULT_BUNDLE), key, args);
}

public DomainException(Status status, String key, String... args) {
super(status, DEFAULT_BUNDLE, key, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
package org.fenixedu.academic.domain.student;

import java.util.Optional;

import org.fenixedu.academic.domain.ExecutionSemester;
import org.fenixedu.academic.domain.exceptions.DomainException;
import org.fenixedu.academic.util.Bundle;
import org.joda.time.LocalDate;

public class SeniorStatute extends SeniorStatute_Base {
Expand Down Expand Up @@ -47,11 +50,17 @@ public SeniorStatute(Student student, Registration registration, StatuteType sta
public SeniorStatute(Student student, Registration registration, StatuteType statuteType, ExecutionSemester
beginExecutionPeriod, ExecutionSemester endExecutionPeriod, LocalDate beginDate, LocalDate endDate, String comment) {
this();
setType(statuteType);
edit(student, registration, beginExecutionPeriod, endExecutionPeriod, beginDate, endDate, comment);
}

public void edit(Student student, Registration registration, ExecutionSemester beginExecutionPeriod,
ExecutionSemester endExecutionPeriod, LocalDate beginDate, LocalDate endDate, String comment) {

setBeginDate(beginDate);
setEndDate(endDate);
setBeginExecutionPeriod(beginExecutionPeriod);
setEndExecutionPeriod(endExecutionPeriod);
setType(statuteType);
setComment(comment);

for (StudentStatute statute : student.getStudentStatutesSet()) {
Expand All @@ -62,7 +71,7 @@ public SeniorStatute(Student student, Registration registration, StatuteType sta
continue;
}

throw new DomainException("error.studentStatute.alreadyExistsOneOverlapingStatute");
throw new DomainException(Optional.of(Bundle.ACADEMIC), "error.studentStatute.alreadyExistsOneOverlapingStatute");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
*/
package org.fenixedu.academic.domain.student;

import java.util.Optional;
import java.util.Set;

import org.fenixedu.academic.domain.ExecutionInterval;
import org.fenixedu.academic.domain.ExecutionSemester;
import org.fenixedu.academic.domain.ExecutionYear;
import org.fenixedu.academic.domain.StudentCurricularPlan;
import org.fenixedu.academic.domain.exceptions.DomainException;
import org.fenixedu.academic.util.Bundle;
import org.fenixedu.bennu.core.domain.Bennu;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
Expand Down Expand Up @@ -62,22 +64,8 @@ public StudentStatute(Student student, StatuteType statuteType, ExecutionSemeste
public StudentStatute(Student student, StatuteType statuteType, ExecutionSemester beginExecutionPeriod, ExecutionSemester
endExecutionPeriod, LocalDate beginDate, LocalDate endDate, String comment) {
this();
setBeginDate(beginDate);
setEndDate(endDate);
setBeginExecutionPeriod(beginExecutionPeriod);
setEndExecutionPeriod(endExecutionPeriod);
setType(statuteType);
setComment(comment);

for (StudentStatute statute : student.getStudentStatutesSet()) {
if (statute.overlapsWith(this)) {
throw new DomainException("error.studentStatute.alreadyExistsOneOverlapingStatute");
}
}

setStudent(student);

checkRules();
edit(student, beginExecutionPeriod, endExecutionPeriod, beginDate, endDate, comment);
}

protected void checkRules() {
Expand Down Expand Up @@ -143,6 +131,26 @@ public boolean isValidInCurrentExecutionPeriod() {
return this.isValidInExecutionPeriod(ExecutionSemester.readActualExecutionSemester());
}

public void edit(Student student, ExecutionSemester beginExecutionPeriod, ExecutionSemester endExecutionPeriod,
LocalDate beginDate, LocalDate endDate, String comment) {

setBeginExecutionPeriod(beginExecutionPeriod);
setEndExecutionPeriod(endExecutionPeriod);
setBeginDate(beginDate);
setEndDate(endDate);
setComment(comment);

for (StudentStatute statute : student.getStudentStatutesSet()) {
if (statute.overlapsWith(this)) {
throw new DomainException(Optional.of(Bundle.ACADEMIC), "error.studentStatute.alreadyExistsOneOverlapingStatute");
}
}

setStudent(student);

checkRules();
}

public void delete() {
checkRulesToDelete();
setBeginExecutionPeriod(null);
Expand All @@ -154,6 +162,10 @@ public void delete() {
}

public boolean overlapsWith(StudentStatute statute) {

if (statute == this) {
return false;
}
ExecutionSemester statuteBegin =
statute.getBeginExecutionPeriod() != null ? statute.getBeginExecutionPeriod() : ExecutionSemester
.readFirstExecutionSemester();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@

/**
* @author - Shezad Anavarali (shezad@ist.utl.pt)
*
*
*/
@Mapping(path = "/studentStatutes", module = "academicAdministration", functionality = SearchForStudentsDA.class)
@Forwards({ @Forward(name = "manageStatutes", path = "/academicAdminOffice/manageStatutes.jsp") })
@Forwards({ @Forward(name = "manageStatutes", path = "/academicAdminOffice/manageStatutes.jsp"),
@Forward(name = "editStatute", path = "/academicAdminOffice/editStatute.jsp") })
public class StudentStatutesDA extends FenixDispatchAction {

public static class CreateStudentStatuteFactory extends ManageStudentStatuteBean implements FactoryExecutor {
Expand Down Expand Up @@ -103,6 +104,16 @@ public ActionForward invalid(ActionMapping mapping, ActionForm actionForm, HttpS
return mapping.findForward("manageStatutes");
}

public ActionForward invalidEdit(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {

keepInRequest(request, "statuteId");
keepInRequest(request, "schemaName");
request.setAttribute("manageStatuteBean", getRenderedObject());

return mapping.findForward("editStatute");
}

public ActionForward seniorStatutePostBack(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {

Expand Down Expand Up @@ -133,7 +144,7 @@ public ActionForward addNewStatute(ActionMapping mapping, ActionForm actionForm,
// add new statute
executeFactoryMethod();
} catch (DomainException e) {
addActionMessage(request, e.getMessage());
request.setAttribute("error", e.getLocalizedMessage());
}

final Student student = ((CreateStudentStatuteFactory) getRenderedObject()).getStudent();
Expand Down Expand Up @@ -166,4 +177,55 @@ public ActionForward deleteStatute(ActionMapping mapping, ActionForm actionForm,

}

public ActionForward prepareEditStatute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws FenixServiceException {

StudentStatute studentStatute = getDomainObject(request, "statuteId");
Student student = studentStatute.getStudent();

ManageStudentStatuteBean bean = new CreateStudentStatuteFactory(student);
bean.setStatuteType(studentStatute.getType());
bean.setBeginExecutionPeriod(studentStatute.getBeginExecutionPeriod());
bean.setEndExecutionPeriod(studentStatute.getEndExecutionPeriod());
bean.setBeginDate(studentStatute.getBeginDate());
bean.setEndDate(studentStatute.getEndDate());
bean.setComment(studentStatute.getComment());

request.setAttribute("statuteId", studentStatute.getExternalId());
request.setAttribute("manageStatuteBean", bean);

if (studentStatute.getType().isSeniorStatute()) {
request.setAttribute("schemaName", "student.editSeniorStatute");
bean.setRegistration(((SeniorStatute) studentStatute).getRegistration());
} else {
request.setAttribute("schemaName", "student.editStatutes");
}

return mapping.findForward("editStatute");
}

public ActionForward editStatute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws FenixServiceException {
final ManageStudentStatuteBean manageStatuteBean = getRenderedObject();
StudentStatute studentStatute = getDomainObject(request, "statuteId");

try {
atomic(() -> {
if (manageStatuteBean.getStatuteType().isSeniorStatute()) {
((SeniorStatute) studentStatute).edit(manageStatuteBean.getStudent(), manageStatuteBean.getRegistration(),
manageStatuteBean.getBeginExecutionPeriod(), manageStatuteBean.getEndExecutionPeriod(),
manageStatuteBean.getBeginDate(), manageStatuteBean.getEndDate(), manageStatuteBean.getComment());
} else {
studentStatute.edit(manageStatuteBean.getStudent(), manageStatuteBean.getBeginExecutionPeriod(),
manageStatuteBean.getEndExecutionPeriod(), manageStatuteBean.getBeginDate(),
manageStatuteBean.getEndDate(), manageStatuteBean.getComment());
}
});
} catch (DomainException e) {
request.setAttribute("error", e.getLocalizedMessage());
return prepareEditStatute(mapping, actionForm, request, response);
}
return redirect("/studentStatutes.do?method=prepare&studentId=" + studentStatute.getStudent().getExternalId(), request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ label.add.attends = Add an attends
label.add.studentData = Insert Student Info
label.addNewActivity = Add New Activity
label.addNewStatute = Add New Statute
label.editStatute = Edit Statute
label.address = Address
label.agreementInformation = Number
label.almamater = Alma Mater
Expand Down Expand Up @@ -2246,7 +2247,6 @@ label.manageStudentCurricularPlans.startDate=Start Date
link.student.printRegistrationDeclaration = Print Registration Declaration
link.student.report.download = Contacts, Media e Permissions
link.student.setEvaluations = Reviews
link.student.statute.delete = Delete Statute
link.student.transitToBolonha = Transfer to Bologne
link.student.unenrol = Unenroll
link.student.viewCurriculum = View Curriculum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ label.add.attends = Adicionar uma frequ
label.add.studentData = Inserir Informação
label.addNewActivity = Adicionar Nova Actividade
label.addNewStatute = Adicionar Novo Estatuto
label.editStatute = Editar Estatuto
label.address = Morada
label.agreementInformation = Número
label.almamater = Alma Mater
Expand Down Expand Up @@ -2246,7 +2247,6 @@ label.manageStudentCurricularPlans.startDate=Data de In
link.student.printRegistrationDeclaration = Imprimir Declaração de Matrícula
link.student.report.download = Contactos, média e autorizações
link.student.setEvaluations = Avaliações
link.student.statute.delete = Apagar Estatuto
link.student.transitToBolonha = Transitar
link.student.unenrol = Desinscrever
link.student.viewCurriculum = Ver Currículo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1521,8 +1521,8 @@ label.NOT_PROCESSED_PAYMENT = Payment Not Processed
label.noResultsFound = No Results Found
title.academic.configurations = Academic Configurations
error.StatuteType.code.alreadyUsed = The specified code already exists
error.studentStatute.beginPeriod.after.endPeriod = The begin semester must be before the end semester
error.studentStatute.beginDate.after.endPeriod = The begin date must be before the end date
error.studentStatute.beginPeriod.after.endPeriod = The begin period must be prior to the end period
error.studentStatute.beginDate.after.endPeriod = The begin date must be prior to the end date
error.studentStatute.missing.StatuteType = Cannot create a student statute without type
error.studentStatute.delete = Error while trying to delete a Student Statute:
success.studentStatute.delete = The Statute Type was deleted successfuly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1522,8 +1522,8 @@ label.NOT_PROCESSED_PAYMENT = Pagamento N
label.noResultsFound = N�o foram encontrados resultados
title.academic.configurations = Configura��es Acad�micas
error.StatuteType.code.alreadyUsed = O c�digo inserido j� existe
error.studentStatute.beginPeriod.after.endPeriod = O semestre de in�cio deve ser antes do semestre de fim
error.studentStatute.beginDate.after.endPeriod = A data de in�cio deve ser antes da data de fim
error.studentStatute.beginPeriod.after.endPeriod = O per�odo de in�cio deve ser anterior ao per�odo de fim
error.studentStatute.beginDate.after.endPeriod = A data de in�cio deve ser anterior � data de fim
error.studentStatute.missing.StatuteType = N�o � poss�vel criar um Estatuto de Aluno sem tipo
error.studentStatute.delete = Ocorreu um erro ao tentar apagar o tipo de Estatuto de Aluno:
success.studentStatute.delete = O tipo de Estatuto foi apagado com sucesso.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@
<property name="providerClass"
value="org.fenixedu.academic.ui.renderers.providers.VisibleStudentStatuteTypeProvider" />
<property name="format" value="${name.content}" />
<property name="destination" value="seniorStatutePostBack"/>
<property name="destination" value="seniorStatutePostBack"/>
</slot>
<slot name="beginExecutionPeriod" layout="menu-select" key="label.beginExecutionPeriod" validator="pt.ist.fenixWebFramework.renderers.validators.RequiredValidator" >
<property name="providerClass" value="org.fenixedu.academic.ui.renderers.providers.StudentExecutionPeriodsProvider" />
Expand Down Expand Up @@ -689,6 +689,41 @@
</slot>
</schema>

<schema name="student.editStatutes" bundle="ACADEMIC_OFFICE_RESOURCES"
type="org.fenixedu.academic.dto.student.ManageStudentStatuteBean">
<slot name="statuteType" read-only="true" key="label.statuteType">
<property name="providerClass"
value="org.fenixedu.academic.ui.renderers.providers.VisibleStudentStatuteTypeProvider" />
<property name="format" value="${name.content}" />
<property name="destination" value="seniorStatutePostBack"/>
</slot>
<slot name="beginExecutionPeriod" layout="menu-select" key="label.beginExecutionPeriod" validator="pt.ist.fenixWebFramework.renderers.validators.RequiredValidator" >
<property name="providerClass" value="org.fenixedu.academic.ui.renderers.providers.StudentExecutionPeriodsProvider" />
<property name="format" value="${semester}º Sem - ${executionYear.year}" />
</slot>
<slot name="endExecutionPeriod" layout="menu-select" key="label.endExecutionPeriod" validator="pt.ist.fenixWebFramework.renderers.validators.RequiredValidator" >
<property name="providerClass" value="org.fenixedu.academic.ui.renderers.providers.StudentExecutionPeriodsProvider" />
<property name="format" value="${semester}º Sem - ${executionYear.year}" />
</slot>
<slot name="beginDate" key="label.beginDate">
<property name="size" value="12"/>
<property name="maxLength" value="10"/>
</slot>
<slot name="endDate" key="label.endDate">
<property name="size" value="12"/>
<property name="maxLength" value="10"/>
</slot>
<slot name="comment" key="label.comment"></slot>
</schema>

<schema name="student.editSeniorStatute" extends="student.editStatutes"
bundle="ACADEMIC_OFFICE_RESOURCES" type="org.fenixedu.academic.dto.student.ManageStudentStatuteBean">
<slot name="registration" layout="menu-select" key="label.studentRegistrations" validator="pt.ist.fenixWebFramework.renderers.validators.RequiredValidator">
<property name="providerClass" value="org.fenixedu.academic.ui.renderers.providers.StudentRegisrationsProvider" />
<property name="format" value="${degree.presentationName}" />
</slot>
</schema>

<schema name="student.extraCurricularActivities" bundle="ACADEMIC_OFFICE_RESOURCES"
type="org.fenixedu.academic.domain.student.curriculum.ExtraCurricularActivity">
<slot name="type.name" key="label.extraCurricularActivity.type" />
Expand Down
51 changes: 51 additions & 0 deletions src/main/webapp/academicAdminOffice/editStatute.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<%--
Copyright © 2017 Instituto Superior Técnico
This file is part of FenixEdu Academic.
FenixEdu Academic 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 Academic 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 Academic. If not, see <http://www.gnu.org/licenses/>.
--%>
<%@ page isELIgnored="true"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://fenix-ashes.ist.utl.pt/fenix-renderers" prefix="fr" %>
<html:xhtml/>

<h3 class="mtop15 mbottom025"><bean:message key="label.editStatute" bundle="ACADEMIC_OFFICE_RESOURCES"/></h3>

<logic:present name="error">
<p>
<span class="error"><!-- Error messages go here --><bean:write name="error" /></span>
</p>
</logic:present>

<bean:define id="studentID" name="manageStatuteBean" property="student.externalId"/>
<bean:define id="statuteId" name="statuteId"/>
<bean:define id="schemaID" name="schemaName"/>

<fr:edit name="manageStatuteBean" schema="<%= schemaID.toString() %>" action="<%="/studentStatutes.do?method=editStatute&statuteId=" + statuteId %>">
<fr:layout name="tabular">
<fr:property name="classes" value="tstyle4 thright thlight"/>
<fr:property name="columnClasses" value=",,tdclear tderror1"/>
</fr:layout>
<fr:hidden slot="student" name="student" />
<fr:destination name="invalid" path="<%="/studentStatutes.do?method=invalidEdit&statuteId=" + statuteId + "&schemaName=" + schemaID.toString()%>"/>
<fr:destination name="cancel" path="<%="/studentStatutes.do?method=prepare&studentId=" + studentID%>" />
</fr:edit>



0 comments on commit ecf7587

Please sign in to comment.