use of fi.otavanopisto.pyramus.dao.application.ApplicationSignaturesDAO in project pyramus by otavanopisto.
the class GenerateAcceptanceDocumentJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
// Ensure user has SSN to be able to eventually sign the generated document
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember staffMember = staffMemberDAO.findById(requestContext.getLoggedUserId());
if (staffMember == null) {
logger.warning("Current user cannot be resolved");
fail(requestContext, "Et ole kirjautunut sisään");
return;
}
if (StringUtils.isBlank(staffMember.getPerson().getSocialSecurityNumber())) {
logger.warning("Current user lacks social security number");
fail(requestContext, "Allekirjoittamiseen vaadittua henkilötunnusta ei ole asetettu");
return;
}
// Find application and ensure its state
Long id = requestContext.getLong("id");
if (id == null) {
logger.warning("Missing application id");
fail(requestContext, "Puuttuva hakemustunnus");
return;
}
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findById(id);
if (application == null) {
logger.warning(String.format("Application with id %d not found", id));
fail(requestContext, String.format("Hakemusta tunnuksella %d ei löytynyt", id));
return;
}
if (application.getState() != ApplicationState.WAITING_STAFF_SIGNATURE) {
logger.warning(String.format("Application with id %d in incorrect state (%s)", id, application.getState()));
fail(requestContext, "Hakemus ei ole allekirjoitettavassa tilassa");
return;
}
// Signatures tracking
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures signatures = applicationSignaturesDAO.findByApplication(application);
if (signatures == null) {
signatures = applicationSignaturesDAO.create(application);
}
if (signatures.getStaffDocumentState() == ApplicationSignatureState.SIGNED) {
fail(requestContext, "Hyväksymisasiakirja on jo allekirjoitettu");
return;
}
// Gather required dynamic data for the PDF document
JSONObject formData = JSONObject.fromObject(application.getFormData());
String applicantName = String.format("%s %s", getFormValue(formData, "field-first-names"), getFormValue(formData, "field-last-name"));
String line = application.getLine();
String documentName = String.format("Hyväksyntä: %s", applicantName);
OnnistuuClient onnistuuClient = OnnistuuClient.getInstance();
try {
// Generate Onnistuu document (if not done before)
String documentId = null;
if (signatures.getStaffDocumentId() == null) {
documentId = onnistuuClient.createDocument(documentName);
signatures = applicationSignaturesDAO.updateStaffDocument(signatures, documentId, null, null, ApplicationSignatureState.DOCUMENT_CREATED);
} else {
documentId = signatures.getStaffDocumentId();
}
if (signatures.getStaffDocumentState() == ApplicationSignatureState.DOCUMENT_CREATED) {
byte[] pdf = onnistuuClient.generateStaffSignatureDocument(requestContext, applicantName, line, staffMember);
onnistuuClient.addPdf(documentId, pdf);
signatures = applicationSignaturesDAO.updateStaffDocument(signatures, documentId, null, null, ApplicationSignatureState.PDF_UPLOADED);
}
if (signatures.getStaffDocumentState() == ApplicationSignatureState.PDF_UPLOADED) {
OnnistuuClient.Invitation invitation = onnistuuClient.createInvitation(documentId, staffMember.getPrimaryEmail().getAddress());
signatures = applicationSignaturesDAO.updateStaffDocument(signatures, documentId, invitation.getUuid(), invitation.getPassphrase(), ApplicationSignatureState.INVITATION_CREATED);
}
// Respond with URL to view the PDF
requestContext.addResponseParameter("status", "OK");
requestContext.addResponseParameter("documentUrl", String.format("https://www.onnistuu.fi/api/v1/invitation/%s/%s/files/0", signatures.getStaffInvitationId(), signatures.getStaffInvitationToken()));
} catch (OnnistuuClientException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
fail(requestContext, e.getMessage());
}
}
use of fi.otavanopisto.pyramus.dao.application.ApplicationSignaturesDAO in project pyramus by otavanopisto.
the class GetDocumentUrlsJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
Long id = requestContext.getLong("id");
if (id != null) {
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findById(id);
if (application != null) {
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
if (applicationSignatures != null) {
if (StringUtils.isNotBlank(applicationSignatures.getStaffInvitationId())) {
String staffDocumentUrl = String.format("https://www.onnistuu.fi/api/v1/invitation/%s/%s/files/0", applicationSignatures.getStaffInvitationId(), applicationSignatures.getStaffInvitationToken());
requestContext.addResponseParameter("staffDocumentUrl", staffDocumentUrl);
}
if (StringUtils.isNotBlank(applicationSignatures.getApplicantInvitationId())) {
String applicantDocumentUrl = String.format("https://www.onnistuu.fi/api/v1/invitation/%s/%s/files/0", applicationSignatures.getApplicantInvitationId(), applicationSignatures.getApplicantInvitationToken());
requestContext.addResponseParameter("applicantDocumentUrl", applicantDocumentUrl);
}
}
}
}
}
use of fi.otavanopisto.pyramus.dao.application.ApplicationSignaturesDAO in project pyramus by otavanopisto.
the class UpdateApplicationStateJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
try {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember staffMember = requestContext.getLoggedUserId() == null ? null : staffMemberDAO.findById(requestContext.getLoggedUserId());
if (staffMember == null) {
fail(requestContext, "Et ole kirjautunut sisään");
return;
}
Long id = requestContext.getLong("id");
if (id == null) {
fail(requestContext, "Puuttuva hakemustunnus");
return;
}
ApplicationState applicationState = ApplicationState.valueOf(requestContext.getString("state"));
Boolean lockApplication = requestContext.getBoolean("lockApplication");
Boolean setHandler = requestContext.getBoolean("setHandler");
Boolean removeHandler = requestContext.getBoolean("removeHandler");
// Application update
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findById(id);
if (application == null) {
fail(requestContext, "Puuttuva hakemus");
return;
}
if (application.getState() != applicationState) {
if (applicationState == ApplicationState.APPROVED_BY_SCHOOL) {
// Gather required dynamic data from the application form
JSONObject formData = JSONObject.fromObject(application.getFormData());
String line = ApplicationUtils.applicationLineUiValue(application.getLine());
String applicantName = String.format("%s %s", getFormValue(formData, "field-first-names"), getFormValue(formData, "field-last-name"));
String ssn = ApplicationUtils.constructSSN(getFormValue(formData, "field-birthday"), getFormValue(formData, "field-ssn-end"));
String address = String.format("%s, %s %s, %s", getFormValue(formData, "field-street-address"), getFormValue(formData, "field-zip-code"), getFormValue(formData, "field-city"), getFormValue(formData, "field-country"));
String municipality = ApplicationUtils.municipalityUiValue(getFormValue(formData, "field-municipality"));
String nationality = ApplicationUtils.nationalityUiValue(getFormValue(formData, "field-nationality"));
String phone = getFormValue(formData, "field-phone");
String email = StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-email")));
String nickname = getFormValue(formData, "field-nickname");
String guardianMail = getFormValue(formData, "field-underage-email");
// Make sure we have application signatures and school approval
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
if (applicationSignatures == null || applicationSignatures.getStaffDocumentState() != ApplicationSignatureState.SIGNED) {
logger.log(Level.WARNING, String.format("Application %s not signed by staff", application.getApplicationId()));
fail(requestContext, "Oppilaitos ei ole vielä allekirjoittanut hyväksymisasiakirjaa");
return;
}
OnnistuuClient onnistuuClient = OnnistuuClient.getInstance();
// Create Onnistuu document (if not done before)
String documentId = null;
if (applicationSignatures.getApplicantDocumentId() == null) {
documentId = onnistuuClient.createDocument(String.format("Vastaanotto: %s", applicantName));
applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, null, null, ApplicationSignatureState.DOCUMENT_CREATED);
} else {
documentId = applicationSignatures.getApplicantDocumentId();
}
if (applicationSignatures.getApplicantDocumentState() == ApplicationSignatureState.DOCUMENT_CREATED) {
byte[] pdf = onnistuuClient.generateApplicantSignatureDocument(requestContext, line, applicantName, ssn, address, municipality, nationality, phone, email);
onnistuuClient.addPdf(documentId, pdf);
applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, null, null, ApplicationSignatureState.PDF_UPLOADED);
}
if (applicationSignatures.getApplicantDocumentState() == ApplicationSignatureState.PDF_UPLOADED) {
OnnistuuClient.Invitation invitation = onnistuuClient.createInvitation(documentId, email);
applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, invitation.getUuid(), invitation.getPassphrase(), ApplicationSignatureState.INVITATION_CREATED);
}
// Construct accepted mail template
String staffDocUrl = String.format("https://www.onnistuu.fi/api/v1/invitation/%s/%s/files/0", applicationSignatures.getStaffInvitationId(), applicationSignatures.getStaffInvitationToken());
StringBuilder signUpUrl = new StringBuilder();
signUpUrl.append(requestContext.getRequest().getScheme());
signUpUrl.append("://");
signUpUrl.append(requestContext.getRequest().getServerName());
signUpUrl.append(":");
signUpUrl.append(requestContext.getRequest().getServerPort());
signUpUrl.append("/applications/accept.page?application=");
signUpUrl.append(application.getApplicationId());
String lineOrganization = ApplicationUtils.isOtaviaLine(application.getLine()) ? "Otavian" : "Otavan Opiston";
String signerOrganization = ApplicationUtils.isOtaviaLine(application.getLine()) ? "Otavia" : "Otavan Opisto";
String subject = String.format("Hyväksyminen %s opiskelijaksi", lineOrganization);
String content = IOUtils.toString(requestContext.getServletContext().getResourceAsStream("/templates/applications/mails/mail-accept-study-place.html"), "UTF-8");
content = String.format(content, nickname, lineOrganization, line.toLowerCase(), staffDocUrl, staffDocUrl, signUpUrl.toString(), signUpUrl.toString(), staffMember.getFullName(), signerOrganization);
if (StringUtils.isBlank(guardianMail)) {
Mailer.sendMail(Mailer.JNDI_APPLICATION, Mailer.HTML, null, email, subject, content);
} else {
Mailer.sendMail(Mailer.JNDI_APPLICATION, Mailer.HTML, null, email, guardianMail, subject, content);
}
// Add notification about sent mail
ApplicationLogDAO applicationLogDAO = DAOFactory.getInstance().getApplicationLogDAO();
applicationLogDAO.create(application, ApplicationLogType.HTML, String.format("<p>%s</p><p><b>%s</b></p>%s", "Hakijalle lähetetty ilmoitus opiskelijaksi hyväksymisestä", subject, content), staffMember);
} else // end of application has been approved logic
if (applicationState == ApplicationState.TRANSFERRED_AS_STUDENT) {
// Separate logic for transferring the applicant as student
// throws exception if multiple persons or is staff
Student student = ApplicationUtils.createPyramusStudent(application, staffMember);
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
personDAO.updateDefaultUser(student.getPerson(), student);
String credentialToken = RandomStringUtils.randomAlphanumeric(32).toLowerCase();
application = applicationDAO.updateApplicationStudentAndCredentialToken(application, student, credentialToken);
ApplicationUtils.mailCredentialsInfo(requestContext.getRequest(), student, application);
} else if (applicationState == ApplicationState.REJECTED) {
if (application.getState() == ApplicationState.REGISTERED_AS_STUDENT) {
Student student = application.getStudent();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
studentDAO.archive(student);
}
// #4226: Applications of rejected Internetix students are removed immediately
if (StringUtils.equals("aineopiskelu", application.getLine())) {
ApplicationUtils.deleteApplication(application);
requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "/applications/browse.page");
return;
}
} else if (applicationState == ApplicationState.PROCESSING) {
// #1216: If a signed application is returned to Processing state, remove the
// previous signatures so that the proper processing order can once again be followed
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
if (applicationSignatures != null) {
applicationSignaturesDAO.delete(applicationSignatures);
}
}
// Update the actual application state
application = applicationDAO.updateApplicationState(application, applicationState, staffMember);
if (Boolean.TRUE.equals(lockApplication) && application.getApplicantEditable()) {
application = applicationDAO.updateApplicantEditable(application, Boolean.FALSE, staffMember);
}
if (Boolean.TRUE.equals(setHandler)) {
application = applicationDAO.updateApplicationHandler(application, staffMember);
}
if (Boolean.TRUE.equals(removeHandler)) {
application = applicationDAO.updateApplicationHandler(application, null);
}
// Email notifications and log entries related to state change
ApplicationUtils.sendNotifications(application, requestContext.getRequest(), staffMember, false, null, true);
}
// Response parameters
requestContext.addResponseParameter("status", "OK");
requestContext.addResponseParameter("id", application.getId());
requestContext.addResponseParameter("state", application.getState());
requestContext.addResponseParameter("stateUi", ApplicationUtils.applicationStateUiValue(application.getState()));
requestContext.addResponseParameter("applicantEditable", application.getApplicantEditable());
requestContext.addResponseParameter("handler", application.getHandler() == null ? null : application.getHandler().getFullName());
requestContext.addResponseParameter("handlerId", application.getHandler() == null ? null : application.getHandler().getId());
requestContext.addResponseParameter("lastModified", application.getLastModified().getTime());
} catch (Exception e) {
requestContext.addResponseParameter("status", "FAIL");
requestContext.addResponseParameter("reason", e.getMessage());
logger.log(Level.SEVERE, "Error updating application state", e);
}
}
use of fi.otavanopisto.pyramus.dao.application.ApplicationSignaturesDAO in project pyramus by otavanopisto.
the class SignStudentDocumentJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
// Validate request parameters
String applicationId = requestContext.getString("id");
if (StringUtils.isBlank(applicationId)) {
logger.warning("Missing application id");
fail(requestContext, "Puuttuva hakemustunnus");
return;
}
String ssn = requestContext.getString("ssn");
if (StringUtils.isBlank(ssn)) {
logger.warning("Missing social security number");
fail(requestContext, "Puuttuva henkilötunnus");
return;
}
String authService = requestContext.getString("authService");
if (StringUtils.isBlank(authService)) {
logger.warning("Missing authService");
fail(requestContext, "Puuttuva tunnistustapa");
return;
}
// Ensure application state
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findByApplicationIdAndArchived(applicationId, Boolean.FALSE);
if (application == null) {
logger.warning(String.format("Application with id %s not found", applicationId));
fail(requestContext, String.format("Hakemusta tunnuksella %s ei löytynyt", applicationId));
return;
}
if (application.getState() != ApplicationState.APPROVED_BY_SCHOOL) {
logger.warning(String.format("Application with id %s in incorrect state (%s)", applicationId, application.getState()));
fail(requestContext, "Hakemus ei ole allekirjoitettavassa tilassa");
return;
}
if (!StringUtils.equals(ssn, ApplicationUtils.extractSSN(application))) {
logger.warning("Social security number mismatch");
fail(requestContext, "Virheellinen henkilötunnus");
return;
}
// Signatures tracking
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures signatures = applicationSignaturesDAO.findByApplication(application);
if (signatures == null || signatures.getApplicantDocumentState() != ApplicationSignatureState.INVITATION_CREATED) {
fail(requestContext, "Opiskelupaikan vastaanottoasiakirja ei ole allekirjoitettavassa tilassa");
return;
}
// Return URL after signing
StringBuilder returnUrl = new StringBuilder();
returnUrl.append(requestContext.getRequest().getScheme());
returnUrl.append("://");
returnUrl.append(requestContext.getRequest().getServerName());
returnUrl.append(":");
returnUrl.append(requestContext.getRequest().getServerPort());
returnUrl.append("/applications/done.page?invitationId=");
returnUrl.append(signatures.getApplicantInvitationId());
// Signing
OnnistuuClient onnistuuClient = OnnistuuClient.getInstance();
try {
String completionUrl = onnistuuClient.getSignatureUrl(signatures.getApplicantInvitationId(), returnUrl.toString(), ssn, authService);
// Respond with URL to complete the signature
requestContext.addResponseParameter("status", "OK");
requestContext.addResponseParameter("completionUrl", completionUrl);
} catch (OnnistuuClientException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
fail(requestContext, e.getMessage());
}
}
use of fi.otavanopisto.pyramus.dao.application.ApplicationSignaturesDAO in project pyramus by otavanopisto.
the class ViewApplicationViewController method process.
public void process(PageRequestContext pageRequestContext) {
try {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember staffMember = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
Long applicationId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("application"));
if (applicationId == null) {
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findById(applicationId);
if (application == null) {
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures signatures = applicationSignaturesDAO.findByApplication(application);
JSONObject formData = JSONObject.fromObject(application.getFormData());
Map<String, Map<String, String>> sections = new LinkedHashMap<>();
// Perustiedot
Map<String, String> fields = new LinkedHashMap<>();
sections.put("Perustiedot", fields);
fields.put("Muokkaustunnus", application.getReferenceCode());
String applicationLine = getFormValue(formData, "field-line");
fields.put("Linja", ApplicationUtils.applicationLineUiValue(applicationLine));
if (StringUtils.equals("nettilukio", applicationLine) || StringUtils.equals("nettipk", applicationLine)) {
AlternativeLine altLine = EnumUtils.getEnum(AlternativeLine.class, getFormValue(formData, "field-nettilukio_alternativelines"));
fields.put("Yksityisopiskelu", AlternativeLine.PRIVATE == altLine ? "Kyllä" : "Ei");
fields.put("Aineopiskelu/yo-tutkinto", AlternativeLine.YO == altLine ? "Kyllä" : "Ei");
String compulsoryStudies = getFormValue(formData, "field-nettilukio_compulsory");
fields.put("Maksuton oppivelvollisuus", StringUtils.equals(compulsoryStudies, "compulsory") ? "Maksuttoman oppivelvollisuuden piirissä" : StringUtils.equals(compulsoryStudies, "non_compulsory") ? "Ei maksuttoman oppivelvollisuuden piirissä" : "Ei koske opiskelijaa");
if (StringUtils.equals(compulsoryStudies, "compulsory")) {
String compulsoryEndDateStr = getFormValue(formData, "field-nettilukio_compulsory_enddate");
if (StringUtils.isNotBlank(compulsoryEndDateStr)) {
fields.put("Maksuton oppivelvollisuus päättynyt alkaen", compulsoryEndDateStr);
}
}
}
fields.put("Nimi", String.format("%s, %s", getFormValue(formData, "field-last-name"), getFormValue(formData, "field-first-names")));
if (StringUtils.isNotBlank(getFormValue(formData, "field-nickname"))) {
fields.put("Kutsumanimi", getFormValue(formData, "field-nickname"));
}
fields.put("Syntymäaika", getFormValue(formData, "field-birthday"));
if (StringUtils.isNotBlank(getFormValue(formData, "field-ssn-end"))) {
fields.put("Henkilötunnuksen loppuosa", StringUtils.upperCase(getFormValue(formData, "field-ssn-end")));
}
fields.put("Sukupuoli", ApplicationUtils.genderUiValue(getFormValue(formData, "field-sex")));
fields.put("Osoite", String.format("%s\n%s %s\n%s", getFormValue(formData, "field-street-address"), getFormValue(formData, "field-zip-code"), getFormValue(formData, "field-city"), getFormValue(formData, "field-country")));
fields.put("Kotikunta", ApplicationUtils.municipalityUiValue(getFormValue(formData, "field-municipality")));
fields.put("Kansallisuus", ApplicationUtils.nationalityUiValue(getFormValue(formData, "field-nationality")));
fields.put("Äidinkieli", ApplicationUtils.languageUiValue(getFormValue(formData, "field-language")));
fields.put("Puhelinnumero", getFormValue(formData, "field-phone"));
fields.put("Sähköposti", StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-email"))));
if (StringUtils.isNotBlank(getFormValue(formData, "field-underage-first-name"))) {
fields = new LinkedHashMap<>();
sections.put("Alaikäisen hakemustiedot", fields);
if (StringUtils.isNotBlank(getFormValue(formData, "field-underage-grounds"))) {
fields.put("Hakemusperusteet", getFormValue(formData, "field-underage-grounds"));
}
fields.put("Huoltajan yhteystiedot", String.format("%s %s\n%s\n%s %s\n%s\n%s\n%s", getFormValue(formData, "field-underage-first-name"), getFormValue(formData, "field-underage-last-name"), getFormValue(formData, "field-underage-street-address"), getFormValue(formData, "field-underage-zip-code"), getFormValue(formData, "field-underage-city"), getFormValue(formData, "field-underage-country"), "Puh: " + getFormValue(formData, "field-underage-phone"), "Sähköposti: " + StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-underage-email")))));
}
if (StringUtils.equals(getFormValue(formData, "field-line"), "aineopiskelu")) {
fields = new LinkedHashMap<>();
sections.put("Aineopiskelijan oppilaitos", fields);
fields.put("Opiskelee muualla", StringUtils.equals(getFormValue(formData, "field-internetix-school"), "kylla") ? "Kyllä" : "Ei");
if (StringUtils.equals(getFormValue(formData, "field-internetix-school"), "kylla")) {
School school = ApplicationUtils.resolveSchool(getFormValue(formData, "field-internetix-contract-school"));
if (school == null) {
fields.put("Oppilaitos", getFormValue(formData, "field-internetix-contract-school-name"));
fields.put("Sopimusoppilaitos", "Ei");
fields.put("Opiskelupaikkakunta", getFormValue(formData, "field-internetix-contract-school-municipality"));
fields.put("Oppilaitoksen yhteyshenkilö", getFormValue(formData, "field-internetix-contract-school-contact"));
StudentExaminationType examinationType = ApplicationUtils.resolveStudentExaminationType(getFormValue(formData, "field-internetix-contract-school-degree"));
if (examinationType != null) {
fields.put("Tutkintotyyppi", examinationType.getName());
}
} else {
fields.put("Oppilaitos", school.getName());
fields.put("Sopimusoppilaitos", "Kyllä");
}
}
}
// Hakemiseen vaadittavat lisätiedot
fields = new LinkedHashMap<>();
sections.put("Hakemiseen vaadittavat lisätiedot", fields);
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-studies-aineopiskelu"))) {
fields.put("Yleissivistävä koulutustausta", ApplicationUtils.previousStudiesInternetixUiValue(getFormValue(formData, "field-previous-studies-aineopiskelu")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-studies"))) {
fields.put("Aiemmat opinnot", getFormValue(formData, "field-previous-studies"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-studies-nettilukio"))) {
fields.put("Aiemmat opinnot", ApplicationUtils.previousStudiesUiValue(getFormValue(formData, "field-previous-studies-nettilukio")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-studies-nettilukio-school"))) {
fields.put("Aiempi oppilaitos", getFormValue(formData, "field-previous-studies-nettilukio-school"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-studies-nettilukio-duration"))) {
fields.put("Aiempien opintojen kesto", getFormValue(formData, "field-previous-studies-nettilukio-duration"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-studies-nettilukio-other"))) {
fields.put("Kerro tarkemmin", getFormValue(formData, "field-previous-studies-nettilukio-other"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-matriculation-exams-nettilukio"))) {
fields.put("Oletko suorittanut aiemmin yo-kokeita?", simpleBooleanUiValue(getFormValue(formData, "field-previous-matriculation-exams-nettilukio")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-matriculation-exams-nettilukio-when"))) {
fields.put("Milloin olet viimeksi osallistunut yo-kokeisiin?", getFormValue(formData, "field-previous-matriculation-exams-nettilukio-when"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-other-school"))) {
fields.put("Opiskelee toisessa oppilaitoksessa", simpleBooleanUiValue(getFormValue(formData, "field-other-school")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-other-school-name"))) {
fields.put("Nykyinen oppilaitos", getFormValue(formData, "field-other-school-name"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-goals"))) {
fields.put("Opiskelutavoitteet", goalsUiValue(getFormValue(formData, "field-goals")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-foreign-student"))) {
fields.put("Ulkomainen vaihto-opiskelija", simpleBooleanUiValue(getFormValue(formData, "field-foreign-student")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-previous-foreign-studies"))) {
fields.put("Aiemmat opinnot kotimaassa ja Suomessa", getFormValue(formData, "field-previous-foreign-studies"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-job"))) {
if ("muu".equals(getFormValue(formData, "field-job"))) {
fields.put("Asema", getFormValue(formData, "field-job-other"));
} else {
fields.put("Asema", jobUiValue(getFormValue(formData, "field-job")));
}
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-foreign-line"))) {
fields.put("Opintojen tyyppi", foreignLineUiValue(getFormValue(formData, "field-foreign-line")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-residence-permit"))) {
fields.put("Oleskelulupa Suomeen", simpleBooleanUiValue(getFormValue(formData, "field-residence-permit")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-info"))) {
fields.put("Vapaamuotoinen esittely", getFormValue(formData, "field-info"));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-lodging"))) {
fields.put("Asunto kampukselta", simpleBooleanUiValue(getFormValue(formData, "field-lodging")));
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-lodging-partial"))) {
fields.put("Asunto kampukselta lähijaksojen ajaksi", simpleBooleanUiValue(getFormValue(formData, "field-lodging-partial")));
}
// Hakulähde
StringBuffer sb = new StringBuffer();
if (formData.has("field-source")) {
String source = getFormValue(formData, "field-source");
if (!StringUtils.startsWith(source, "[")) {
source = String.format("[\"%s\"]", source);
}
JSONArray sourcesArray = JSONArray.fromObject(source);
for (int i = 0; i < sourcesArray.size(); i++) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(ApplicationUtils.sourceUiValue(sourcesArray.getString(i)));
}
}
if (StringUtils.isNotBlank(getFormValue(formData, "field-source-other"))) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(getFormValue(formData, "field-source-other"));
}
if (sb.length() > 0) {
fields.put("Mistä sai tiedon koulutuksesta", sb.toString());
}
// Hakemuksen tilatiedot
pageRequestContext.getRequest().setAttribute("infoState", application.getState());
pageRequestContext.getRequest().setAttribute("infoStateUi", ApplicationUtils.applicationStateUiValue(application.getState()));
pageRequestContext.getRequest().setAttribute("infoApplicantEditable", application.getApplicantEditable());
if (application.getHandler() != null) {
pageRequestContext.getRequest().setAttribute("infoHandler", application.getHandler().getFullName());
pageRequestContext.getRequest().setAttribute("infoHandlerId", application.getHandler().getId());
}
if (application.getStudent() != null) {
pageRequestContext.getRequest().setAttribute("infoStudentUrl", String.format("/students/viewstudent.page?person=%d#at-student.%d", application.getStudent().getPerson().getId(), application.getStudent().getId()));
}
pageRequestContext.getRequest().setAttribute("infoCreated", application.getCreated());
pageRequestContext.getRequest().setAttribute("infoLastModified", ApplicationUtils.getLatest(application.getLastModified(), application.getApplicantLastModified(), application.getCreated()));
pageRequestContext.getRequest().setAttribute("infoSignatures", signatures);
pageRequestContext.getRequest().setAttribute("infoSsn", staffMember == null ? null : staffMember.getPerson().getSocialSecurityNumber());
pageRequestContext.getRequest().setAttribute("mode", "view");
pageRequestContext.getRequest().setAttribute("applicationEntityId", application.getId());
pageRequestContext.getRequest().setAttribute("applicationId", application.getApplicationId());
pageRequestContext.getRequest().setAttribute("applicationLine", application.getLine());
pageRequestContext.getRequest().setAttribute("sections", sections);
pageRequestContext.setIncludeJSP("/templates/applications/management-view-application.jsp");
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to serve error response", e);
return;
}
}
Aggregations