コード例 #1
0
 public ActionForward candidateDelete(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response) {
   InternshipCandidacyBean bean = getRenderedObject();
   bean.getCandidacy().delete();
   addActionMessage(request, "success.internationalrelations.internship.candidacy.delete");
   return prepareCandidates(mapping, actionForm, request, response);
 }
コード例 #2
0
 public ActionForward candidateEdit(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response) {
   InternshipCandidacyBean bean = getRenderedObject();
   try {
     bean.getCandidacy().edit(bean);
   } catch (DuplicateInternshipCandidacy e) {
     addErrorMessage(
         request,
         "studentNumber",
         "error.internationalrelations.internship.candidacy.duplicateStudentNumber",
         e.getNumber(),
         e.getUniversity());
     return mapping.findForward("edit");
   }
   return prepareCandidates(mapping, actionForm, request, response);
 }
コード例 #3
0
  public ActionForward exportToCandidatesToXls(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws FenixActionException {
    CandidateSearchBean search = getRenderedObject("search");
    if (search.getCutEnd().isBefore(search.getCutStart())) {
      addErrorMessage(
          request,
          "start",
          "error.internationalrelations.internship.candidacy.search.startafterend");
      return prepareCandidates(mapping, actionForm, request, response);
    }
    if (search.getCutEnd().plusDays(1).toDateMidnight().isAfterNow()) {
      addErrorMessage(
          request, "end", "error.internationalrelations.internship.candidacy.export.todaywontwork");
      return prepareCandidates(mapping, actionForm, request, response);
    }
    Spreadsheet sheet = new Spreadsheet(search.getName());
    if (search.getUniversity() == null) {
      sheet.setHeaders(HEADERS);
    } else {
      sheet.setHeaders(HEADERS_NO_UNIV);
    }
    for (InternshipCandidacyBean bean : filterCandidates(search)) {
      Row row = sheet.addRow();
      row.setCell(bean.getCandidacy().getCandidacyCode());
      if (search.getUniversity() == null) {
        row.setCell(bean.getUniversity().getFullPresentationName());
      }
      row.setCell(bean.getStudentNumber());
      row.setCell(bean.getStudentYear().ordinal() + 1);
      row.setCell(bean.getDegree());
      row.setCell(bean.getBranch());
      row.setCell(bean.getName());
      row.setCell(bean.getGender().toLocalizedString());
      row.setCell(bean.getBirthday().toString("dd-MM-yyyy"));
      row.setCell(bean.getParishOfBirth());
      row.setCell(
          StringUtils.capitalize(
              bean.getCountryOfBirth().getCountryNationality().getPreferedContent().toLowerCase()));
      row.setCell(bean.getDocumentIdNumber());
      row.setCell(
          bean.getEmissionLocationOfDocumentId() != null
              ? bean.getEmissionLocationOfDocumentId()
              : null);
      row.setCell(
          bean.getEmissionDateOfDocumentId() != null
              ? bean.getEmissionDateOfDocumentId().toString("dd-MM-yyyy")
              : null);
      row.setCell(
          bean.getExpirationDateOfDocumentId() != null
              ? bean.getExpirationDateOfDocumentId().toString("dd-MM-yyyy")
              : null);
      row.setCell(bean.getPassportIdNumber() != null ? bean.getPassportIdNumber() : "");
      row.setCell(
          bean.getEmissionLocationOfPassport() != null ? bean.getEmissionLocationOfPassport() : "");
      row.setCell(
          bean.getEmissionDateOfPassport() != null
              ? bean.getEmissionDateOfPassport().toString("dd-MM-yyyy")
              : "");
      row.setCell(
          bean.getExpirationDateOfPassport() != null
              ? bean.getExpirationDateOfPassport().toString("dd-MM-yyyy")
              : "");
      row.setCell(bean.getStreet());
      row.setCell(bean.getAreaCode());
      row.setCell(bean.getArea());
      row.setCell(bean.getTelephone());
      row.setCell(bean.getMobilePhone());
      row.setCell(bean.getEmail());
      row.setCell(
          StringUtils.capitalize(
              bean.getFirstDestination() != null
                  ? bean.getFirstDestination().getName().toLowerCase()
                  : ""));
      row.setCell(
          StringUtils.capitalize(
              bean.getSecondDestination() != null
                  ? bean.getSecondDestination().getName().toLowerCase()
                  : ""));
      row.setCell(
          StringUtils.capitalize(
              bean.getThirdDestination() != null
                  ? bean.getThirdDestination().getName().toLowerCase()
                  : ""));
      row.setCell(BundleUtil.getString(Bundle.ENUMERATION, bean.getEnglish().getQualifiedKey()));
      row.setCell(BundleUtil.getString(Bundle.ENUMERATION, bean.getFrench().getQualifiedKey()));
      row.setCell(BundleUtil.getString(Bundle.ENUMERATION, bean.getSpanish().getQualifiedKey()));
      row.setCell(BundleUtil.getString(Bundle.ENUMERATION, bean.getGerman().getQualifiedKey()));
      row.setCell(bean.getPreviousCandidacy() ? "Sim" : "Não");
    }

    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachment; filename=" + search.getName() + ".xls");

    try {
      OutputStream outputStream = response.getOutputStream();
      sheet.exportToXLSSheet(outputStream);
      outputStream.close();
    } catch (IOException e) {
      logger.error(e.getMessage(), e);
    }
    return null;
  }