use of com.tomasio.projects.trainning.dao.NetworkGroupDAO in project trainning by fernandotomasio.
the class UserServiceSimpleImpl method findAllRoleGroups.
@Override
public NetworkGroupDTO[] findAllRoleGroups() {
NetworkGroupDAO dao = factory.getNetworkGroupDAO();
NetworkGroupDTO[] groupsArray = null;
try {
List<NetworkGroupDTO> groups = dao.findAllRoles();
if (groups != null) {
groupsArray = new NetworkGroupDTO[groups.size()];
groups.toArray(groupsArray);
}
} catch (DAOException ex) {
throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
}
return groupsArray;
}
use of com.tomasio.projects.trainning.dao.NetworkGroupDAO in project trainning by fernandotomasio.
the class TestesDAO method main.
public static void main(String[] args) throws DAOException {
@SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext("persist-context.xml");
DAOFactory factory = (DAOFactory) context.getBean("daoFactory");
NetworkGroupDAO dao = factory.getNetworkGroupDAO();
SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
Session session = transactionManager.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
NetworkGroupDTO group = dao.findRole("OperadorLocal");
group.getMembers().add("uid=tasdfasd,ou=people");
dao.update(group);
tx.commit();
session.close();
}
use of com.tomasio.projects.trainning.dao.NetworkGroupDAO in project trainning by fernandotomasio.
the class UserServiceSimpleImpl method findAllOrganizationsGroups.
@Override
public NetworkGroupDTO[] findAllOrganizationsGroups() {
NetworkGroupDAO dao = factory.getNetworkGroupDAO();
NetworkGroupDTO[] groupsArray = null;
try {
List<NetworkGroupDTO> groups = dao.findAllOrganizations();
if (groups != null) {
groupsArray = new NetworkGroupDTO[groups.size()];
groups.toArray(groupsArray);
}
} catch (DAOException ex) {
throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
}
return groupsArray;
}
use of com.tomasio.projects.trainning.dao.NetworkGroupDAO in project trainning by fernandotomasio.
the class UserServiceSimpleImpl method findOrganizationGroup.
@Override
public NetworkGroupDTO findOrganizationGroup(String id) {
NetworkGroupDAO dao = factory.getNetworkGroupDAO();
NetworkGroupDTO group = null;
try {
group = dao.findOrganization(id);
} catch (DAOException ex) {
throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
}
return group;
}
use of com.tomasio.projects.trainning.dao.NetworkGroupDAO in project trainning by fernandotomasio.
the class UserServiceSimpleImpl method updateUser.
@Override
@Transactional(readOnly = true)
public void updateUser(NetworkUserDTO user, String[] roles) {
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);
}
}
// REMOVER DE TODAS AS ROLES
List<NetworkGroupDTO> roleGroups = groupDAO.findAllRoles();
for (NetworkGroupDTO roleGroup : roleGroups) {
NetworkGroupDTO r = groupDAO.findRole(roleGroup.getNome());
r.getMembers().remove(oldUser.getId());
groupDAO.update(r);
}
// ADICIONAR NOVAS ROLES
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());
}
}
Aggregations