Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable repeating document requests. FISTM-354 #resolve #1284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1256,48 +1256,44 @@ final public boolean hasAdministrativeOfficeFeeAndInsuranceDebtsCurrently(final
}

public boolean hasDiplomaRequest() {
for (PhdAcademicServiceRequest academicServiceRequest : getPhdAcademicServiceRequestsSet()) {
if (academicServiceRequest.isDiploma() && !academicServiceRequest.isCancelled()
&& !academicServiceRequest.isRejected()) {
return true;
}
}
return getDiplomaRequest() != null;
}

return false;
public boolean hasRegistryDiplomaRequest() {
return getRegistryDiplomaRequest() != null;
}

public PhdRegistryDiplomaRequest getRegistryDiplomaRequest() {
for (PhdAcademicServiceRequest academicServiceRequest : getPhdAcademicServiceRequestsSet()) {
if (academicServiceRequest.isRegistryDiploma() && !academicServiceRequest.isCancelled()
&& !academicServiceRequest.isRejected()) {
return (PhdRegistryDiplomaRequest) academicServiceRequest;
}
}
final public PhdDiplomaRequest getDiplomaRequest() {
return getLatestRequest(getDiplomaRequests());
}

return null;
final public Set<PhdDiplomaRequest> getDiplomaRequests() {
return getRequests(PhdDiplomaRequest.class);
}

public boolean hasRegistryDiplomaRequest() {
return getRegistryDiplomaRequest() != null;
final public PhdRegistryDiplomaRequest getRegistryDiplomaRequest() {
return getLatestRequest(getRegistryDiplomaRequests());
}

public PhdDiplomaRequest getDiplomaRequest() {
for (PhdAcademicServiceRequest academicServiceRequest : getPhdAcademicServiceRequestsSet()) {
if (academicServiceRequest.isDiploma() && !academicServiceRequest.isCancelled()
&& !academicServiceRequest.isRejected()) {
return (PhdDiplomaRequest) academicServiceRequest;
}
}
final public Set<PhdRegistryDiplomaRequest> getRegistryDiplomaRequests() {
return getRequests(PhdRegistryDiplomaRequest.class);
}

return null;
final public PhdDiplomaSupplementRequest getDiplomaSupplementRequest() {
return getLatestRequest(getDiplomaSupplementRequests());
}

public PhdDiplomaSupplementRequest getDiplomaSupplementRequest() {
if (!hasRegistryDiplomaRequest()) {
return null;
}
final public Set<PhdDiplomaSupplementRequest> getDiplomaSupplementRequests() {
return getRequests(PhdDiplomaSupplementRequest.class);
}

return getRegistryDiplomaRequest().getDiplomaSupplement();
private <T extends PhdAcademicServiceRequest> T getLatestRequest(Collection<T> requests){
return requests.stream().sorted(Comparator.comparing(PhdAcademicServiceRequest::getCreationDate).reversed())
.findFirst().orElse(null);
}
private <T extends PhdAcademicServiceRequest> Set<T> getRequests(Class<T> c) {
return getPhdAcademicServiceRequestsSet().stream().filter(dr -> c.isInstance(dr) && !dr.finishedUnsuccessfully())
.map(c::cast).collect(Collectors.toSet());
}

public PhdConclusionProcess getLastConclusionProcess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
package org.fenixedu.academic.domain.phd.serviceRequests;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.fenixedu.academic.domain.Person;
Expand All @@ -28,6 +30,7 @@
import org.fenixedu.academic.domain.phd.serviceRequests.documentRequests.PhdDocumentRequest;
import org.fenixedu.academic.domain.phd.serviceRequests.documentRequests.PhdRegistryDiplomaRequest;
import org.fenixedu.academic.domain.phd.serviceRequests.documentRequests.certificates.PhdFinalizationCertificateRequest;
import org.fenixedu.academic.domain.serviceRequests.RegistryCode;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.AcademicServiceRequestType;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.DocumentRequestType;

Expand All @@ -39,6 +42,9 @@ public class PhdDocumentRequestCreateBean extends PhdAcademicServiceRequestCreat
private String givenNames;
private String familyNames;

private RegistryCode registryCode;
private List<RegistryCode> associateCodes;

private DocumentRequestType documentRequestType;

public PhdDocumentRequestCreateBean(PhdIndividualProgramProcess phdIndividualProgramProcess) {
Expand Down Expand Up @@ -77,6 +83,22 @@ public void setFamilyNames(String familyNames) {
this.familyNames = familyNames;
}

public RegistryCode getRegistryCode() {
return registryCode;
}

public void setRegistryCode(RegistryCode registryCode) {
this.registryCode = registryCode;
}

public List<RegistryCode> getAssociateCodes() {
return associateCodes != null ? new ArrayList<>(associateCodes) : new ArrayList<>();
}

public void setAssociateCodes(List<RegistryCode> associateCodes) {
this.associateCodes = associateCodes != null ? new ArrayList<>(associateCodes) : new ArrayList<>();
}

public DocumentRequestType getDocumentRequestType() {
return documentRequestType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,34 @@ protected void init(final PhdDocumentRequestCreateBean bean) {
PhdDiplomaRequestEvent.create(getAdministrativeOffice(), getPhdIndividualProgramProcess().getPerson(), this);
}

applyRegistryCode();
}

private void applyRegistryCode() {
RegistryCode code = getRegistryCode();
RegistryCode code = bean.getRegistryCode();
if (code != null) {
if (!code.getDocumentRequestSet().contains(this)) {
code.addDocumentRequest(this);
}
setRegistryCode(code);
} else {
getRootDomainObject().getInstitutionUnit().getRegistryCodeGenerator().createRegistryFor(this);
}
}


private void checkParameters(final PhdDocumentRequestCreateBean bean) {
PhdIndividualProgramProcess process = bean.getPhdIndividualProgramProcess();
RegistryCode code = bean.getRegistryCode();

if (process.hasDiplomaRequest()) {
throw new PhdDomainOperationException("error.phdDiploma.alreadyHasDiplomaRequest");
}

checkRegistryDiplomaRequest(process);
}

private void checkRegistryDiplomaRequest(PhdIndividualProgramProcess process) {

if (!process.isBolonha()) {
return;
}

if (!process.hasRegistryDiplomaRequest()) {
throw new PhdDomainOperationException("error.phdDiploma.registryDiploma.must.be.requested");
}

PhdRegistryDiplomaRequest phdRegistryDiploma = process.getRegistryDiplomaRequest();

if (phdRegistryDiploma.isPayedUponCreation() && !phdRegistryDiploma.getEvent().isPayed()) {
throw new PhdDomainOperationException("error.phdDiploma.registryDiploma.must.be.payed");
if(code == null) {
if(process.isBolonha()) {
throw new PhdDomainOperationException("error.phdDiploma.codeRequired");
}
} else {
if (code.getPhdDiploma() != null) {
throw new PhdDomainOperationException("error.phdDiploma.alreadyHasDiplomaRequest");
}
PhdRegistryDiplomaRequest phdRegistryDiploma = code.getPhdRegistryDiploma();
if (phdRegistryDiploma == null) {
throw new PhdDomainOperationException("error.phdDiploma.registryDiploma.must.be.requested");
}
if (phdRegistryDiploma.isPayedUponCreation() && !phdRegistryDiploma.getEvent().isPayed()) {
throw new PhdDomainOperationException("error.phdDiploma.registryDiploma.must.be.payed");
}
}
}

Expand Down Expand Up @@ -156,18 +146,6 @@ public boolean hasPersonalInfo() {
return true;
}

@Override
public RegistryCode getRegistryCode() {
PhdIndividualProgramProcess phdIndividualProgramProcess = getPhdIndividualProgramProcess();
RegistryCode registryCode = null;

if (phdIndividualProgramProcess.hasRegistryDiplomaRequest()) {
registryCode = phdIndividualProgramProcess.getRegistryDiplomaRequest().getRegistryCode();
}

return registryCode != null ? registryCode : super.getRegistryCode();
}

@Override
protected void internalChangeState(AcademicServiceRequestBean academicServiceRequestBean) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.fenixedu.academic.domain.phd.serviceRequests.PhdDocumentRequestCreateBean;
import org.fenixedu.academic.domain.phd.thesis.PhdThesisFinalGrade;
import org.fenixedu.academic.domain.serviceRequests.IDiplomaSupplementRequest;
import org.fenixedu.academic.domain.serviceRequests.RegistryCode;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.DocumentRequestType;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.IRectorateSubmissionBatchDocumentEntry;
import org.fenixedu.academic.domain.student.Registration;
Expand Down Expand Up @@ -69,6 +70,7 @@ protected void init(final PhdDocumentRequestCreateBean bean) {
super.init(bean);
checkParameters(bean);

setRegistryCode(bean.getRegistryCode());
getPhdIndividualProgramProcess().getPerson().getProfile().changeName(bean.getGivenNames(), bean.getFamilyNames(), null);
}

Expand All @@ -82,14 +84,13 @@ private void checkParameters(final PhdDocumentRequestCreateBean bean) {
throw new DomainException("error.diplomaSupplementRequest.splittedNamesDoNotMatch");
}

PhdIndividualProgramProcess process = getPhdIndividualProgramProcess();
if (!process.hasRegistryDiplomaRequest() && process.hasDiplomaRequest()) {
RegistryCode code = bean.getRegistryCode();
if (code == null || (code.getPhdRegistryDiploma() == null && code.getPhdDiploma() == null)) {
throw new DomainException(
"error.diplomaSupplementRequest.cannotAskForSupplementWithoutEitherRegistryDiplomaOrDiplomaRequest");
}

final PhdDiplomaSupplementRequest supplement = process.getDiplomaSupplementRequest();
if (supplement != null && supplement != this) {
if(code.getPhdDiplomaSupplement() != null) {
throw new DomainException("error.diplomaSupplementRequest.alreadyRequested");
}
}
Expand Down Expand Up @@ -155,10 +156,6 @@ protected void internalChangeState(AcademicServiceRequestBean academicServiceReq
"error.phdDiplomaSupplement.registration.not.submited.to.conclusion.process");
}

if (getRegistryCode() == null) {
getRegistryDiplomaRequest().getRegistryCode().addDocumentRequest(this);
}

if (getLastGeneratedDocument() == null) {
generateDocument();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.fenixedu.academic.domain.phd.serviceRequests.PhdDocumentRequestCreateBean;
import org.fenixedu.academic.domain.phd.thesis.PhdThesisFinalGrade;
import org.fenixedu.academic.domain.serviceRequests.IRegistryDiplomaRequest;
import org.fenixedu.academic.domain.serviceRequests.RegistryCode;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.DocumentRequestType;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.IRectorateSubmissionBatchDocumentEntry;
import org.fenixedu.academic.dto.serviceRequests.AcademicServiceRequestBean;
Expand Down Expand Up @@ -73,20 +74,28 @@ protected void init(final PhdDocumentRequestCreateBean bean) {
PhdRegistryDiplomaRequestEvent.create(getAdministrativeOffice(), getPhdIndividualProgramProcess().getPerson(), this);
}

RegistryCode code = bean.getRegistryCode();
if (code != null) {
setRegistryCode(code);
} else {
code = getRootDomainObject().getInstitutionUnit().getRegistryCodeGenerator().createRegistryFor(this);
bean.setRegistryCode(code);
}

setDiplomaSupplement(PhdDiplomaSupplementRequest.create(bean));
}

private void checkParameters(final PhdDocumentRequestCreateBean bean) {
PhdIndividualProgramProcess process = bean.getPhdIndividualProgramProcess();
if (process.hasRegistryDiplomaRequest()) {
throw new PhdDomainOperationException("error.registryDiploma.alreadyRequested");
}
RegistryCode code = bean.getRegistryCode();

if (!process.isBolonha()) {
return;
if(code != null) {
if (code.getPhdRegistryDiploma() != null) {
throw new PhdDomainOperationException("error.registryDiploma.alreadyRequested");
}
}

if (process.hasDiplomaRequest()) {
if (process.isBolonha() && process.hasDiplomaRequest()) {
throw new PhdDomainOperationException("error.registryDiploma.alreadyHasDiplomaRequest");
}

Expand Down Expand Up @@ -203,18 +212,7 @@ protected void internalChangeState(AcademicServiceRequestBean academicServiceReq
throw new PhdDomainOperationException("AcademicServiceRequest.hasnt.been.payed");
}

if (getRegistryCode() == null) {

PhdDiplomaRequest diplomaRequest = getPhdIndividualProgramProcess().getDiplomaRequest();

if (diplomaRequest != null && diplomaRequest.hasRegistryCode()) {
diplomaRequest.getRegistryCode().addDocumentRequest(this);
} else {
getRootDomainObject().getInstitutionUnit().getRegistryCodeGenerator().createRegistryFor(this);
}

getAdministrativeOffice().getCurrentRectorateSubmissionBatch().addDocumentRequest(this);
}
getAdministrativeOffice().getCurrentRectorateSubmissionBatch().addDocumentRequest(this);

if (getLastGeneratedDocument() == null) {
generateDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.fenixedu.academic.domain.phd.serviceRequests.PhdDocumentRequestCreateBean;
import org.fenixedu.academic.domain.phd.serviceRequests.documentRequests.PhdRegistryDiplomaRequest;
import org.fenixedu.academic.domain.serviceRequests.RectorateSubmissionBatch;
import org.fenixedu.academic.domain.serviceRequests.RegistryCode;
import org.fenixedu.academic.domain.serviceRequests.documentRequests.DocumentRequestType;
import org.fenixedu.academic.dto.serviceRequests.AcademicServiceRequestBean;
import org.fenixedu.academic.report.academicAdministrativeOffice.AdministrativeOfficeDocument;
Expand All @@ -48,9 +49,15 @@ protected PhdFinalizationCertificateRequest(PhdDocumentRequestCreateBean bean) {

this.init(bean);

PhdRegistryDiplomaRequest registryDiplomaRequest = getPhdIndividualProgramProcess().getRegistryDiplomaRequest();
RegistryCode code = bean.getRegistryCode();

if (registryDiplomaRequest == null) {
if(code == null) {
throw new PhdDomainOperationException("error.PhdFinalizationCertificateRequest.codeRequired");
}
setRegistryCode(code);

PhdRegistryDiplomaRequest registryDiplomaRequest = code.getPhdRegistryDiploma();
if(registryDiplomaRequest == null) {
throw new PhdDomainOperationException("error.PhdFinalizationCertificateRequest.registry.diploma.request.none");
}

Expand All @@ -71,14 +78,6 @@ protected void init(PhdDocumentRequestCreateBean bean) {
PhdFinalizationCertificateRequestEvent.create(getAdministrativeOffice(), getPerson(), this);
}

if (!bean.getPhdIndividualProgramProcess().isBolonha()) {
return;
}

if (getPhdIndividualProgramProcess().getRegistryDiplomaRequest() == null) {
throw new PhdDomainOperationException("error.PhdFinalizationCertificateRequest.registry.diploma.not.requested");
}

}

@Override
Expand All @@ -92,7 +91,7 @@ protected void internalChangeState(AcademicServiceRequestBean academicServiceReq

super.internalChangeState(academicServiceRequestBean);
if (academicServiceRequestBean.isToProcess()) {
PhdRegistryDiplomaRequest registryDiplomaRequest = getPhdIndividualProgramProcess().getRegistryDiplomaRequest();
PhdRegistryDiplomaRequest registryDiplomaRequest = getRegistryCode().getPhdRegistryDiploma();

if (registryDiplomaRequest == null) {
throw new PhdDomainOperationException("error.PhdFinalizationCertificateRequest.registry.diploma.request.none");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ final public boolean isDocumentRequest() {
* Special condition for pre-existing documents that are able to consume a
* registry number.
*/
public boolean isCanGenerateRegistryCode() {
public boolean isManuallySentToRectorate() {
return false;
}

Expand Down
Loading