packagetecnig.system.server.beans;importjavax.persistence.*;importtecnig.system.server.*;importtecnig.system.datastore.*;importtecnig.system.utils.*;importtecnig.system.xml.*;/** * Classe (event handler) que implementa o caso de uso de login. * * @author [email removido] */publicfinalclassLogin{/** * Construtor default requerido. */publicLogin(){}/** * Processa o evento de negócio. */publicBusinessResultexecute(BusinessEventevent){try{EntityManagerem=(EntityManager)ServiceLocator.lookup("EM");// Extrai dadosXMLdata=(XML)event.getData();Stringlogin=data.getAttribute("login").asString();Stringsenha=data.getAttribute("senha").asString();// Valida dadosif(login==null||login.equals("")){thrownewValidationException("Login não informado");}if(senha==null||senha.equals("")){thrownewValidationException("Senha não informada");}// PersistênciaEntidadeentidade=(Entidade)em.createNamedQuery("Entidade.findByLogin").setParameter("login",login).getSingleResult();// Avalia regras de negócioif(!entidade.isAtivado()){thrownewRulesetException("Login desativado");}if(!entidade.getSenha().equals(CryptoUtils.encrypt(senha))){thrownewRulesetException("Senha inválida");}// Persistênciaentidade.setUltimoLogin(TypeUtils.now());em.merge(entidade);// Produz resultadoXMLresult=newXML("entidade");result.addAttribute("entidadeId",entidade.getEntidadeId());result.addAttribute("nome",entidade.getNome());result.addAttribute("nomeCompleto",entidade.getNomeCompleto());returnnewBusinessResult(result);}catch(Throwablee){thrownewBusinessException("Erro na tentativa de login",e);}}}