@Override
  public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
      throws IOException, ServletException {
    arg2.doFilter(arg0, arg1);

    HttpServletRequest request = (HttpServletRequest) arg0;
    ResponseWrapper response = (ResponseWrapper) arg1;

    if ("doOperation".equals(request.getParameter("method"))
        && "PRINT_ALL_DOCUMENTS".equals(request.getParameter("operationType"))) {

      try {
        // clean the response html and make a DOM document out of it
        String responseHtml = clean(response.getContent());
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(new ByteArrayInputStream(responseHtml.getBytes()));

        // alter paths of link/img tags so itext can use them properly
        patchLinks(doc, request);

        // structure pdf document
        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(doc, "");
        renderer.layout();

        // create the pdf
        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        renderer.createPDF(pdfStream);

        // concatenate with other docs
        final Person person = (Person) request.getAttribute("person");
        final StudentCandidacy candidacy = getCandidacy(request);
        ByteArrayOutputStream finalPdfStream =
            concatenateDocs(pdfStream.toByteArray(), person, candidacy);
        byte[] pdfByteArray = finalPdfStream.toByteArray();

        // associate the summary file to the candidacy
        associateSummaryFile(pdfByteArray, person.getStudent().getNumber().toString(), candidacy);

        // redirect user to the candidacy summary page
        response.reset();
        response.sendRedirect(buildRedirectURL(request, candidacy));

        response.flushBuffer();
      } catch (ParserConfigurationException e) {
        logger.error(e.getMessage(), e);
      } catch (SAXException e) {
        logger.error(e.getMessage(), e);
      } catch (DocumentException e) {
        logger.error(e.getMessage(), e);
      }
    }
  }
Ejemplo n.º 2
0
  public ActionForward chooseStudent(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    final StudentContextSelectionBean studentContextSelectionBean = getRenderedObject();

    final String number = studentContextSelectionBean.getNumber();
    if (number != null && !number.isEmpty()) {
      final AcademicInterval academicInterval = studentContextSelectionBean.getAcademicInterval();
      final ExecutionInterval executionInterval =
          ExecutionInterval.getExecutionInterval(academicInterval);

      final SearchParameters searchParameters = new SearchParameters();
      if (StringUtils.isNumeric(number)) {
        searchParameters.setStudentNumber(Integer.valueOf(number));
      } else {
        searchParameters.setUsername(number);
      }
      final CollectionPager<Person> people =
          new SearchPerson()
              .run(searchParameters, new SearchPerson.SearchPersonPredicate(searchParameters));
      final Collection<Registration> registrations = new ArrayList<Registration>();
      for (final Person person : people.getCollection()) {
        if (person.getStudent() != null) {
          for (final Registration registration : person.getStudent().getRegistrationsSet()) {
            if (registration.hasAnyActiveState((ExecutionSemester) executionInterval)) {
              registrations.add(registration);
            }
          }
        }
      }

      if (studentContextSelectionBean.getToEdit()) {
        request.setAttribute("toEditScheduleRegistrations", registrations);
      } else {
        request.setAttribute("registrations", registrations);
        request.setAttribute("timeTableExecutionSemester", executionInterval);
      }
    }

    return prepare(mapping, form, request, response);
  }
 public static String createNewLine(
     final Person person, final CardGenerationBatch cardGenerationBatch) {
   final Student student = person.getStudent();
   if (student != null && !student.getActiveRegistrations().isEmpty()) {
     final StudentCurricularPlan studentCurricularPlan =
         findStudentCurricularPlan(cardGenerationBatch, student);
     if (studentCurricularPlan != null) {
       final String line = CardGenerationEntry.createLine(studentCurricularPlan);
       return line;
     }
   }
   return null;
 }
Ejemplo n.º 4
0
    public static boolean eval(Person contactPerson) {
      if (hasRole(RoleType.OPERATOR)
          || hasRole(RoleType.MANAGER)
          || isSelfPerson(contactPerson)
          || hasRole(RoleType.PERSONNEL_SECTION)) {
        return true;
      }

      if (contactPerson.getStudent() != null
          && !contactPerson.hasRole(RoleType.GRANT_OWNER)
          && !contactPerson.hasRole(RoleType.EMPLOYEE)) {
        return AcademicAuthorizationGroup.get(AcademicOperationType.EDIT_STUDENT_PERSONAL_DATA)
            .isMember(Authenticate.getUser());
      }

      return false;
    }
Ejemplo n.º 5
0
 private String getDegrees(final Person person) {
   final StringBuilder stringBuilder = new StringBuilder();
   final Student student = person.getStudent();
   if (student != null) {
     final Set<String> names = new TreeSet<String>();
     for (final Registration registration : student.getRegistrationsSet()) {
       final Degree degree = registration.getDegree();
       names.add(degree.getSigla());
     }
     for (final String name : names) {
       if (stringBuilder.length() > 0) {
         stringBuilder.append(", ");
       }
       stringBuilder.append(name);
     }
   }
   return stringBuilder.toString();
 }
  private void loadIndexes() {
    for (final Party party : RootDomainObject.getInstance().getPartysSet()) {
      if (party.isPerson()) {
        final Person person = (Person) party;
        try {
          final String personName = CardGenerationEntry.normalizePersonName(person).trim();
          addPerson(peopleByName, person, personName);

          if (person.hasEmployee()) {
            final Integer number = person.getEmployee().getEmployeeNumber();
            addPerson(peopleByNumber, person, number);
          }
          if (person.hasStudent()) {
            final Integer number = person.getStudent().getNumber();
            addPerson(peopleByNumber, person, number);
          }
        } catch (Error e) {
          // keep going... ignore the person for now.
          peopleWithBadNames.add(person);
        }
      }
    }
  }
  @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;
  }