Subversion Repositories bacoAlunos

Rev

Rev 1423 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1235 jmachado 1
package pt.estgp.estgweb.services.sigesimports.oracle.dao;
2
 
3
import pt.estgp.estgweb.services.sigesimports.oracle.domain.Aluno;
4
import pt.estgp.estgweb.services.sigesimports.oracle.domain.AlunoHistorico;
5
import pt.estgp.estgweb.services.sigesimports.oracle.domain.Disciplina;
1553 jmachado 6
import pt.estgp.estgweb.services.sigesimports.oracle.domain.Nacionalidade;
1235 jmachado 7
 
8
import java.sql.Connection;
9
import java.sql.PreparedStatement;
10
import java.sql.ResultSet;
11
import java.sql.SQLException;
12
import java.util.ArrayList;
1553 jmachado 13
import java.util.HashMap;
1235 jmachado 14
 
15
/**
16
 * Created by jorgemachado on 07/01/16.
17
 */
18
public class AlunoDao extends AbstractDao<Aluno> {
19
    private static AlunoDao instance = null;
20
 
21
    private AlunoDao() {
22
    }
23
 
24
    public static AlunoDao getInstance() {
25
        if (instance == null)
26
            instance = new AlunoDao();
27
        return instance;
28
    }
29
 
30
    protected 1.5.0/docs/api/java/lang/String.html">String getTable() {
31
        return "CSE.T_ALUNOS";
32
    }
33
 
34
    protected 1.5.0/docs/api/java/lang/String.html">String getIdColumn() {
35
        return "CD_ALUNO";
36
    }
37
 
1553 jmachado 38
    public HashMap<Integer,Nacionalidade> loadNacionalidades(1.5.0/docs/api/java/sql/Connection.html">Connection conn) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
39
        HashMap<Integer,Nacionalidade> nacionalidades = new HashMap<Integer, Nacionalidade>();
40
        boolean connWasNull = conn == null;
41
        if (conn == null) {
42
            conn = getCurrentConnection();
43
        }
44
        1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement catCMD = conn.prepareStatement("SELECT * FROM SIGES.T_TBNACIONA");
45
        1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReader = catCMD.executeQuery();
46
        while (aReader.next())
47
        {
48
            1.5.0/docs/api/java/lang/Integer.html">Integer nacionalidadeCodigo = getDecimal("CD_NACIONA", aReader);
49
            1.5.0/docs/api/java/lang/String.html">String nacionalidade = getString("DS_NACIONA",aReader);
50
            1.5.0/docs/api/java/lang/String.html">String pais = getString("DS_PAIS",aReader);
51
            Nacionalidade nacionalidadeRec = new Nacionalidade();
52
            nacionalidadeRec.setCodigoNacionalidade(nacionalidadeCodigo);
53
            nacionalidadeRec.setNacionalidade(nacionalidade);
54
            nacionalidadeRec.setPais(pais);
55
            nacionalidades.put(nacionalidadeCodigo,nacionalidadeRec);
56
 
57
        }
58
        //close the reader
59
        aReader.close();
60
        catCMD.close();
61
 
62
        if (connWasNull)
63
            conn.close();
64
        return nacionalidades;
65
    }
66
 
1235 jmachado 67
    public Aluno load(1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReader) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
68
        Aluno a = new Aluno();
69
        a.codigo = getDecimal("CD_ALUNO", aReader);
70
        //a.nome = getString("NM_ALUNO",aReader);
71
        a.nome = getString("NM_COMPLETO", aReader);
1553 jmachado 72
        a.codigoNacionalidade = getDecimal("CD_NACIONA",aReader);
1235 jmachado 73
 
74
        //d.nomeFuncionario = getString("NM_COMPLETO", aReader); //ok T_INDIVIDUO  FALTA VER O "NOME"
75
        //d.nomeFuncionarioInt = getString("NM_FUNC_INT", aReader);
76
        //d.nomeFuncionario = getString("NM_ABREVIADO", aReader); //ok T_INDIVIDUO
77
        //d.nomeAcademico = getString("NM_ACADEMICO", aReader);   //ok T_INDIVIDUO
78
 
79
        //a.sexo = getString("CD_SEXO", aReader);
80
        a.sexo = getString("SEXO", aReader);
81
 
82
        //a.data_nascimento = getDateTime("DT_NASCIME", aReader);
83
        //a.morada = getString("DS_MORADA", aReader);
84
        //a.codigoPostal = getInteger("CD_POSTAL", aReader);
85
        //a.subCodigoPostal = getInteger("CD_SUBPOS", aReader);
86
        //a.email = getString("DS_EMAIL", aReader);
87
        //a.numeroBi = getString("NR_BI", aReader);
88
        a.telemovel = getString("NR_TELEMOVEL", aReader);
89
 
90
 
91
        a.data_nascimento = getDateTime("DT_NASCIMENTO", aReader);
92
        a.morada = getString("DS_MORADA", aReader);
93
        a.codigoPostal = getDecimal("CD_POSTAL", aReader);
94
        a.subCodigoPostal = getDecimal("CD_SUBPOS", aReader);
95
        a.email = getString("EMAIL", aReader);
96
        a.numeroBi = getString("IDENTIFICACAO", aReader);
97
 
98
 
99
        //a.usernameNetpa = getString("USERNAME_NETPA", aReader);
100
        a.usernameNetpa = getString("USER_NETPA", aReader); //T_ALUNO
101
        return a;
102
    }
103
 
1312 jmachado 104
    public ArrayList<Integer> loadCodigosAlunos(1.5.0/docs/api/java/lang/Integer.html">Integer codigoInstituicao, 1.5.0/docs/api/java/lang/String.html">String ano) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
105
        return loadCodigosAlunos(codigoInstituicao, ano,null);
106
    }
1235 jmachado 107
    /*Valid with diagrams*/
1312 jmachado 108
    public ArrayList<Integer> loadCodigosAlunos(1.5.0/docs/api/java/lang/Integer.html">Integer codigoInstituicao, 1.5.0/docs/api/java/lang/String.html">String ano, 1.5.0/docs/api/java/sql/Connection.html">Connection conn) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
1235 jmachado 109
        ArrayList<Integer> codigos = new ArrayList<Integer>();
1312 jmachado 110
        boolean connWasNull = conn == null;
111
        if (conn == null) {
112
            conn = getCurrentConnection();
113
        }
1423 jmachado 114
        1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement catCMD = conn.prepareStatement("SELECT DISTINCT " +
115
                " CSE.T_ALUNOS.CD_ALUNO AS CD_ALUNO " +
116
                "FROM CSE.T_ALUNOS " +
117
                "INNER JOIN (CSE.T_INSCRI INNER JOIN CSE.T_TBDISCIP ON CSE.T_INSCRI.CD_DISCIP = CSE.T_TBDISCIP.CD_DISCIP) ON CSE.T_ALUNOS.CD_ALUNO = CSE.T_INSCRI.CD_ALUNO " +
118
                "WHERE (((CSE.T_TBDISCIP.CD_INSTITUIC)=" + codigoInstituicao + ") AND ((CSE.T_INSCRI.CD_LECTIVO)='" + ano + "') " +
119
                /*AND ((CSE.T_ALUNOS.CD_SITUA_PAR)=1)*/
120
                " AND ((CSE.T_INSCRI.CD_STATUS)<>5))");
1235 jmachado 121
        1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReader = catCMD.executeQuery();
122
        while (aReader.next()) {
123
            codigos.add(getDecimal("CD_ALUNO", aReader));
124
        }
125
        //close the reader
126
        aReader.close();
1312 jmachado 127
        catCMD.close();
128
        if (connWasNull)
129
            conn.close();
1235 jmachado 130
        return codigos;
131
    }
132
 
133
    public Aluno loadInscrito(1.5.0/docs/api/java/lang/Integer.html">Integer codigo, 1.5.0/docs/api/java/lang/Integer.html">Integer codigoInstituicao, 1.5.0/docs/api/java/lang/String.html">String ano) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
1312 jmachado 134
        return loadInscrito(codigo, codigoInstituicao, ano,null);
135
    }
136
    public Aluno loadInscrito(1.5.0/docs/api/java/lang/Integer.html">Integer codigo, 1.5.0/docs/api/java/lang/Integer.html">Integer codigoInstituicao, 1.5.0/docs/api/java/lang/String.html">String ano,1.5.0/docs/api/java/sql/Connection.html">Connection conn) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
1235 jmachado 137
 
1312 jmachado 138
        boolean connWasNull = conn == null;
139
        if (conn == null) {
140
            conn = getCurrentConnection();
141
        }
1423 jmachado 142
        1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement catCMD = conn.prepareStatement("SELECT * FROM " + getTable() + " " +
143
                "INNER JOIN SIGES.T_INDIVIDUO on SIGES.T_INDIVIDUO.ID_INDIVIDUO = CSE.T_ALUNOS.ID_INDIVIDUO " +
144
                "where /*CD_SITUA_PAR = 1 AND*/ " + getIdColumn() + "=" + codigo);
1235 jmachado 145
        1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReader = catCMD.executeQuery();
1423 jmachado 146
 
147
 
1235 jmachado 148
        if (aReader.next()) {
149
            Aluno a = load(aReader);
1298 jmachado 150
            a.disciplinasInscrito = loadDiscilpinasInscrito(codigo, codigoInstituicao, ano);
1312 jmachado 151
            a.historicos = getHistorico(codigo);
1423 jmachado 152
 
153
            obtainTiposAlunoRepresentados(codigo, ano, conn, a);
154
 
1235 jmachado 155
            aReader.close();
156
            return a;
157
        }
158
        aReader.close();
1312 jmachado 159
        catCMD.close();
160
        if (connWasNull)
161
            conn.close();
162
 
1235 jmachado 163
        //close the reader
164
        return null;
165
    }
166
 
1423 jmachado 167
    private void obtainTiposAlunoRepresentados(1.5.0/docs/api/java/lang/Integer.html">Integer codigo, 1.5.0/docs/api/java/lang/String.html">String ano, 1.5.0/docs/api/java/sql/Connection.html">Connection conn, Aluno a) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
168
        1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement tiposAluno = conn.prepareStatement(
169
                "SELECT DISTINCT CSE.T_TIPALUNO.CD_TIP_ALU AS CD_TIP_ALU, CSE.T_TBTIPALU.DS_TIP_ALU AS DS_TIP_ALU " +
170
                "       FROM CSE.T_TIPALUNO " +
171
                "       LEFT OUTER JOIN CSE.T_TBTIPALU ON CSE.T_TIPALUNO.CD_TIP_ALU = CSE.T_TBTIPALU.CD_TIP_ALU " +
172
                "       where     CSE.T_TIPALUNO.CD_ALUNO = " + codigo + "  " +
173
                "             AND CSE.T_TIPALUNO.CD_LECTIVO = '" + ano + "'");
174
 
175
 
176
        1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReaderTiposAluno = tiposAluno.executeQuery();
177
        a.setTiposAlunosRepresentados(new ArrayList<Aluno.TipoAluno>());
178
        while(aReaderTiposAluno.next())
179
        {
180
 
181
            1.5.0/docs/api/java/lang/Integer.html">Integer cdTipAluno = getDecimal("CD_TIP_ALU",aReaderTiposAluno);
182
            if(cdTipAluno != null && cdTipAluno > 0)
183
            {
184
                Aluno.TipoAluno tipoAluno = new Aluno.TipoAluno();
185
                tipoAluno.setCodigoTipoAluno(""+cdTipAluno);
186
                tipoAluno.setDescTipoAluno(getString("DS_TIP_ALU", aReaderTiposAluno));
187
                a.getTiposAlunosRepresentados().add(tipoAluno);
188
            }
189
 
190
        }
191
        aReaderTiposAluno.close();
192
        tiposAluno.close();
193
    }
194
 
1235 jmachado 195
    /*Mudar a lista para uma lista de Códigos com pelo menos CD_LECTIVO, CD_DISCIP, CD_CURSO, CD_TURMA*/
196
                /*Do lado do Baco as Disciplinas são criadas uma por (CD_LECTIVO, CODIGO, CURSO, SEMESTRE) ficam anexadas todas as turmas encontradas*/
197
                /* O Serviço de Leituras de Sumarios pede apenas os detalhe_aula com codigos de turma igual ao pedido e CD_LECTIVO = actual */
198
    public ArrayList<Disciplina> loadDiscilpinasInscrito(1.5.0/docs/api/java/lang/Integer.html">Integer codigo, 1.5.0/docs/api/java/lang/Integer.html">Integer codigoInstituicao, 1.5.0/docs/api/java/lang/String.html">String ano) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
199
        ArrayList<Disciplina> disciplinas = new ArrayList<Disciplina>();
200
        1.5.0/docs/api/java/sql/Connection.html">Connection conn = getCurrentConnection();
201
        1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement catCMD = conn.prepareStatement("SELECT " +
1341 jmachado 202
                "                CSE.T_INSCRI.CD_TIPDIS AS CD_TIPDIS, " +
203
                "                CSE.T_INSCRI.CD_DISCIP AS CD_DISCIP,  " +
204
                "                CSE.T_INSCRI.CD_DURACAO AS CD_DURACAO, " +
205
                "                CSE.T_INSCRI.CD_CURSO AS CD_CURSO, " +
206
                "                CSE.T_INSCRI.CD_TURMA_T AS CD_TURMA, " +
207
                "                CSE.T_INSCRI.CD_TURMA_P, " +
208
                "                CSE.T_INSCRI.CD_TURMA_L, " +
1400 jmachado 209
                "                CSE.T_INSCRI.CD_TURMA_TP, " +
210
                "                CSE.T_INSCRI.CD_TURMA_S, " +
211
                "                CSE.T_INSCRI.CD_TURMA_C, " +
212
                "                CSE.T_INSCRI.CD_TURMA_O, " +
1423 jmachado 213
                "                CSE.T_INSCRI.CD_TURMA_E "  +
214
                "                FROM CSE.T_INSCRI INNER JOIN CSE.T_TBDISCIP ON CSE.T_INSCRI.CD_DISCIP = CSE.T_TBDISCIP.CD_DISCIP " +
1399 jmachado 215
                //"                INNER JOIN CSE.T_CURSOS ON CSE.T_CURSOS.CD_CURSO = CSE.T_INSCRI.CD_CURSO " +
1423 jmachado 216
 
1341 jmachado 217
                "                WHERE CSE.T_INSCRI.CD_ALUNO = " + codigo + " " +
218
                "                AND" +
219
                "                    CSE.T_TBDISCIP.CD_INSTITUIC= " + codigoInstituicao + " AND " +
220
                "                    CSE.T_INSCRI.CD_LECTIVO='" + ano + "' AND " +
221
                "                    CSE.T_INSCRI.CD_STATUS<>5 AND " +
1423 jmachado 222
                "                (CSE.T_INSCRI.CD_TIPDIS = 2 OR CSE.T_INSCRI.CD_TIPDIS = 1 OR CSE.T_INSCRI.CD_TIPDIS = 6) "
223
 
224
 
225
        );
1235 jmachado 226
        //CD_TIPDISC = 1 Inscricoes normais
227
        //CD_TIPDISC = 2 Nao conta para media
228
        //CD_TIPDISC = 3 Qualitativa
229
        //CD_TIPDISC = 4 Equivalencia
230
        //CD_TIPDISC = 5 Equivalencia sem nota
231
        //CD_TIPDISC = 6 Extra Curricular
232
        //CD_TIPDISC = 7 Suplemento Diploma
233
        //CD_TIPDISC = 8 Integracao ou refazimento do plano de estudos
234
 
235
        1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReader = catCMD.executeQuery();
236
        while (aReader.next()) {
237
            Disciplina d = new Disciplina();
238
            d.codigo = getDecimal("CD_DISCIP", aReader);
239
            d.codigoCurso = getDecimal("CD_CURSO", aReader);
240
            d.codigoInstituicao = codigoInstituicao;
241
            d.cdLectivo = ano;
242
            d.cdTipoDisciplina = getDecimal("CD_TIPDIS", aReader);
243
            d.cdDuracao = getString("CD_DURACAO", aReader);
244
            d.cdTurma = getString("CD_TURMA", aReader);
1423 jmachado 245
 
1400 jmachado 246
            if(getString("CD_TURMA_P", aReader) != null)
247
            {
248
                d.outraTurma = getString("CD_TURMA_P", aReader);
249
                d.outraTurmaCode = "P";
250
            }
251
            else if(getString("CD_TURMA_L", aReader) != null)
252
            {
253
                d.outraTurma = getString("CD_TURMA_L", aReader);
254
                d.outraTurmaCode = "L";
255
            }
256
            else if(getString("CD_TURMA_TP", aReader) != null)
257
            {
258
                d.outraTurma = getString("CD_TURMA_TP", aReader);
259
                d.outraTurmaCode = "TP";
260
            }
261
            else if(getString("CD_TURMA_S", aReader) != null)
262
            {
263
                d.outraTurma = getString("CD_TURMA_S", aReader);
264
                d.outraTurmaCode = "S";
265
            }
266
            else if(getString("CD_TURMA_C", aReader) != null)
267
            {
268
                d.outraTurma = getString("CD_TURMA_C", aReader);
269
                d.outraTurmaCode = "C";
270
            }
271
            else if(getString("CD_TURMA_O", aReader) != null)
272
            {
273
                d.outraTurma = getString("CD_TURMA_O", aReader);
274
                d.outraTurmaCode = "O";
275
            }
276
            else if(getString("CD_TURMA_E", aReader) != null)
277
            {
278
                d.outraTurma = getString("CD_TURMA_E", aReader);
279
                d.outraTurmaCode = "E";
280
            }
1235 jmachado 281
            disciplinas.add(d);
282
        }
283
        //close the reader
284
        aReader.close();
285
        return disciplinas;
286
    }
287
 
288
    /*Mudar a lista para uma lista de Códigos com pelo menos CD_LECTIVO, CD_DISCIP, CD_CURSO, CD_TURMA*/
289
        /*Do lado do Baco as Disciplinas são criadas uma por (CD_LECTIVO, CODIGO, CURSO, SEMESTRE) ficam anexadas todas as turmas encontradas*/
290
        /* O Serviço de Leituras de Sumarios pede apenas os detalhe_aula com codigos de turma igual ao pedido e CD_LECTIVO = actual */
291
    public ArrayList<AlunoHistorico> getHistorico(1.5.0/docs/api/java/lang/Integer.html">Integer codigo) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException {
292
        ArrayList<AlunoHistorico> historicos = new ArrayList<AlunoHistorico>();
293
        1.5.0/docs/api/java/sql/Connection.html">Connection conn = getCurrentConnection();
1298 jmachado 294
 
1235 jmachado 295
        1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement catCMD = conn.prepareStatement("SELECT CSE.T_HISTALUN.CD_LECTIVO AS CD_LECTIVO, CSE.T_HISTALUN.CD_CURSO AS CD_CURSO, CSE.T_HISTALUN.DT_MATRIC AS DT_MATRIC, CSE.T_HISTALUN.PROTEGIDO AS PROTEGIDO, CSE.T_HISTALUN.CD_PROPINA AS CD_PROPINA  FROM CSE.T_HISTALUN WHERE CSE.T_HISTALUN.CD_ALUNO = " + codigo + "");
296
 
297
 
298
        1.5.0/docs/api/java/sql/ResultSet.html">ResultSet aReader = catCMD.executeQuery();
299
        while (aReader.next()) {
300
            AlunoHistorico a = new AlunoHistorico();
301
            a.codigo = codigo;
302
            a.codigoCurso = getDecimal("CD_CURSO", aReader);
303
            a.codigoLectivo = getString("CD_LECTIVO", aReader);
304
            a.dataMatricula = getDateTime("DT_MATRIC", aReader);
305
            a.propinaEmDia = getString("CD_PROPINA", aReader);
306
            a.historicoProtegido = getString("PROTEGIDO", aReader);
307
            historicos.add(a);
308
        }
309
        //close the reader
310
        aReader.close();
311
        return historicos;
312
    }
313
 
314
}