Exemplo n.º 1
0
  /**
   * @param table
   * @param prof
   * @param bim
   * @return a planilha parseada ou <code>null</code> caso a primeira célula de aulas dadas esteja
   *     vazia, ou algum outro problema aconteça
   * @throws NotasParserException
   */
  private ProfSheet parseSheet(Table table, String prof, Periodo bim) throws NotasParserException {

    logger.debug("Lendo período " + bim);

    ProfSheet profSheet = new ProfSheet(bim, prof);

    Coluna y = new Coluna(COL_FIRST_TARJETA);
    int i = 0;
    String posTurma = y.getValor().concat(LIN_TURMAS);
    String turma = "";
    turma = table.getCellByPosition(posTurma).getDisplayText();

    while (!turma.isEmpty() && !turma.contains("FIM")) {

      try {
        Tarjeta tarj = parseTarjeta(table, i, prof, bim);
        profSheet.getTarjetas().add(tarj);
      } catch (NotasParserException e) {
        logger.warn(
            "Tarjeta da "
                + turma
                + " "
                + bim
                + " não incluída na planilha de "
                + profSheet.getProfessor());
      }

      i++;
      y.inc(TARJETAS_DISTANCE);
      String pos = y.getValor().concat(LIN_TURMAS);
      Cell nextCell = table.getCellByPosition(pos);
      turma = nextCell.getDisplayText();
    }

    return profSheet;
  }
Exemplo n.º 2
0
  /**
   * Extrai informação da tarjeta. Tarjeta gerada possui nome do professor identificado na própria
   * tarjeta. Mas mensagens de erro são dadas em nome do professor dono do arquivo, pois a mensagem
   * serve para ajudar o operador a identificar o local do problema.
   *
   * @param table
   * @param index índice da tarjeta na planilha, indo de 0 a N-1
   * @param professor dono da planilha, a princípio prof de todas as tarjetas
   * @param bim
   * @return
   * @throws NotasParserException
   */
  private Tarjeta parseTarjeta(Table table, int index, String profSheet, Periodo bim)
      throws NotasParserException {

    Coluna y = new Coluna(COL_FIRST_TARJETA);
    y.inc(TARJETAS_DISTANCE * index);

    String turma, aulasDadasStr, aulasPrevistasStr, materia, profTarjeta = "";
    String posTurma = y.getValor().concat(LIN_TURMAS);
    turma = table.getCellByPosition(posTurma).getDisplayText();
    String posAulasDadas = y.getValor().concat(LIN_AULAS_DADAS);
    aulasDadasStr = table.getCellByPosition(posAulasDadas).getDisplayText();
    String posAulasPrevistas = y.getValor().concat(LIN_AULAS_PREVISTAS);
    aulasPrevistasStr = table.getCellByPosition(posAulasPrevistas).getDisplayText();
    String posMateria = y.getValor().concat(LIN_MATERIAS);
    materia = table.getCellByPosition(posMateria).getDisplayText();
    Coluna yprof = new Coluna(y.getValor());
    yprof.dec();
    String posProf = yprof.getValor().concat(LIN_NOME_PROF);
    profTarjeta = table.getCellByPosition(posProf).getDisplayText();

    // se prof não foi identificado na tarjeta,
    // assumimos que o professor é o dono da planilha
    if (profTarjeta == null || profTarjeta.isEmpty()) {
      profTarjeta = profSheet;
    }

    if (turma.isEmpty()) {
      String msg =
          "Turma não especificada na tarjeta "
              + (index + 1)
              + " do "
              + bim
              + " do prof "
              + profSheet;
      logger.error(msg);
      throw new NotasParserException(msg);
    }
    if (materia.isEmpty()) {
      String msg =
          "Matéria não especificada na tarjeta "
              + (index + 1)
              + " do "
              + bim
              + " do prof "
              + profSheet;
      logger.error(msg);
      throw new NotasParserException(msg);
    }

    int aulasDadas = 0, aulasPrevistas = 0;
    try {
      aulasDadas = Integer.parseInt(aulasDadasStr);
    } catch (NumberFormatException e) {
      String message =
          "Aulas dadas não foram registradas na célula" + y.getValor() + LIN_AULAS_DADAS;
      logger.warn(message);
    }
    try {
      aulasPrevistas = Integer.parseInt(aulasPrevistasStr);
    } catch (NumberFormatException e) {
      String message =
          "Aulas previstas não foram registradas na célula "
              + y.getValor()
              + LIN_AULAS_PREVISTAS
              + " ("
              + profSheet
              + " - "
              + bim
              + ")";
      logger.warn(message);
    }

    Tarjeta tarj = new Tarjeta(turma, materia, profTarjeta, bim, aulasDadas, aulasPrevistas);

    // notas
    int row = Integer.parseInt(LIN_FIRST_NOTA);
    for (int i = 0; i < MAX_ALUNOS; i++) {

      String nota, aluno, faltas = "";
      String posNota = y.getValor().concat(Integer.toString(row));
      nota = table.getCellByPosition(posNota).getDisplayText();
      Coluna ya = new Coluna(y.getValor());
      ya.dec();
      String posAluno = ya.toString().concat(Integer.toString(row));
      aluno = table.getCellByPosition(posAluno).getDisplayText();
      Coluna yf = new Coluna(y.getValor());
      yf.inc();
      String posFaltas = yf.getValor().concat(Integer.toString(row));
      faltas = table.getCellByPosition(posFaltas).getDisplayText();

      int notaInt = 0, faltasInt = 0;
      String alteracao = null;
      if (nota != null && !nota.isEmpty()) {
        try {
          notaInt = Integer.parseInt(nota);
        } catch (NumberFormatException e) {
          if (nota != null && !nota.isEmpty()) alteracao = nota;
        }
        try {
          faltasInt = Integer.parseInt(faltas);
        } catch (NumberFormatException e) {;
        }
      }
      Conceito conc = new Conceito(new Aluno(aluno, turma), notaInt, faltasInt);
      conc.setAlteracao(alteracao);
      tarj.getNotas().add(conc);

      row++;
    }

    return tarj;
  }