Search in sources :

Example 1 with HibernateTurmaDAO

use of com.tomasio.projects.trainning.dao.HibernateTurmaDAO in project trainning by fernandotomasio.

the class ImportTurmasImplEfetivasFromTabelao method recuperarDocumentos.

private void recuperarDocumentos(String codCurso, String numeroTurma, TurmaEfetiva turmaCriada, Connection conn) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    ContentDAO contentDAO = new AlfrescoContentDAO();
    TurmaDAO turmaDAO = new HibernateTurmaDAO();
    String documentsRoot = "SGC/Documentos de Treinamentos/testes";
    String oldFolderName = "D-CTP/Documentos de Treinamentos/2013/" + codCurso + "-" + numeroTurma;
    String newFolderName = df.format(turmaCriada.getExercicio()) + "_" + turmaCriada.getCurso().getCodigo() + "_" + turmaCriada.getNumeroTurma() + "_" + turmaCriada.getId();
    try {
        WebServiceFactory.setEndpointAddress("http://dctp.decea.intraer:8080/ecm/api");
        boolean existsOldFolder = contentExistsByPath(oldFolderName);
        if (existsOldFolder) {
            WebServiceFactory.setEndpointAddress("http://10.32.63.32:8080/alfresco/api");
            FolderDTO folder = new FolderDTO();
            folder.setName(newFolderName);
            String folderId = contentDAO.createFolder(folder, documentsRoot);
            turmaCriada.setFolderId(folderId);
            turmaDAO.update(turmaCriada);
            WebServiceFactory.setEndpointAddress("http://dctp.decea.intraer:8080/ecm/api");
            ContentDTO[] contents = findAllContentByPath(oldFolderName);
            for (ContentDTO content : contents) {
                WebServiceFactory.setEndpointAddress("http://dctp.decea.intraer:8080/ecm/api");
                DocumentDTO document = findDocumentByUUID(content.getUid());
                document.setMimeType("application/pdf");
                WebServiceFactory.setEndpointAddress("http://10.32.63.32:8080/alfresco/api");
                contentDAO.createDocumentWithUUIDParent(document, folderId);
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(ImportTurmasImplEfetivasFromTabelao.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : ParseException(java.text.ParseException) RemoteException(java.rmi.RemoteException) DAOException(com.tomasio.projects.trainning.exception.DAOException) ContentDAO(com.tomasio.projects.trainning.dao.ContentDAO) AlfrescoContentDAO(com.tomasio.projects.trainning.dao.AlfrescoContentDAO) ContentDTO(com.tomasio.projects.trainning.dto.ContentDTO) FolderDTO(com.tomasio.projects.trainning.dto.FolderDTO) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) AlfrescoContentDAO(com.tomasio.projects.trainning.dao.AlfrescoContentDAO) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with HibernateTurmaDAO

use of com.tomasio.projects.trainning.dao.HibernateTurmaDAO in project trainning by fernandotomasio.

the class ImportTurmasImplEfetivasFromTabelao method execute.

@Override
public void execute() {
    try {
        TurmaDAO turmaDAO = new HibernateTurmaDAO();
        CursoDAO cursoDAO = null;
        PlanejamentoDAO planejamentoDAO = new HibernatePlanejamentoDAO();
        OrganizacaoDAO organizacaoDAO = new HibernateOrganizacaoDAO();
        Connection conn = DriverManager.getConnection("jdbc:mysql://10.32.63.29/dctp?user=dctp&password=112358");
        Statement stm = conn.createStatement();
        ResultSet rs = stm.executeQuery("SELECT * FROM tabelao where ano=2013");
        int i = 0;
        while (rs.next()) {
            // PlanejamentoDTO planejamento = planejamentoDAO.find(1L);
            TurmaEfetiva turma = new TurmaEfetiva();
            // turma.setPlanejamento(planejamento);
            Organizacao organizacaoGestora = organizacaoDAO.findBySigla("DECEA");
            if (organizacaoGestora != null) {
                turma.setOrganizacaoGestoraId(organizacaoGestora.getId());
            }
            turma.setExercicio(new Date());
            Date inicio = rs.getDate("inicio");
            Date fim = rs.getDate("fim");
            String local = rs.getString("local");
            Date inicio2 = rs.getDate("inicio2");
            Date fim2 = rs.getDate("fim2");
            String local2 = rs.getString("local2");
            Date inicio3 = rs.getDate("inicio3");
            Date fim3 = rs.getDate("fim3");
            String local3 = rs.getString("local3");
            String numTurma = rs.getString("turma");
            String codCurso = rs.getString("codcurso");
            int quantidadeVagas = rs.getInt("Vagas");
            turma.setQuantidadeVagas(quantidadeVagas);
            int codPlano = rs.getInt("codPlano");
            String ativado = rs.getString("ativado");
            int codTabelao = rs.getInt("codTabelao");
            // if (codCurso.equals("CNS014")) {
            // continue;
            // }
            // if (codCurso.equals("CNS005")) {
            // continue;
            // }
            // if (codCurso.equals("SAR005")) {
            // continue;
            // }
            // if (codCurso.equals("ASE007")) {
            // continue;
            // }
            // if (codCurso.equals("ASE009")) {
            // continue;
            // }
            Curso curso = cursoDAO.findByCodigo(codCurso);
            turma.setCurso(curso);
            if (codPlano != 11) {
                continue;
            }
            if (numTurma.contains("GT")) {
                System.out.println("GT NÃO IMPORTADO");
                continue;
            }
            String newNumTurma = numTurma;
            if (numTurma.contains("EP")) {
                newNumTurma = numTurma.replace("EP", "10");
            }
            try {
                turma.setNumeroTurma(Integer.parseInt(newNumTurma));
            } catch (NumberFormatException e) {
                System.out.println("INFO-ERROR   :  TURMA NÃO IMPORTADA " + codCurso + numTurma);
                continue;
            }
            if (inicio != null || fim != null) {
                local = corrigirLocal(local);
                Organizacao organizacao = organizacaoDAO.findBySigla(local);
                if (organizacao != null) {
                    turma.setResponsavelId(organizacao.getId());
                }
                Fase fase = new Fase();
                fase.setDataInicio(inicio);
                fase.setDataTermino(fim);
                fase.setDescricao("Presencial");
                if (organizacao != null) {
                    fase.setLocal(organizacao);
                }
                turma.addFase(fase);
            }
            if (inicio2 != null || fim2 != null) {
                local2 = corrigirLocal(local2);
                Organizacao organizacao2 = organizacaoDAO.findBySigla(local2);
                Fase fase2 = new Fase();
                fase2.setDataInicio(inicio2);
                fase2.setDataTermino(fim2);
                fase2.setDescricao("Prática");
                if (organizacao2 != null) {
                    fase2.setLocal(organizacao2);
                }
                turma.addFase(fase2);
            }
            if (inicio3 != null || fim3 != null) {
                local3 = corrigirLocal(local3);
                Organizacao organizacao3 = organizacaoDAO.findBySigla(local3);
                Fase fase3 = new Fase();
                fase3.setDataInicio(inicio3);
                fase3.setDataTermino(fim3);
                fase3.setDescricao("Prática");
                if (organizacao3 != null) {
                    fase3.setLocal(organizacao3);
                }
                turma.addFase(fase3);
            }
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            Calendar calendar = Calendar.getInstance();
            Periodo periodoIndicacao = new Periodo();
            try {
                periodoIndicacao.setDataInicio(df.parse("01/01/2013"));
                calendar.setTime(turma.getDataInicio());
                calendar.add(Calendar.DAY_OF_YEAR, -30);
                periodoIndicacao.setDataTermino(calendar.getTime());
            } catch (ParseException ex) {
                Logger.getLogger(ImportTurmasImplEfetivasFromTabelao.class.getName()).log(Level.SEVERE, null, ex);
            }
            if (ativado.equals("C")) {
                turma.setCancelado(true);
            }
            turma.setPeriodoIndicacao(periodoIndicacao);
            if ((turma.getCurso() != null) && (turma.getExercicio() != null)) {
                Long turmaId = turmaDAO.create(turma);
                TurmaEfetiva turmaCriada = (TurmaEfetiva) turmaDAO.find(turmaId);
                // TurmaEfetiva turmaCriada = new TurmaEfetiva(); //retirar essa linha e descomentar as duas de cima
                distribuirVagas(codTabelao, turmaCriada, conn);
                recuperarIndicacoes(codTabelao, turmaCriada, conn);
                recuperarInstrutores(codTabelao, turmaCriada, conn);
                if (turma.isCancelado() == false) {
                // recuperarMatriculas(codTabelao, turmaCriada, conn);
                }
                recuperarAnotacoes(codTabelao, turmaCriada, conn);
                recuperarAnotacoesPagina(codTabelao, turmaCriada, conn);
                recuperarDocumentos(codCurso, numTurma, turmaCriada, conn);
                Long time = new Date().getTime();
                while (new Date().getTime() - time < 200) {
                }
                System.out.println(i++ + "-------------------------------------------------------------------------");
            } else {
                System.out.println("turma não cadastrada " + codCurso + " - " + codTabelao + " - " + numTurma);
            }
        }
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(ImportTurmasImplEfetivasFromTabelao.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DAOException ex) {
        Logger.getLogger(ImportTurmasImplEfetivasFromTabelao.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : Fase(com.tomasio.projects.trainning.model.Fase) HibernateCursoDAO(com.tomasio.projects.trainning.dao.HibernateCursoDAO) CursoDAO(com.tomasio.projects.trainning.dao.CursoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) HibernateOrganizacaoDAO(com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) HibernatePlanejamentoDAO(com.tomasio.projects.trainning.dao.HibernatePlanejamentoDAO) HibernatePlanejamentoDAO(com.tomasio.projects.trainning.dao.HibernatePlanejamentoDAO) PlanejamentoDAO(com.tomasio.projects.trainning.dao.PlanejamentoDAO) Curso(com.tomasio.projects.trainning.model.Curso) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) TurmaEfetiva(com.tomasio.projects.trainning.model.TurmaEfetiva) Calendar(java.util.Calendar) HibernateOrganizacaoDAO(com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO) Periodo(com.tomasio.projects.trainning.model.Periodo) Date(java.util.Date) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with HibernateTurmaDAO

use of com.tomasio.projects.trainning.dao.HibernateTurmaDAO in project trainning by fernandotomasio.

the class MigrateFromPlanejamentoToItemPlanejamento method main.

public static void main(String[] args) throws DAOException {
    TreinamentoSolicitadoDAO dao = new HibernateTreinamentoSolicitadoDAO();
    TurmaDAO turmaDAO = new HibernateTurmaDAO();
    List<TreinamentoSolicitadoDTO> treinamentos = dao.findAll(null, null, null, null);
    List<TurmaPlanejadaDTO> turmas = turmaDAO.findAllTurmasPlanejadas(1L, null, null, null);
    PlanejamentoDAO planejamentoDAO = new HibernatePlanejamentoDAO();
    List<Long> ids = new ArrayList<Long>();
    for (TreinamentoSolicitadoDTO treinamentoSolicitadoDTO : treinamentos) {
        // PlanejamentoDTO p = planejamentoDAO.find(treinamentoSolicitadoDTO.getPlanejamento().getId());
        // treinamentoSolicitadoDTO.setPlanejamento(p);
        dao.update(treinamentoSolicitadoDTO);
        // System.out.println(treinamentoSolicitadoDTO.getPlanejamento().getExercicio());
        // System.out.println(treinamentoSolicitadoDTO.getPlanejamento().getExercicio());
        System.out.println("-------------------------------------------------\n\n");
    // treinamentoSolicitadoDTO.setPlanejamento(null); // para não encher a coleção e provocar overflow stack
    }
// List<Long> turmasIds = new ArrayList<Long>();
// for (TurmaDTO turma : turmas) {
// turmasIds.add(turma.getId());
// }
// 
// for (Long id : turmasIds) {
// PlanejamentoDTO p = planejamentoDAO.find(1L);
// TurmaPlanejadaDTO turma = (TurmaPlanejadaDTO) turmaDAO.find(id);
// turma.setPlanejamento(p);
// turmaDAO.update(turma);
// System.out.println(turma.getPlanejamento().getExercicio());
// 
// System.out.println(turma.getPlanejamento().getExercicio());
// }
// 
}
Also used : ArrayList(java.util.ArrayList) HibernateTreinamentoSolicitadoDAO(com.tomasio.projects.trainning.dao.HibernateTreinamentoSolicitadoDAO) TreinamentoSolicitadoDAO(com.tomasio.projects.trainning.dao.TreinamentoSolicitadoDAO) HibernatePlanejamentoDAO(com.tomasio.projects.trainning.dao.HibernatePlanejamentoDAO) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) HibernateTreinamentoSolicitadoDAO(com.tomasio.projects.trainning.dao.HibernateTreinamentoSolicitadoDAO) PlanejamentoDAO(com.tomasio.projects.trainning.dao.PlanejamentoDAO) HibernatePlanejamentoDAO(com.tomasio.projects.trainning.dao.HibernatePlanejamentoDAO) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) TreinamentoSolicitadoDTO(com.tomasio.projects.trainning.dto.TreinamentoSolicitadoDTO) TurmaPlanejadaDTO(com.tomasio.projects.trainning.dto.TurmaPlanejadaDTO)

Aggregations

HibernateTurmaDAO (com.tomasio.projects.trainning.dao.HibernateTurmaDAO)3 TurmaDAO (com.tomasio.projects.trainning.dao.TurmaDAO)3 HibernatePlanejamentoDAO (com.tomasio.projects.trainning.dao.HibernatePlanejamentoDAO)2 PlanejamentoDAO (com.tomasio.projects.trainning.dao.PlanejamentoDAO)2 DAOException (com.tomasio.projects.trainning.exception.DAOException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 AlfrescoContentDAO (com.tomasio.projects.trainning.dao.AlfrescoContentDAO)1 ContentDAO (com.tomasio.projects.trainning.dao.ContentDAO)1 CursoDAO (com.tomasio.projects.trainning.dao.CursoDAO)1 HibernateCursoDAO (com.tomasio.projects.trainning.dao.HibernateCursoDAO)1 HibernateOrganizacaoDAO (com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO)1 HibernateTreinamentoSolicitadoDAO (com.tomasio.projects.trainning.dao.HibernateTreinamentoSolicitadoDAO)1 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)1 TreinamentoSolicitadoDAO (com.tomasio.projects.trainning.dao.TreinamentoSolicitadoDAO)1 ContentDTO (com.tomasio.projects.trainning.dto.ContentDTO)1 DocumentDTO (com.tomasio.projects.trainning.dto.DocumentDTO)1 FolderDTO (com.tomasio.projects.trainning.dto.FolderDTO)1 TreinamentoSolicitadoDTO (com.tomasio.projects.trainning.dto.TreinamentoSolicitadoDTO)1 TurmaPlanejadaDTO (com.tomasio.projects.trainning.dto.TurmaPlanejadaDTO)1