Search in sources :

Example 1 with NetworkUserDAO

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

the class UserServiceSimpleImpl method removeUser.

@Override
public void removeUser(String uid) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    try {
        NetworkUserDTO user = userDAO.find(uid);
        userDAO.remove(uid);
        NetworkGroupDTO organizationGroup = groupDAO.findOrganization(user.getOrganizacao());
        if (organizationGroup != null) {
            organizationGroup.getMembers().remove(user.getId());
            if (organizationGroup.getMembers().size() > 0) {
                groupDAO.update(organizationGroup);
            } else {
                groupDAO.removeOrganization(user.getOrganizacao());
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO)

Example 2 with NetworkUserDAO

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

the class UserServiceSimpleImpl method updateUser.

@Override
@Transactional(readOnly = true)
public void updateUser(NetworkUserDTO user) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        NetworkUserDTO oldUser = userDAO.find(user.getLogin());
        userDAO.update(user);
        if (!oldUser.getOrganizacao().equals(user.getOrganizacao())) {
            // REMOVER DO GRUPO DA ORGANIZAÇÃO ANTIGA
            NetworkGroupDTO oldOrganizationGroup = groupDAO.findOrganization(oldUser.getOrganizacao());
            if (oldOrganizationGroup != null) {
                oldOrganizationGroup.getMembers().remove(oldUser.getId());
                if (oldOrganizationGroup.getMembers().size() > 0) {
                    groupDAO.update(oldOrganizationGroup);
                } else {
                    groupDAO.removeOrganization(oldUser.getOrganizacao());
                }
            }
            // ADICIONAR AO GRUPO DA ORGANIZAÇÃO NOVA
            Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
            NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
            if (organizationGroup == null) {
                organizationGroup = new NetworkGroupDTO();
                organizationGroup.setNome(organizacao.getSigla());
                organizationGroup.setDescricao(organizacao.getNome());
                organizationGroup.getMembers().add(user.getId());
                groupDAO.createOrganization(organizationGroup);
            } else {
                organizationGroup.getMembers().add(user.getId());
                groupDAO.update(organizationGroup);
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with NetworkUserDAO

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

the class UserServiceSimpleImpl method createUser.

@Override
@Transactional(readOnly = true)
public void createUser(NetworkUserDTO user) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        userDAO.create(user);
        user = userDAO.find(user.getLogin());
        NetworkGroupDTO roleGroup = groupDAO.findRole("OperadorLocal");
        Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
        NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
        if (organizationGroup == null) {
            organizationGroup = new NetworkGroupDTO();
            organizationGroup.setNome(organizacao.getSigla());
            organizationGroup.setDescricao(organizacao.getNome());
            organizationGroup.getMembers().add(user.getId());
            groupDAO.createOrganization(organizationGroup);
        } else {
            organizationGroup.getMembers().add(user.getId());
            groupDAO.update(organizationGroup);
        }
        roleGroup.getMembers().add(user.getId());
        groupDAO.update(roleGroup);
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with NetworkUserDAO

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

the class UserServiceSimpleImpl method createUser.

@Override
@Transactional(readOnly = true)
public void createUser(NetworkUserDTO user, String[] roles) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        userDAO.create(user);
        user = userDAO.find(user.getLogin());
        Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
        NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
        if (organizationGroup == null) {
            organizationGroup = new NetworkGroupDTO();
            organizationGroup.setNome(organizacao.getSigla());
            organizationGroup.setDescricao(organizacao.getNome());
            organizationGroup.getMembers().add(user.getId());
            groupDAO.createOrganization(organizationGroup);
        } else {
            organizationGroup.getMembers().add(user.getId());
            groupDAO.update(organizationGroup);
        }
        if (roles != null) {
            for (String role : roles) {
                NetworkGroupDTO roleGroup = groupDAO.findRole(role);
                roleGroup.getMembers().add(user.getId());
                groupDAO.update(roleGroup);
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with NetworkUserDAO

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

the class UserServiceSimpleImpl method authenticate.

@Override
public NetworkUserDTO authenticate(String uid, String password) {
    NetworkUserDAO dao = factory.getNetworkUserDAO();
    NetworkUserDTO user = null;
    try {
        user = dao.authenticate(uid, password);
    } catch (DAOException ex) {
        ex.printStackTrace();
    }
    return user;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO)

Aggregations

NetworkUserDAO (com.tomasio.projects.trainning.dao.NetworkUserDAO)12 DAOException (com.tomasio.projects.trainning.exception.DAOException)11 NetworkUserDTO (com.tomasio.projects.trainning.dto.NetworkUserDTO)9 CoreException (com.tomasio.projects.trainning.exeption.CoreException)9 NetworkGroupDAO (com.tomasio.projects.trainning.dao.NetworkGroupDAO)5 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)5 NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)5 Organizacao (com.tomasio.projects.trainning.model.Organizacao)5 Transactional (org.springframework.transaction.annotation.Transactional)4 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1