コード例 #1
0
  public ActionForward prepareEditObject(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixServiceException, ClassNotFoundException {

    Person person = checkUser();

    String documentIdNumber = person.getDocumentIdNumber();
    DynaActionForm actionForm = (DynaActionForm) form;
    Integer idPos1Index = (Integer) actionForm.get("idPos1Index");
    Integer idPos2Index = (Integer) actionForm.get("idPos2Index");
    Integer idPos3Index = (Integer) actionForm.get("idPos3Index");
    Character idPos1Value = (Character) actionForm.get("idPos1Value");
    Character idPos2Value = (Character) actionForm.get("idPos2Value");
    Character idPos3Value = (Character) actionForm.get("idPos3Value");

    if (documentIdNumber.charAt(idPos1Index - 1) == idPos1Value.charValue()
        && documentIdNumber.charAt(idPos2Index - 1) == idPos2Value.charValue()
        && documentIdNumber.charAt(idPos3Index - 1) == idPos3Value.charValue()) {

      DomainObject object = getDomainObject(actionForm, "classToManageId");

      if (object != null) {
        request.setAttribute("objectToEdit", object);
      }
    } else {
      request.setAttribute("message", "Who the hell are you!?!?!");
    }
    return mapping.findForward("prepareEditObject");
  }
コード例 #2
0
    public ByteArrayOutputStream getFilledPdf(Person person) throws IOException, DocumentException {
      InputStream istream = getClass().getResourceAsStream(BPI_AEIST_CARD_PDF_PATH);
      PdfReader reader = new PdfReader(istream);
      reader.getAcroForm().remove(PdfName.SIGFLAGS);
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      PdfStamper stamper = new PdfStamper(reader, output);
      form = stamper.getAcroFields();

      setField("BI/CC", person.getDocumentIdNumber());
      setField("Nome", person.getName());
      setField(
          "topmostSubform[0].Page1[0].Datavalidade[0]",
          person
              .getExpirationDateOfDocumentIdYearMonthDay()
              .toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      setField(
          "dia",
          String.valueOf(person.getExpirationDateOfDocumentIdYearMonthDay().getDayOfMonth()));
      setField(
          "Mês",
          String.valueOf(person.getExpirationDateOfDocumentIdYearMonthDay().getMonthOfYear()));
      setField("Ano", String.valueOf(person.getExpirationDateOfDocumentIdYearMonthDay().getYear()));

      LocalDate today = new LocalDate();
      setField("dia_1", String.valueOf(today.getDayOfMonth()));
      setField("Mês_1", String.valueOf(today.getMonthOfYear()));
      setField("Ano_1", String.valueOf(today.getYear()));

      stamper.setFormFlattening(true);
      stamper.close();
      return output;
    }
コード例 #3
0
    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;
    }
コード例 #4
0
  public ActionForward deleteObject(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixServiceException, ClassNotFoundException {

    Person person = checkUser();

    String documentIdNumber = person.getDocumentIdNumber();

    DynaActionForm actionForm = (DynaActionForm) form;
    Integer idPos1Index = (Integer) actionForm.get("idPos1Index");
    Integer idPos2Index = (Integer) actionForm.get("idPos2Index");
    Integer idPos3Index = (Integer) actionForm.get("idPos3Index");
    Character idPos1Value = (Character) actionForm.get("idPos1Value");
    Character idPos2Value = (Character) actionForm.get("idPos2Value");
    Character idPos3Value = (Character) actionForm.get("idPos3Value");

    if (documentIdNumber.charAt(idPos1Index - 1) == idPos1Value.charValue()
        && documentIdNumber.charAt(idPos2Index - 1) == idPos2Value.charValue()
        && documentIdNumber.charAt(idPos3Index - 1) == idPos3Value.charValue()) {

      String classToDelete = (String) actionForm.get("classToManage");
      String classToDeleteId = (String) actionForm.get("classToManageId");

      try {
        DeleteObjectByOID.run(classToDeleteId);
        request.setAttribute(
            "message",
            "Object "
                + classToDelete
                + " with ID:"
                + classToDeleteId
                + " Deleted. God have mercy of your soul...");

      } catch (Exception e) {
        logger.error(e.getMessage(), e);
        request.setAttribute(
            "message", "Error deleting Object " + classToDelete + " with ID:" + classToDeleteId);
      }

    } else {
      request.setAttribute("message", "Who the hell are you!?!?!");
    }

    request.setAttribute("domainClasses", getClasses());
    ((DynaActionForm) form).set("method", "prepareEditObject");
    return mapping.findForward("chooseClassToManage");
  }
コード例 #5
0
  private void generateIdIndexesToAnswer(ActionForm form, Person person) {
    int documentIdLength = person.getDocumentIdNumber().length();
    Integer pos1 = null;
    Integer pos2 = null;
    Integer pos3 = null;

    pos1 = (int) Math.round(Math.random() * (documentIdLength - 1)) + 1;

    do {
      pos2 = (int) Math.round(Math.random() * (documentIdLength - 1)) + 1;
    } while (pos1 == pos2);

    do {
      pos3 = (int) Math.round(Math.random() * (documentIdLength - 1)) + 1;
    } while (pos3 == pos2 && pos3 == pos1);

    DynaActionForm actionForm = (DynaActionForm) form;
    actionForm.set("idPos1Index", pos1);
    actionForm.set("idPos2Index", pos2);
    actionForm.set("idPos3Index", pos3);
  }
コード例 #6
0
    public ByteArrayOutputStream getFilledPdf(Person person) throws IOException, DocumentException {
      InputStream istream = getClass().getResourceAsStream(SANTANDER_APPLICATION_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("topmostSubform[0].Page1[0].Nomecompleto[0]", person.getName());
      String documentIdNumber = person.getDocumentIdNumber();
      if (person.getIdDocumentType().equals(IDDocumentType.CITIZEN_CARD)
          || person.getIdDocumentType().equals(IDDocumentType.IDENTITY_CARD)) {
        setField("topmostSubform[0].Page1[0].NumBICartaoCidadaooutro[0]", documentIdNumber);
        setField(
            "topmostSubform[0].Page1[0].Checkdigit[0]",
            person.getIdentificationDocumentSeriesNumberValue());
      } else {
        setField("topmostSubform[0].Page1[0].Outrotipodocidentificacao[0]", documentIdNumber);
      }

      YearMonthDay emissionDate = person.getEmissionDateOfDocumentIdYearMonthDay();
      if (emissionDate != null) {
        setField(
            "topmostSubform[0].Page1[0].Dataemissao[0]",
            emissionDate.toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      }
      setField(
          "topmostSubform[0].Page1[0].Datavalidade[0]",
          person
              .getExpirationDateOfDocumentIdYearMonthDay()
              .toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      setField("topmostSubform[0].Page1[0].NIF[0]", person.getSocialSecurityNumber());
      setField(
          "topmostSubform[0].Page1[0].Nacionalidade[0]",
          person.getCountryOfBirth().getCountryNationality().toString());
      setField(
          "topmostSubform[0].Page1[0].Datanascimento[0]",
          person.getDateOfBirthYearMonthDay().toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      YearMonthDay dateOfBirthYearMonthDay = person.getDateOfBirthYearMonthDay();
      Period periodBetween = new Period(dateOfBirthYearMonthDay, new YearMonthDay());
      setField(
          "topmostSubform[0].Page1[0].Idadeactual[0]",
          String.valueOf(periodBetween.get(DurationFieldType.years())));
      if (person.isFemale()) {
        setField("topmostSubform[0].Page1[0].Sexo[0]", "F"); // female
      } else if (person.isMale()) {
        setField("topmostSubform[0].Page1[0].Sexo[0]", "M"); // male
      }

      switch (person.getMaritalStatus()) {
        case CIVIL_UNION:
          setField("topmostSubform[0].Page1[0].Uniaofacto[0]", "1");
          break;
        case DIVORCED:
          setField("topmostSubform[0].Page1[0].Divorciado[0]", "1");
          break;
        case MARRIED:
          setField("topmostSubform[0].Page1[0].Casado[0]", "1");
          break;
        case SEPARATED:
          setField("topmostSubform[0].Page1[0].Separado[0]", "1");
          break;
        case SINGLE:
          setField("topmostSubform[0].Page1[0].Solteiro[0]", "1");
          break;
        case WIDOWER:
          setField("topmostSubform[0].Page1[0].Viuvo[0]", "1");
          break;
      }
      setField("topmostSubform[0].Page1[0].Telemovel[0]", person.getDefaultMobilePhoneNumber());
      setField("topmostSubform[0].Page1[0].E-mail[0]", getMail(person));
      setField("topmostSubform[0].Page1[0].Moradaprincipal[0]", person.getAddress());
      setField("topmostSubform[0].Page1[0].localidade[0]", person.getAreaOfAreaCode());
      String postalCode = person.getPostalCode();
      int dashIndex = postalCode.indexOf('-');
      setField("topmostSubform[0].Page1[0].CodPostal[0]", postalCode.substring(0, 4));
      String last3Numbers = person.getPostalCode().substring(dashIndex + 1, dashIndex + 4);
      setField("topmostSubform[0].Page1[0].ExtensaoCodPostal[0]", last3Numbers);

      setField(
          "topmostSubform[0].Page1[0].Nacionalidade[0]",
          person.getCountryOfBirth().getCountryNationality().toString());
      setField(
          "topmostSubform[0].Page1[0].Nacionalidade[0]",
          person.getCountryOfBirth().getCountryNationality().toString());

      stamper.setFormFlattening(true);
      stamper.close();
      return output;
    }
コード例 #7
0
  @SuppressWarnings("unchecked")
  private ByteArrayOutputStream createAcademicAdminProcessSheet(Person person) throws JRException {
    InputStream istream = getClass().getResourceAsStream(ACADEMIC_ADMIN_SHEET_REPORT_PATH);
    JasperReport report = (JasperReport) JRLoader.loadObject(istream);

    @SuppressWarnings("rawtypes")
    HashMap map = new HashMap();

    try {
      final Student student = person.getStudent();
      final Registration registration = findRegistration(student);

      map.put("executionYear", ExecutionYear.readCurrentExecutionYear().getYear());
      if (registration != null) {
        map.put("course", registration.getDegree().getNameI18N().toString());
      }
      map.put("studentNumber", student.getNumber().toString());
      map.put("fullName", person.getName());

      try {
        map.put(
            "photo",
            new ByteArrayInputStream(person.getPersonalPhotoEvenIfPending().getDefaultAvatar()));
      } catch (Exception e) {
        // nothing; print everything else
      }

      map.put(
          "sex",
          BundleUtil.getStringFromResourceBundle(
              "resources/EnumerationResources", person.getGender().name()));
      map.put("maritalStatus", person.getMaritalStatus().getPresentationName());
      map.put("profession", person.getProfession());
      map.put("idDocType", person.getIdDocumentType().getLocalizedName());
      map.put("idDocNumber", person.getDocumentIdNumber());

      YearMonthDay emissionDate = person.getEmissionDateOfDocumentIdYearMonthDay();
      if (emissionDate != null) {
        map.put(
            "idDocEmissionDate", emissionDate.toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      }

      map.put(
          "idDocExpirationDate",
          person
              .getExpirationDateOfDocumentIdYearMonthDay()
              .toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      map.put("idDocEmissionLocation", person.getEmissionLocationOfDocumentId());

      String nif = person.getSocialSecurityNumber();
      if (nif != null) {
        map.put("NIF", nif);
      }

      map.put(
          "birthDate",
          person.getDateOfBirthYearMonthDay().toString(DateTimeFormat.forPattern("dd/MM/yyyy")));
      map.put("nationality", person.getCountryOfBirth().getCountryNationality().toString());
      map.put("parishOfBirth", person.getParishOfBirth());
      map.put("districtSubdivisionOfBirth", person.getDistrictSubdivisionOfBirth());
      map.put("districtOfBirth", person.getDistrictOfBirth());
      map.put("countryOfBirth", person.getCountryOfBirth().getName());
      map.put("fathersName", person.getNameOfFather());
      map.put("mothersName", person.getNameOfMother());
      map.put("address", person.getAddress());
      map.put("postalCode", person.getPostalCode());
      map.put("locality", person.getAreaOfAreaCode());
      map.put("cellphoneNumber", person.getDefaultMobilePhoneNumber());
      map.put("telephoneNumber", person.getDefaultPhoneNumber());
      map.put("emailAddress", getMail(person));
      map.put(
          "currentDate",
          new java.text.SimpleDateFormat(
                  "'Lisboa, 'dd' de 'MMMM' de 'yyyy", new java.util.Locale("PT", "pt"))
              .format(new java.util.Date()));
    } catch (NullPointerException e) {
      // nothing; will cause printing of incomplete form
      // better than no form at all
    }

    JasperPrint print = JasperFillManager.fillReport(report, map);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    JasperExportManager.exportReportToPdfStream(print, output);
    return output;
  }
コード例 #8
0
 private static String buildFilename(Person person, Integer year) {
   return String.format(
       "IRS-%s-%s-%s.pdf",
       year, person.getDocumentIdNumber(), new LocalDate().toString("yyyyMMdd"));
 }
コード例 #9
0
  private static void drawPersonalInformation(
      final Page page, final PhdProgramPublicCandidacyHashCode hashCode, final String folderName)
      throws IOException {

    final Person person = hashCode.getPerson();

    page.h(3, "Personal Information", "mtop2");
    page.tableStart("tstyle2 thwhite thnowrap thlight thleft thtop ulnomargin ");

    page.rowStart("tdbold")
        .headerStartWithStyle("width: 125px;")
        .write("Name:")
        .headerEnd()
        .column(person.getName())
        .rowEnd();
    page.rowStart()
        .header("Gender:")
        .column(person.getGender().toLocalizedString(Locale.ENGLISH))
        .rowEnd();
    page.rowStart()
        .header("Identity card type:")
        .column(person.getIdDocumentType().getLocalizedName())
        .rowEnd();
    page.rowStart().header("Identity card #:").column(person.getDocumentIdNumber()).rowEnd();
    page.rowStart().header("Issued by:").column(person.getEmissionLocationOfDocumentId()).rowEnd();
    page.rowStart()
        .header("Fiscal number:")
        .column(string(person.getSocialSecurityNumber()))
        .rowEnd();
    page.rowStart()
        .header("Date of birth:")
        .column(person.getDateOfBirthYearMonthDay().toString("dd/MM/yyyy"))
        .rowEnd();
    page.rowStart().header("Birthplace:").column(person.getDistrictSubdivisionOfBirth()).rowEnd();
    page.rowStart()
        .header("Nationality:")
        .column(person.getCountry().getCountryNationality().getContent())
        .rowEnd();
    page.rowStart().header("Address:").column(person.getAddress()).rowEnd();
    page.rowStart().header("City:").column(person.getArea()).rowEnd();
    page.rowStart().header("Zip code:").column(person.getAreaCode()).rowEnd();
    page.rowStart()
        .header("Country:")
        .column(
            (person.getCountryOfResidence() != null
                ? person.getCountryOfResidence().getName()
                : "-"))
        .rowEnd();
    page.rowStart().header("Phone:").column(person.getDefaultPhoneNumber()).rowEnd();
    page.rowStart().header("Mobile:").column(person.getDefaultMobilePhoneNumber()).rowEnd();
    page.rowStart().header("Email:").column(person.getDefaultEmailAddressValue()).rowEnd();

    page.tableEnd();

    page.h(3, "Photo");
    String photoUrl = APPLICATION_PREFIX_LINK + "/phd/epfl/applications/photo";
    final Photograph photo = person.getPersonalPhotoEvenIfPending();
    if (photo != null) {
      photoUrl += "?photoOid=" + photo.getExternalId();
    }
    page.photo(photoUrl);
  }