Beispiel #1
0
 @Override
 public void modificarColorAV(long idAV, String color) {
   try {
     AV av = avDAO.traerAV(idAV);
     if (av != null && !color.equals(av.getColor())) {
       av.setColor(color);
       avDAO.actualizarAV(av);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Beispiel #2
0
 @Override
 public void eliminarAlerta(long idAlerta, long idAV) throws NoExisteElAV {
   String tenant = getTenant(idAV);
   if (tenant != null) {
     avDAOTenant.open(tenant);
     Alerta alerta = avDAOTenant.buscarAlerta(idAlerta);
     avDAOTenant.eliminarAlerta(alerta);
     avDAOTenant.close(tenant);
   } else {
     throw new exceptions.NoExisteElAV();
   }
 }
Beispiel #3
0
  @Override
  public void marcarNotificacionComoLeida(long idNoti, long idAV) throws Exception {
    String tenant = getTenant(idAV);
    if (tenant != null) {
      avDAOTenant.open(tenant);
      Notificacion noti = avDAOTenant.buscarNotificacion(idNoti, tenant);
      noti.setLeido(true);
      avDAOTenant.actualizarNotificacion(noti, tenant);
      avDAOTenant.close(tenant);

    } else {
      throw new Exception("No existe un AV con id: " + idAV);
    }
  }
Beispiel #4
0
  public void compartirAV(long idAV, String nickname) {
    Usuario usu = usuarioDAO.buscarUsuario(nickname);
    AV av = avDAO.traerAV(idAV);

    List<Usuario> usuComp = av.getUsuariosCompartidos();
    usuComp.add(usu);
    av.setUsuariosCompartidos(usuComp);

    List<AV> avsComp = usu.getAVcompartidos();
    avsComp.add(av);
    usu.setAVcompartidos(avsComp);

    usuarioDAO.actualizarUsuario(usu);
    avDAO.actualizarAV(av);
  }
Beispiel #5
0
 @Override
 public void eliminarNotificacion(long idAV, long idNoti) throws Exception {
   if (idAV > 0) {
     String tenant = getTenant(idAV);
     if (tenant != null) {
       avDAOTenant.open(tenant);
       avDAOTenant.eliminarNotificacion(idNoti, tenant);
       avDAOTenant.close(tenant);
     } else {
       throw new Exception("No existe un AV con id: " + idAV);
     }
   } else {
     throw new Exception("Valor de idAV invalido: " + idAV);
   }
 }
Beispiel #6
0
 @Override
 public List<DataNotificacion> listaNotificacionesNoLeidas(long idAV) throws NoExisteElAV {
   String tenant = getTenant(idAV);
   if (tenant != null) {
     avDAOTenant.open(tenant);
     List<Notificacion> notis = avDAOTenant.buscarNotificacionesNoLeidas();
     List<DataNotificacion> dns = new ArrayList<>();
     for (Notificacion n : notis) {
       dns.add(n.getDataNotificacion());
     }
     avDAOTenant.close(tenant);
     return dns;
   } else {
     throw new exceptions.NoExisteElAV();
   }
 }
Beispiel #7
0
 @Override
 public void crearNotificacion(String texto, long idAV) throws Exception {
   if (idAV > 0) {
     String tenant = getTenant(idAV);
     if (tenant != null) {
       avDAOTenant.open(tenant);
       Notificacion noti = new Notificacion(texto);
       avDAOTenant.persistirNotificacion(noti, tenant);
       avDAOTenant.close(tenant);
     } else {
       throw new Exception("No existe un AV con id: " + idAV);
     }
   } else {
     throw new Exception("Valor de idAV invalido: " + idAV);
   }
 }
Beispiel #8
0
  @Override
  public DataAV traerAV(long idAV) throws NoExisteElAV {
    AV av = avDAO.traerAV(idAV);

    if (av == null) throw new exceptions.NoExisteElAV();

    return av.getDataAV();
  }
Beispiel #9
0
 private String getTenant(long idAV) {
   AV av = avDAO.traerAV(idAV);
   if (av != null) {
     return av.getUsuarioCreador().getNick() + "_" + av.getNombreAV();
   } else {
     return null;
   }
 }
Beispiel #10
0
 @Override
 public void modificarNotificacion(long idAV, long idNoti, String texto, boolean leido)
     throws Exception {
   if (idAV > 0) {
     String tenant = getTenant(idAV);
     if (tenant != null) {
       avDAOTenant.open(tenant);
       Notificacion noti = avDAOTenant.buscarNotificacion(idNoti, tenant);
       noti.setTexto(texto);
       noti.setLeido(leido);
       avDAOTenant.actualizarNotificacion(noti, tenant);
       avDAOTenant.close(tenant);
     } else {
       throw new Exception("No existe un AV con id: " + idAV);
     }
   } else {
     throw new Exception("Valor de idAV invalido: " + idAV);
   }
 }
Beispiel #11
0
  @Override
  public List<DataAlerta> listaDeAlertas(long idAV) throws NoExisteElAV {
    List<DataAlerta> da = new ArrayList<>();
    String tenant = getTenant(idAV);
    if (tenant != null) {
      avDAOTenant.open(tenant);
      List<Alerta> alertas = avDAOTenant.getAllAlerta();
      da = new ArrayList<>();

      for (Alerta a : alertas) {
        da.add(a.getDataAlerta());
      }

      avDAOTenant.close(tenant);

    } else {
      throw new exceptions.NoExisteElAV();
    }
    return da;
  }
Beispiel #12
0
  @Override
  public void crearAlerta(String producto, String condicion, long idAV) throws NoExisteElAV {
    String tenant = getTenant(idAV);
    if (tenant != null) {
      Condicion cond = util.Serializador.convertirCondicionAString(condicion);

      invDAOTenant.open(tenant);
      Producto prod = invDAOTenant.buscarProducto(producto, tenant);

      if (prod != null) {
        Alerta alerta = new Alerta(cond, prod);
        avDAOTenant.open(tenant);
        avDAOTenant.persistirAlerta(alerta);
        avDAOTenant.close(tenant);
      }

      invDAOTenant.close(tenant);
    } else {
      throw new exceptions.NoExisteElAV();
    }
  }
Beispiel #13
0
  @Override
  public void eliminarAV(long idAV) throws Exception {

    AV av = avDAO.traerAV(idAV);
    String tenant = getTenant(idAV);
    if (tenant != null) {
      List<Usuario> usuarios = av.getUsuariosCompartidos();

      for (Usuario usu : usuarios) {
        usu.removeAVCompartido(av);
        usuarioDAO.actualizarUsuario(usu);
      }

      Usuario usu = av.getUsuarioCreador();
      usu.removeAV(av);
      usuarioDAO.actualizarUsuario(usu);
      avDAO.eliminarAV(tenant, av);
    } else {
      throw new Exception("No existe un AV con id: " + idAV);
    }
  }
Beispiel #14
0
  @Override
  public List<DataNotificacion> getNotificaciones(long idAV) throws Exception {
    if (idAV > 0) {
      String tenant = getTenant(idAV);
      if (tenant != null) {
        avDAOTenant.open(tenant);
        List<Object> notis = avDAOTenant.getAllNotificaciones(tenant);
        List<DataNotificacion> datas = new ArrayList<>();

        for (Object o : notis) {
          Notificacion n = (Notificacion) o;
          datas.add(n.getDataNotificacion());
        }
        avDAOTenant.close(tenant);
        return datas;
      } else {
        throw new Exception("No existe un AV con id: " + idAV);
      }
    } else {
      throw new Exception("Valor de idAV invalido: " + idAV);
    }
  }
Beispiel #15
0
  @Override
  public void descompartirAV(long idAV, String nickUsuario) throws NoExisteElAV {

    AV av = avDAO.traerAV(idAV);

    if (av != null) {
      List<Usuario> compas = av.getUsuariosCompartidos();
      Usuario compa = null;
      for (Usuario usu : compas) {
        if (usu.getNick().equals(nickUsuario)) {
          compa = usu;
          break;
        }
      }
      av.removeUsuarioCompartido(compa);
      compa.removeAVCompartido(av);

      avDAO.actualizarAV(av);
      usuarioDAO.actualizarUsuario(compa);

    } else {
      throw new exceptions.NoExisteElAV();
    }
  }
Beispiel #16
0
  public long altaAV(String nombreAV, String usuarioCreador) throws NombreDeAVInvalido {

    if (!seguridad.Validacion.esAlfaNumerico(nombreAV)) throw new exceptions.NombreDeAVInvalido();

    Usuario usu = usuarioDAO.buscarUsuario(usuarioCreador);

    if (usu != null) {
      if (!(this.existeAVusuario(nombreAV, usuarioCreador))) {
        AV av = new AV(nombreAV, usu, "skin-blue");
        av.setUsuarioCreador(usu); // usu
        avDAO.altaAV(av);
        usu.addAV(av);
        usuarioDAO.actualizarUsuario(usu);

        return av.getIdAV();
      }
    }
    return -1;
  }