Search in sources :

Example 1 with DominioAprendizagemDTO

use of com.tomasio.projects.trainning.dto.DominioAprendizagemDTO in project trainning by fernandotomasio.

the class TeachingDocumentsServiceSimpleImpl method findAllDominiosAprendizagem.

@Override
@Transactional(readOnly = true)
public DominioAprendizagemDTO[] findAllDominiosAprendizagem() {
    NivelAprendizagemDAO dao = factory.getNivelAprendizagemDAO();
    DominioAprendizagemDTO[] dominiosArray = null;
    try {
        List<DominioAprendizagem> dominios = dao.findAllDominiosAprendizagem();
        if (dominios != null) {
            dominiosArray = new DominioAprendizagemDTO[dominios.size()];
            for (int i = 0; i < dominios.size(); i++) {
                dominiosArray[i] = dominios.get(i).createDTO();
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return dominiosArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) DominioAprendizagemDTO(com.tomasio.projects.trainning.dto.DominioAprendizagemDTO) DominioAprendizagem(com.tomasio.projects.trainning.model.DominioAprendizagem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DominioAprendizagemDTO

use of com.tomasio.projects.trainning.dto.DominioAprendizagemDTO in project trainning by fernandotomasio.

the class ImportInstrutoresCSV method execute.

@Override
public void execute() {
    BufferedReader br = null;
    String line;
    String cvsSplitBy = ",";
    Map<String, DominioAprendizagemDTO> dominiosMap = new HashMap<String, DominioAprendizagemDTO>();
    Map<String, List<String>> verbosMap = new HashMap<String, List<String>>();
    try {
        br = new BufferedReader(new FileReader(new ClassPathResource("instrutores.csv").getFile()));
        while ((line = br.readLine()) != null) {
            // use comma as separator
            String[] data = line.split(cvsSplitBy);
            String pessoaId = data[0];
            String cursoId = data[1];
            CursoDTO curso = trainningService.findCurso(Long.parseLong(cursoId));
            PessoaDTO pessoa = organizationalService.findPessoa(Long.parseLong(pessoaId));
            HabilitacaoInstrutorEfetivaDTO dto = new HabilitacaoInstrutorEfetivaDTO();
            dto.setCoordenador(false);
            dto.setSombra(false);
            dto.setCurso(curso);
            dto.setPessoa(pessoa);
            PeriodoDTO periodo = new PeriodoDTO();
            periodo.setDataInicio(new Date());
            dto.setPeriodo(periodo);
            instructorsService.createHabilitacaoInstrutor(dto);
            System.out.println("IMPORTADO " + curso.getCodigo());
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    System.out.println("Done");
}
Also used : HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Date(java.util.Date) PessoaDTO(com.tomasio.projects.trainning.dto.PessoaDTO) PeriodoDTO(com.tomasio.projects.trainning.dto.PeriodoDTO) BufferedReader(java.io.BufferedReader) DominioAprendizagemDTO(com.tomasio.projects.trainning.dto.DominioAprendizagemDTO) List(java.util.List) FileReader(java.io.FileReader) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO) HabilitacaoInstrutorEfetivaDTO(com.tomasio.projects.trainning.dto.HabilitacaoInstrutorEfetivaDTO)

Example 3 with DominioAprendizagemDTO

use of com.tomasio.projects.trainning.dto.DominioAprendizagemDTO in project trainning by fernandotomasio.

the class ImportNiveisAprendizagemCSV method execute.

@Override
public void execute() {
    BufferedReader br = null;
    String line;
    String cvsSplitBy = "\\|";
    Map<String, DominioAprendizagemDTO> dominiosMap = new HashMap<String, DominioAprendizagemDTO>();
    Map<String, List<String>> verbosMap = new HashMap<String, List<String>>();
    try {
        br = new BufferedReader(new FileReader(new ClassPathResource("verbos.csv").getFile()));
        while ((line = br.readLine()) != null) {
            // use comma as separator
            String[] data = line.split(cvsSplitBy);
            String verbo = data[0];
            String nivel = data[1];
            List<String> verbos = verbosMap.get(nivel);
            if (verbos != null) {
                verbos.add(verbo);
            } else {
                verbos = new ArrayList<String>();
                verbos.add(verbo);
                verbosMap.put(nivel, verbos);
            }
        }
        WorkbookSettings ws = new WorkbookSettings();
        ws.setEncoding("Cp1252");
        Workbook workbook = Workbook.getWorkbook(new ClassPathResource("niveis.xls").getInputStream(), ws);
        Sheet sheet = workbook.getSheet(0);
        for (int i = 0; i < sheet.getRows(); i++) {
            String nome = sheet.getCell(0, i).getContents();
            String codigo = sheet.getCell(1, i).getContents();
            String descricao = sheet.getCell(2, i).getContents();
            String dominio = sheet.getCell(3, i).getContents();
            NivelAprendizagemDTO nivel = new NivelAprendizagemDTO();
            nivel.setNome(nome);
            nivel.setCodigo(codigo);
            nivel.setDescricao(descricao);
            List<String> verbos = verbosMap.get(nome);
            String[] verbosArray = new String[verbos.size()];
            for (int j = 0; j < verbos.size(); j++) {
                verbosArray[j] = verbos.get(j);
            }
            nivel.setVerbos(verbosArray);
            DominioAprendizagemDTO dominioAprendizagem = dominiosMap.get(dominio);
            if (dominioAprendizagem == null) {
                DominioAprendizagemDTO d = new DominioAprendizagemDTO();
                d.setDescricao(dominio);
                Long dominioId = service.createDominioAprendizagem(d);
                d = service.findDominioAprendizagem(dominioId);
                dominiosMap.put(dominio, d);
                nivel.setDominioAprendizagem(d);
            } else {
                nivel.setDominioAprendizagem(dominioAprendizagem);
            }
            service.createNivelAprendizagem(nivel);
            System.out.println(nome);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BiffException ex) {
        Logger.getLogger(ImportNiveisAprendizagemCSV.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    System.out.println("Done");
}
Also used : BiffException(jxl.read.biff.BiffException) NivelAprendizagemDTO(com.tomasio.projects.trainning.dto.NivelAprendizagemDTO) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) WorkbookSettings(jxl.WorkbookSettings) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Workbook(jxl.Workbook) BufferedReader(java.io.BufferedReader) DominioAprendizagemDTO(com.tomasio.projects.trainning.dto.DominioAprendizagemDTO) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) Sheet(jxl.Sheet)

Example 4 with DominioAprendizagemDTO

use of com.tomasio.projects.trainning.dto.DominioAprendizagemDTO in project trainning by fernandotomasio.

the class DominioAprendizagem method createDTO.

public DominioAprendizagemDTO createDTO() {
    DominioAprendizagemDTO dto = new DominioAprendizagemDTO();
    dto.setDescricao(descricao);
    dto.setId(id);
    return dto;
}
Also used : DominioAprendizagemDTO(com.tomasio.projects.trainning.dto.DominioAprendizagemDTO)

Aggregations

DominioAprendizagemDTO (com.tomasio.projects.trainning.dto.DominioAprendizagemDTO)4 BufferedReader (java.io.BufferedReader)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 CursoDTO (com.tomasio.projects.trainning.dto.CursoDTO)1 HabilitacaoInstrutorEfetivaDTO (com.tomasio.projects.trainning.dto.HabilitacaoInstrutorEfetivaDTO)1 NivelAprendizagemDTO (com.tomasio.projects.trainning.dto.NivelAprendizagemDTO)1 PeriodoDTO (com.tomasio.projects.trainning.dto.PeriodoDTO)1 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)1 DAOException (com.tomasio.projects.trainning.exception.DAOException)1 CoreException (com.tomasio.projects.trainning.exeption.CoreException)1 DominioAprendizagem (com.tomasio.projects.trainning.model.DominioAprendizagem)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Sheet (jxl.Sheet)1 Workbook (jxl.Workbook)1