public ByteArrayOutputStream getFilledPdf(Person person) throws IOException, DocumentException {
      InputStream istream = getClass().getResourceAsStream(BPI_PERSONAL_INFORMATION_PDF_PATH);
      PdfReader reader = new PdfReader(istream);
      reader.getAcroForm().remove(PdfName.SIGFLAGS);
      reader.selectPages("1,2");
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      PdfStamper stamper = new PdfStamper(reader, output);
      form = stamper.getAcroFields();

      setField("Nome completo_1", person.getName());
      setField("NIF", person.getSocialSecurityNumber());
      setField("Nº", person.getDocumentIdNumber());

      setField("Nacionalidade", person.getCountryOfBirth().getCountryNationality().toString());
      setField("Naturalidade", person.getCountryOfBirth().getName());

      setField("Distrito", person.getDistrictOfBirth());
      setField("Concelho", person.getDistrictSubdivisionOfBirth());
      setField("Freguesia", person.getParishOfBirth());
      setField("Nome do Pai", person.getNameOfFather());
      setField("Nome da Mãe", person.getNameOfMother());
      setField("Morada de Residencia_1", person.getAddress());
      setField("Localidade", person.getAreaOfAreaCode());
      setField("Designação Postal", person.getAreaOfAreaCode());
      setField("País", person.getCountryOfResidence().getName());

      String postalCode = person.getPostalCode();
      int dashIndex = postalCode.indexOf('-');
      setField("Código Postal4", postalCode.substring(0, 4));
      String last3Numbers = postalCode.substring(dashIndex + 1, dashIndex + 4);
      setField("Código Postal_5", last3Numbers);
      setField("Móvel", person.getDefaultMobilePhoneNumber());
      setField("E-mail", getMail(person));

      YearMonthDay emissionDate = person.getEmissionDateOfDocumentIdYearMonthDay();
      if (emissionDate != null) {
        setField("Dia_1", String.valueOf(emissionDate.getDayOfMonth()));
        setField("Mês_1", String.valueOf(emissionDate.getMonthOfYear()));
        setField("Ano_1", String.valueOf(emissionDate.getYear()));
      }

      YearMonthDay expirationDate = person.getExpirationDateOfDocumentIdYearMonthDay();
      setField("Dia_2", String.valueOf(expirationDate.getDayOfMonth()));
      setField("Mês_2", String.valueOf(expirationDate.getMonthOfYear()));
      setField("Ano_2", String.valueOf(expirationDate.getYear()));

      YearMonthDay birthdayDate = person.getDateOfBirthYearMonthDay();
      setField("Dia3", String.valueOf(birthdayDate.getDayOfMonth()));
      setField("Mês3", String.valueOf(birthdayDate.getMonthOfYear()));
      setField("Ano_3", String.valueOf(birthdayDate.getYear()));

      stamper.setFormFlattening(true);
      stamper.close();
      return output;
    }
Exemplo n.º 2
0
 @Deprecated
 public java.util.Date getEnd() {
   org.joda.time.YearMonthDay ymd = getEndYearMonthDay();
   return (ymd == null)
       ? null
       : new java.util.Date(ymd.getYear() - 1900, ymd.getMonthOfYear() - 1, ymd.getDayOfMonth());
 }
  public ActionForward prepareEdit(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixActionException {

    User userView = Authenticate.getUser();
    DynaActionForm dynaForm = (DynaActionForm) form;

    InfoDegreeCurricularPlan oldInfoDegreeCP = null;

    try {
      oldInfoDegreeCP =
          ReadDegreeCurricularPlan.runReadDegreeCurricularPlan(
              request.getParameter("degreeCurricularPlanId"));

    } catch (NonExistingServiceException e) {
      throw new NonExistingActionException(
          "message.nonExistingDegreeCurricularPlan", mapping.findForward("readDegree"));
    } catch (FenixServiceException fenixServiceException) {
      throw new FenixActionException(fenixServiceException.getMessage());
    }

    dynaForm.set("name", oldInfoDegreeCP.getName());
    dynaForm.set("state", oldInfoDegreeCP.getState().toString());

    DegreeCurricularPlan oldDegreeCP = oldInfoDegreeCP.getDegreeCurricularPlan();

    if (oldDegreeCP.getInitialDateYearMonthDay() != null) {
      YearMonthDay ymd = oldDegreeCP.getInitialDateYearMonthDay();
      String initialDateString =
          ymd.getDayOfMonth() + "/" + ymd.getMonthOfYear() + "/" + ymd.getYear();

      dynaForm.set("initialDate", initialDateString);
    }

    if (oldDegreeCP.getEndDateYearMonthDay() != null) {
      YearMonthDay ymd = oldDegreeCP.getEndDateYearMonthDay();
      String endDateString = ymd.getDayOfMonth() + "/" + ymd.getMonthOfYear() + "/" + ymd.getYear();

      dynaForm.set("endDate", endDateString);
    }

    if (oldInfoDegreeCP.getDegreeDuration() != null) {
      dynaForm.set("degreeDuration", oldInfoDegreeCP.getDegreeDuration().toString());
    }
    if (oldInfoDegreeCP.getMinimalYearForOptionalCourses() != null) {
      dynaForm.set(
          "minimalYearForOptionalCourses",
          oldInfoDegreeCP.getMinimalYearForOptionalCourses().toString());
    }

    if (oldInfoDegreeCP.getNeededCredits() != null) {
      dynaForm.set("neededCredits", oldInfoDegreeCP.getNeededCredits().toString());
    }

    dynaForm.set("markType", oldInfoDegreeCP.getMarkType().getType().toString());

    if (oldInfoDegreeCP.getGradeScale() != null) {
      dynaForm.set("gradeType", oldInfoDegreeCP.getGradeScale().toString());
    }

    if (oldInfoDegreeCP.getNumerusClausus() != null) {
      dynaForm.set("numerusClausus", oldInfoDegreeCP.getNumerusClausus().toString());
    }
    dynaForm.set("anotation", oldInfoDegreeCP.getAnotation());

    return mapping.findForward("editDegreeCP");
  }