Java tutorial
/** * Copyright 2002 Instituto Superior Tcnico * * This file is part of FenixEdu Core. * * FenixEdu Core 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 Core 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 Core. If not, see <http://www.gnu.org/licenses/>. */ package net.sourceforge.fenixedu.domain.phd.serviceRequests; import java.util.Arrays; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.phd.PhdIndividualProgramProcess; import net.sourceforge.fenixedu.domain.phd.serviceRequests.documentRequests.PhdDiplomaRequest; import net.sourceforge.fenixedu.domain.phd.serviceRequests.documentRequests.PhdDocumentRequest; import net.sourceforge.fenixedu.domain.phd.serviceRequests.documentRequests.PhdRegistryDiplomaRequest; import net.sourceforge.fenixedu.domain.phd.serviceRequests.documentRequests.certificates.PhdFinalizationCertificateRequest; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.AcademicServiceRequestType; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.DocumentRequestType; import org.apache.commons.lang.StringUtils; import pt.ist.fenixframework.Atomic; public class PhdDocumentRequestCreateBean extends PhdAcademicServiceRequestCreateBean { private static final long serialVersionUID = 1L; private String givenNames; private String familyNames; private DocumentRequestType documentRequestType; public PhdDocumentRequestCreateBean(PhdIndividualProgramProcess phdIndividualProgramProcess) { super(phdIndividualProgramProcess); setRequestType(AcademicServiceRequestType.DOCUMENT); setGivenAndFamilyNames(); } private void setGivenAndFamilyNames() { final Person person = getPhdIndividualProgramProcess().getPerson(); if (StringUtils.isEmpty(person.getGivenNames())) { String[] parts = person.getName().split("\\s+"); int split = parts.length > 3 ? 2 : 1; setGivenNames(StringUtils.join(Arrays.copyOfRange(parts, 0, split), " ")); setFamilyNames(StringUtils.join(Arrays.copyOfRange(parts, split, parts.length), " ")); } else { setGivenNames(person.getGivenNames()); setFamilyNames(person.getFamilyNames()); } } public String getGivenNames() { return givenNames; } public void setGivenNames(String givenNames) { this.givenNames = givenNames; } public String getFamilyNames() { return familyNames; } public void setFamilyNames(String familyNames) { this.familyNames = familyNames; } public DocumentRequestType getDocumentRequestType() { return documentRequestType; } public void setDocumentRequestType(DocumentRequestType documentRequestType) { this.documentRequestType = documentRequestType; } @Atomic @Override public PhdDocumentRequest createNewRequest() { switch (getDocumentRequestType()) { case DIPLOMA_REQUEST: return PhdDiplomaRequest.create(this); case REGISTRY_DIPLOMA_REQUEST: return PhdRegistryDiplomaRequest.create(this); case PHD_FINALIZATION_CERTIFICATE: return PhdFinalizationCertificateRequest.create(this); default: throw new DomainException("error.PhdAcademicServiceRequest.create.document.request.type.unknown"); } } }