public String removerProfessor() { obj.getProfessoresRemocao().add(turmaProfessor); obj.getProfessores().remove(turmaProfessor); turmaProfessor = new TurmaProfessor(); turmaProfessor.setDisciplinas(new ArrayList<DisciplinaTurmaProfessor>()); turmaProfessor.setProfessor(new Professor()); turmaProfessor.setTurma(new Turma()); turmaProfessor.setDisciplinasRemoacao(new ArrayList<DisciplinaTurmaProfessor>()); disciplinasSelecionadas = null; return getPaginaCadastro(); }
public String iniciarCadastro() { try { resetObj(); turmaProfessor = new TurmaProfessor(); turmaProfessor.setProfessor(new Professor()); turmaProfessor.setTurma(new Turma()); turmaProfessor.setDisciplinas(new ArrayList<DisciplinaTurmaProfessor>()); disciplinasSelecionadas = null; disciplinas = new DisciplinaDataModel(); disciplinas.setWrappedData(service.getAll(Disciplina.class)); alteracaoAssociacaoProfessor = false; } catch (NegocioException e) { addMensagemErro(processaException(e)); } setConfirmButton("Cadastrar"); return getPaginaCadastro(); }
public String preAlterar() { if (ValidatorUtil.isEmpty(obj)) { addMensagemErro("O elemento selecionando não se encontra na base de dados."); resetObj(); return null; } try { disciplinas = new DisciplinaDataModel(); disciplinas.setWrappedData(service.getAll(Disciplina.class)); obj.setProfessores(tpService.getByTurma(obj)); obj.setProfessoresRemocao(new ArrayList<TurmaProfessor>()); for (TurmaProfessor tp : obj.getProfessores()) { tp.setDisciplinas( tpService.getByExactField( DisciplinaTurmaProfessor.class, "turmaProfessor.id", tp.getId())); } } catch (NegocioException e) { addMensagemErro(processaException(e)); } setConfirmButton("Alterar"); return getPaginaCadastro(); }
public String inserirProfessor() { validateInserirProfessor(); if (isContemErros()) { return getPaginaCadastro(); } TurmaProfessor tp = new TurmaProfessor(); try { tp = (TurmaProfessor) turmaProfessor.clone(); } catch (CloneNotSupportedException e) { addMensagemErro(processaException(e)); } if (isAlteracaoAssociacaoProfessor()) { if (ValidatorUtil.isEmpty(tp.getDisciplinasRemoacao())) { tp.setDisciplinasRemoacao(new ArrayList<DisciplinaTurmaProfessor>()); } // Verifica se existem disciplinas a serem removidas Collection<DisciplinaTurmaProfessor> disciplinasAnteriores = new ArrayList<DisciplinaTurmaProfessor>(tp.getDisciplinas()); Collection<Disciplina> disciplinas = new ArrayList<Disciplina>(); for (DisciplinaTurmaProfessor dtp : disciplinasAnteriores) { List<Disciplina> asList = Arrays.asList(disciplinasSelecionadas); if (!asList.contains(dtp.getDisciplina())) { tp.getDisciplinasRemoacao().add(dtp); tp.getDisciplinas().remove(dtp); } disciplinas.add(dtp.getDisciplina()); } // Verifica disciplinas adicionadas for (Disciplina disciplina : Arrays.asList(disciplinasSelecionadas)) { if (!disciplinas.contains(disciplina)) { DisciplinaTurmaProfessor dtp = new DisciplinaTurmaProfessor(); dtp.setDisciplina(disciplina); dtp.setTurmaProfessor(tp); tp.getDisciplinas().add(dtp); } } obj.getProfessores().remove(turmaProfessor); obj.getProfessores().add(tp); } else { for (Disciplina disciplina : disciplinasSelecionadas) { DisciplinaTurmaProfessor dtp = new DisciplinaTurmaProfessor(); dtp.setDisciplina(disciplina); dtp.setTurmaProfessor(tp); if (ValidatorUtil.isEmpty(tp.getDisciplinas())) { tp.setDisciplinas(new ArrayList<DisciplinaTurmaProfessor>()); } tp.getDisciplinas().add(dtp); } tp.setTurma(obj); obj.getProfessores().add(tp); } turmaProfessor = new TurmaProfessor(); disciplinasSelecionadas = null; alteracaoAssociacaoProfessor = false; return getPaginaCadastro(); }