Search in sources :

Example 6 with Area

use of com.tomasio.projects.trainning.model.Area in project trainning by fernandotomasio.

the class PlanningServiceSimpleImpl method findAllAreasSobResponsabilidade.

@Override
@Transactional(readOnly = true)
public AreaDTO[] findAllAreasSobResponsabilidade(Long planejamentoId, Long organizacaoId) {
    AreaDAO areaDAO = factory.getAreaDAO();
    ResponsavelAreaDTO[] responsaveisAreas = findAllResponsaveisAreas(planejamentoId, organizacaoId);
    List<AreaDTO> areasSobResponsabilidadeDireta = new ArrayList<AreaDTO>();
    List<AreaDTO> areasSobResponsabilidade = new ArrayList<AreaDTO>();
    if (responsaveisAreas.length != 0) {
        // Pega todas as áreas que a organização é responsável (configurado no planejamento)
        for (ResponsavelAreaDTO responsavelArea : responsaveisAreas) {
            areasSobResponsabilidadeDireta.add(responsavelArea.getArea());
        }
        // Pega todas as áreas dos cursos do planejamento
        List<Area> areasPlanejamento = new ArrayList<Area>();
        try {
            areasPlanejamento = areaDAO.findAllAreasByPlanejamento(planejamentoId);
        } catch (DAOException ex) {
            Logger.getLogger(PlanningServiceSimpleImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (Area areaPlanejamento : areasPlanejamento) {
            // Monta a hierarquia acima da área
            List<AreaDTO> hierarquiaAreaPlanejamento = arrangeAreasByHierarchyUp(areaPlanejamento.createDTO());
            // Adiciona na lista todas as áreas dos cursos na qual a responsabilidade direta faz parte de suas hierarquias
            for (AreaDTO areaSobResponsabilidadeDireta : areasSobResponsabilidadeDireta) {
                if (hierarquiaAreaPlanejamento.contains(areaSobResponsabilidadeDireta) && !areasSobResponsabilidade.contains(areaPlanejamento)) {
                    areasSobResponsabilidade.add(areaPlanejamento.createDTO());
                }
            }
        }
    }
    return areasSobResponsabilidade.toArray(new AreaDTO[areasSobResponsabilidade.size()]);
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) ResponsavelArea(com.tomasio.projects.trainning.model.ResponsavelArea) Area(com.tomasio.projects.trainning.model.Area) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Area

use of com.tomasio.projects.trainning.model.Area in project trainning by fernandotomasio.

the class TrainningServiceSimpleImpl method findAllAreasExcept.

@Override
@Transactional(readOnly = true)
public AreaDTO[] findAllAreasExcept(Long areaId) {
    AreaDAO dao = factory.getAreaDAO();
    AreaDTO[] areasArray = null;
    try {
        List<Area> areas = dao.findAll();
        if (areas != null) {
            List<Area> filtered_areas = new ArrayList<Area>();
            for (Area area : areas) {
                if (!area.getId().equals(areaId)) {
                    filtered_areas.add(area);
                }
            }
            areasArray = new AreaDTO[filtered_areas.size()];
            for (int i = 0; i < filtered_areas.size(); i++) {
                areasArray[i] = filtered_areas.get(i).createDTO();
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return areasArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Area(com.tomasio.projects.trainning.model.Area) CoreException(com.tomasio.projects.trainning.exeption.CoreException) ArrayList(java.util.ArrayList) AreaDTO(com.tomasio.projects.trainning.dto.AreaDTO) AreaDAO(com.tomasio.projects.trainning.dao.AreaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Area

use of com.tomasio.projects.trainning.model.Area in project trainning by fernandotomasio.

the class TrainningServiceSimpleImpl method findAllAreasByPlanejamentoId.

@Override
@Transactional(readOnly = true)
public AreaDTO[] findAllAreasByPlanejamentoId(Long planejamentoId) {
    AreaDAO dao = factory.getAreaDAO();
    AreaDTO[] areasArray = null;
    try {
        List<Area> areas = dao.findAllAreasByPlanejamento(planejamentoId);
        if (areas != null) {
            areasArray = new AreaDTO[areas.size()];
            for (int i = 0; i < areas.size(); i++) {
                areasArray[i] = areas.get(i).createDTO();
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return areasArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Area(com.tomasio.projects.trainning.model.Area) CoreException(com.tomasio.projects.trainning.exeption.CoreException) AreaDTO(com.tomasio.projects.trainning.dto.AreaDTO) AreaDAO(com.tomasio.projects.trainning.dao.AreaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Area

use of com.tomasio.projects.trainning.model.Area in project trainning by fernandotomasio.

the class TrainningServiceSimpleImpl method searchArea.

@Override
@Transactional(readOnly = true)
public AreaDTO[] searchArea(String term) {
    AreaDAO dao = factory.getAreaDAO();
    AreaDTO[] areasArray = null;
    try {
        List<Area> areas = dao.search(term);
        if (areas != null) {
            areasArray = new AreaDTO[areas.size()];
            for (int i = 0; i < areas.size(); i++) {
                areasArray[i] = areas.get(i).createDTO();
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return areasArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Area(com.tomasio.projects.trainning.model.Area) CoreException(com.tomasio.projects.trainning.exeption.CoreException) AreaDTO(com.tomasio.projects.trainning.dto.AreaDTO) AreaDAO(com.tomasio.projects.trainning.dao.AreaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Area

use of com.tomasio.projects.trainning.model.Area in project trainning by fernandotomasio.

the class TrainningServiceSimpleImpl method createArea.

@Override
@Transactional
public Long createArea(AreaDTO dto) {
    AreaDAO dao = factory.getAreaDAO();
    Area _area = new Area(dto);
    Long id = null;
    try {
        id = dao.create(_area);
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    return id;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Area(com.tomasio.projects.trainning.model.Area) CoreException(com.tomasio.projects.trainning.exeption.CoreException) AreaDAO(com.tomasio.projects.trainning.dao.AreaDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DAOException (com.tomasio.projects.trainning.exception.DAOException)10 Area (com.tomasio.projects.trainning.model.Area)10 Transactional (org.springframework.transaction.annotation.Transactional)9 AreaDAO (com.tomasio.projects.trainning.dao.AreaDAO)7 CoreException (com.tomasio.projects.trainning.exeption.CoreException)7 AreaDTO (com.tomasio.projects.trainning.dto.AreaDTO)4 ArrayList (java.util.ArrayList)3 ResponsavelArea (com.tomasio.projects.trainning.model.ResponsavelArea)2 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1