...
 
Commits (2)
......@@ -24,13 +24,14 @@ import redis.clients.jedis.Jedis;
@Stateless
@LocalBean
public class FacadeDao implements FacadeDaoLocal {
Jedis jedis = null;
//private Jedis jedis = JedisConnection.getJedisInstance();
private IDocumentSession session = DocumentStoreHolder.getStore().openSession();
private final static Logger LOGGER = Logger.getLogger("logger");
public FacadeDao() {
// TODO Auto-generated constructor stub
jedis = new Jedis("localhost", 6379);
}
public Usuario altaUsuario(String nombre, String mail){
......@@ -103,6 +104,21 @@ public class FacadeDao implements FacadeDaoLocal {
}
}
public Boolean existeCacheMail(String email) {
if (jedis.exists(email)) {
return true;
}else {
return false;
}
}
public String persistirCacheMail(String email, String value) {
String response = jedis.set(email, value);
jedis.expire(email, 120);
return response;
}
@Override
public DataComentario altaComentario(String id, String texto, String emailUsuario) {
......
......@@ -30,4 +30,8 @@ public interface FacadeDaoLocal {
public DataComentario obtenerFullComentario(String idComentario);
public Boolean existeCacheMail(String email);
public String persistirCacheMail(String email, String value);
}
......@@ -28,16 +28,30 @@ public class FacadeNegocio implements FacadeNegocioLocal {
// TODO Auto-generated constructor stub
}
private Boolean existeEmail(String email) {
Boolean response = false;
if ( dao.existeCacheMail(email)) {
response = true;
}else {
response= dao.existeEmail(email);
if (response) {
dao.persistirCacheMail(email, "active");
}
}
return response;
}
public DataUsuario altaUsuario(String nombre, String mail) throws Exception {
if(dao.existeEmail(mail)) {
if(existeEmail(mail)) {
throw new Exception("El email "+mail+" ya esta en uso");
} else {
Usuario u = dao.altaUsuario(nombre, mail);
dao.persistirCacheMail(mail, nombre);
return new DataUsuario(u.getId(),u.getNombre(), u.getEmail());
}
}
public DataComentario altaComentario(String id, String texto, String emailUsuario) throws Exception {
if(dao.existeEmail(emailUsuario)) {
if(existeEmail(emailUsuario)) {
DataComentario c = dao.altaComentario(id, texto, emailUsuario);
return c;//new DataComentario(c.getId(),c.getTexto(), c.getEmailUsuario());
} else {
......
......@@ -20,4 +20,6 @@ public interface FacadeNegocioLocal {
public String altaComentarioRedis(String key, String value);
public String obtenerComentarioRedis(String key);
public Boolean existeComentarioRedis(String key);
}