Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.test.builder; |
| 2 | |||
| 3 | import static br.gov.al.saude.test.util.ConversorDeTipo.converterStringParaBoolean; |
||
| 4 | import static br.gov.al.saude.test.util.ConversorDeTipo.converterStringParaInteger; |
||
| 5 | import static br.gov.al.saude.test.util.ConversorDeTipo.converterStringParaLong; |
||
| 6 | |||
| 7 | import java.util.HashSet; |
||
| 8 | import java.util.Set; |
||
| 9 | |||
| 10 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 11 | import br.gov.al.saude.scg.model.view.MunicipioView; |
||
| 12 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 13 | import br.gov.al.saude.scg.model.view.UfView; |
||
| 14 | import br.gov.al.saude.scs.model.Capacitacao; |
||
| 15 | import br.gov.al.saude.scs.model.Turma; |
||
| 16 | import br.gov.al.saude.scs.model.TurmaParticipante; |
||
| 17 | import br.gov.al.saude.scs.model.TurmaPeriodo; |
||
| 18 | import br.gov.al.saude.scs.model.TurmaProcesso; |
||
| 19 | import br.gov.al.saude.scs.model.view.UnidadeView; |
||
| 20 | import br.gov.al.saude.test.unidade.generic.builder.AbstractEntidadeBuilder; |
||
| 21 | |||
| 22 | public class TurmaBuilder extends AbstractEntidadeBuilder<Turma> { |
||
| 23 | |||
| 24 | public TurmaBuilder comSequencial(String sequencial) { |
||
| 25 | entidade.setSequencial(parseLong(sequencial)); |
||
| 26 | return this; |
||
| 27 | } |
||
| 28 | |||
| 29 | public TurmaBuilder comCapacitacao(String sequencialCapacitacao) { |
||
| 30 | if (VerificadorUtil.naoEstaNuloOuVazio(sequencialCapacitacao)) { |
||
| 31 | Capacitacao capacitacao = new CapacitacaoBuilder().comSequencial(sequencialCapacitacao).build(); |
||
| 32 | entidade.setCapacitacao(capacitacao); |
||
| 33 | } |
||
| 34 | return this; |
||
| 35 | } |
||
| 36 | |||
| 37 | public TurmaBuilder comAnoExercicio(String ano) { |
||
| 38 | entidade.setAnoExercicio(converterStringParaInteger(ano)); |
||
| 39 | return this; |
||
| 40 | } |
||
| 41 | |||
| 42 | public TurmaBuilder comCargaHoraria(String cargaHoraria) { |
||
| 43 | entidade.setCargaHoraria(converterStringParaInteger(cargaHoraria)); |
||
| 44 | return this; |
||
| 45 | } |
||
| 46 | |||
| 47 | public TurmaBuilder comUf(String codigoUf) { |
||
| 48 | if (VerificadorUtil.naoEstaNuloOuVazio(codigoUf)) { |
||
| 49 | UfView uf = new UfView(); |
||
| 50 | uf.setCodigo(codigoUf); |
||
| 51 | entidade.setUf(uf); |
||
| 52 | } |
||
| 53 | return this; |
||
| 54 | } |
||
| 55 | |||
| 56 | public TurmaBuilder comMunicipio(String sequencialMunicipio) { |
||
| 57 | if (VerificadorUtil.naoEstaNuloOuVazio(sequencialMunicipio)) { |
||
| 58 | MunicipioView municipio = new MunicipioView(); |
||
| 59 | municipio.setSequencial(converterStringParaLong(sequencialMunicipio)); |
||
| 60 | entidade.setMunicipio(municipio); |
||
| 61 | } |
||
| 62 | return this; |
||
| 63 | } |
||
| 64 | |||
| 65 | public TurmaBuilder comObservacao(String observacao) { |
||
| 66 | entidade.setObservacao(observacao); |
||
| 67 | return this; |
||
| 68 | } |
||
| 69 | |||
| 70 | public TurmaBuilder comEmenta(String ementa) { |
||
| 71 | entidade.setEmenta(ementa); |
||
| 72 | return this; |
||
| 73 | } |
||
| 74 | |||
| 75 | public TurmaBuilder comUnidadeSolicitante(String sequencialUnidade) { |
||
| 76 | if (VerificadorUtil.naoEstaNuloOuVazio(sequencialUnidade)) { |
||
| 77 | UnidadeView unidade = new UnidadeView(); |
||
| 78 | unidade.setSequencial(converterStringParaLong(sequencialUnidade)); |
||
| 79 | entidade.setUnidadeSolicitante(unidade); |
||
| 80 | } |
||
| 81 | return this; |
||
| 82 | } |
||
| 83 | |||
| 84 | public TurmaBuilder comRepresentantes(String representantesString) { |
||
| 85 | if (VerificadorUtil.naoEstaNuloOuVazio(representantesString)) { |
||
| 86 | entidade.setRepresentantes(gerarTurmaRepresentantes(representantesString)); |
||
| 87 | } |
||
| 88 | return this; |
||
| 89 | } |
||
| 90 | |||
| 91 | private Set<PessoaFisicaView> gerarTurmaRepresentantes(String representantesString) { |
||
| 92 | Set<PessoaFisicaView> representantes = new HashSet<PessoaFisicaView>(); |
||
| 93 | String[] arrayRepresentantes = representantesString.split(";"); |
||
| 94 | for (String sequenciaPessoa : arrayRepresentantes) { |
||
| 95 | PessoaFisicaView representante = new PessoaFisicaView(); |
||
| 96 | representante.setSequencialPessoa(parseLong(sequenciaPessoa)); |
||
| 97 | representantes.add(representante); |
||
| 98 | } |
||
| 99 | return representantes; |
||
| 100 | } |
||
| 101 | |||
| 102 | public TurmaBuilder comProcessos(String processosTurmaString) { |
||
| 103 | if (VerificadorUtil.naoEstaNuloOuVazio(processosTurmaString)) { |
||
| 104 | entidade.setProcessos(gerarTurmaProcessos(processosTurmaString)); |
||
| 105 | } |
||
| 106 | return this; |
||
| 107 | } |
||
| 108 | |||
| 109 | private Set<TurmaProcesso> gerarTurmaProcessos(String processosTurmaString) { |
||
| 110 | Set<TurmaProcesso> turmaProcessos = new HashSet<TurmaProcesso>(); |
||
| 111 | String[] arrayTurmaProcesso = processosTurmaString.split(";"); |
||
| 112 | for (String turmaProcessoString : arrayTurmaProcesso) { |
||
| 113 | String[] propriedades = turmaProcessoString.split(","); |
||
| 114 | TurmaProcesso turmaProcesso = new TurmaProcessoBuilder() |
||
| 115 | .comTurma(entidade) |
||
| 116 | .comOrgao(propriedades[0]) |
||
| 117 | .comNumeroProcesso(propriedades[1]) |
||
| 118 | .comAno(propriedades[2]) |
||
| 119 | .build(); |
||
| 120 | turmaProcessos.add(turmaProcesso); |
||
| 121 | } |
||
| 122 | return turmaProcessos; |
||
| 123 | } |
||
| 124 | |||
| 125 | public TurmaBuilder comParticipantes(String participantesTurmaString) { |
||
| 126 | if (VerificadorUtil.naoEstaNuloOuVazio(participantesTurmaString)) { |
||
| 127 | entidade.setParticipantes(gerarTurmaParticipante(participantesTurmaString)); |
||
| 128 | } |
||
| 129 | return this; |
||
| 130 | } |
||
| 131 | |||
| 132 | private Set<TurmaParticipante> gerarTurmaParticipante(String participantesTurmaString) { |
||
| 133 | Set<TurmaParticipante> turmaParticipantes = new HashSet<TurmaParticipante>(); |
||
| 134 | String[] arrayTurmaParticipante = participantesTurmaString.split(";"); |
||
| 135 | for (String turmaParticipanteString : arrayTurmaParticipante) { |
||
| 136 | String[] propriedades = turmaParticipanteString.split(","); |
||
| 137 | TurmaParticipante turmaParticipante = new TurmaParticipanteBuilder() |
||
| 138 | .comTurma(entidade) |
||
| 139 | .comPessoa(propriedades[0]) |
||
| 140 | .comPerfil(propriedades[1]) |
||
| 141 | .comIndicadorRemunerado(propriedades[2]) |
||
| 142 | .comCargaHorariaEspecifica("null".equals(propriedades[3])?null:propriedades[3]) |
||
| 143 | .build(); |
||
| 144 | turmaParticipantes.add(turmaParticipante); |
||
| 145 | } |
||
| 146 | return turmaParticipantes; |
||
| 147 | } |
||
| 148 | |||
| 149 | public TurmaBuilder comPeriodos(String periodosTurmaString) { |
||
| 150 | if (VerificadorUtil.naoEstaNuloOuVazio(periodosTurmaString)) { |
||
| 151 | entidade.setPeriodos(gerarTurmaPeriodo(periodosTurmaString)); |
||
| 152 | } |
||
| 153 | return this; |
||
| 154 | } |
||
| 155 | |||
| 156 | private Set<TurmaPeriodo> gerarTurmaPeriodo(String periodosTurmaString) { |
||
| 157 | Set<TurmaPeriodo> turmaPeriodos = new HashSet<TurmaPeriodo>(); |
||
| 158 | String[] arrayTurmaPeriodo = periodosTurmaString.split(";"); |
||
| 159 | for (String turmaPeriodoString : arrayTurmaPeriodo) { |
||
| 160 | String[] propriedades = turmaPeriodoString.split(","); |
||
| 161 | TurmaPeriodo turmaPeriodo = new TurmaPeriodoBuilder() |
||
| 162 | .comTurma(entidade) |
||
| 163 | .comDataInicial(propriedades[0]) |
||
| 164 | .comDataFinal(propriedades[1]) |
||
| 165 | .build(); |
||
| 166 | turmaPeriodos.add(turmaPeriodo); |
||
| 167 | } |
||
| 168 | return turmaPeriodos; |
||
| 169 | } |
||
| 170 | |||
| 171 | public TurmaBuilder comIndicadorAtivo(String indicadorAtivo) { |
||
| 172 | entidade.setIndicadorAtivo(converterStringParaBoolean(indicadorAtivo)); |
||
| 173 | return this; |
||
| 174 | } |
||
| 175 | |||
| 176 | @Override |
||
| 177 | protected void inicializarDadosDefault() { |
||
| 178 | entidade = new Turma(); |
||
| 179 | } |
||
| 180 | |||
| 181 | } |