Package com.cosmo.data

Examples of com.cosmo.data.DataAgent


    * @throws AuthorizationException
    */
   public void deleteActivity(String activityId) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Elimina las asociaciones con roles
         sql = "DELETE FROM " + TABLE_ROLE_ACTIVITIES + " " +
               "WHERE actid='" + DataAgent.sqlFormatTextValue(activityId) + "'";
         conn.execute(sql);

         // Elimina el rol
         sql = "DELETE FROM " + TABLE_ACTIVITIES + " " +
               "WHERE actid='" + DataAgent.sqlFormatTextValue(activityId) + "'";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here


    * @throws AuthorizationException
    */
   public void updateActivity(Activity activity) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Agrega el nuevo rol
         sql = "UPDATE " + TABLE_ACTIVITIES + " " +
               "SET actdescription  = '" + DataAgent.sqlFormatTextValue(activity.getDescription()) + "', " +
               "    actdefaultgrant =  " + (activity.isGrantedByDefault() ? "true" : "false") + ", " +
               "    actenabled      =  " + (activity.isEnabled() ? "true" : "false") + " " +
               "WHERE actid = '" + DataAgent.sqlFormatTextValue(activity.getId()) + "'";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthorizationException
    */
   public void assignActivityToRole(String activityId, String roleId, boolean isGranted) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      // Si existe esta asociaci�n, la elimina
      unassignActivityFromRole(activityId, roleId);

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Agrega la nueva asociaci�n
         sql = "INSERT INTO " + TABLE_ROLE_ACTIVITIES + " (actid, roleid, isgranted) " +
               "VALUES ('" + DataAgent.sqlFormatTextValue(activityId) + "', " +
                       "'" + DataAgent.sqlFormatTextValue(roleId) + "', " +
                             (isGranted ? "true" : "false") + ")";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthorizationException
    */
   public void unassignActivityFromRole(String activityId, String roleId) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Si existe esta asociaci�n, la elimina
         sql = "DELETE FROM " + TABLE_ROLE_ACTIVITIES + " " +
               "WHERE  actid  = '" + DataAgent.sqlFormatTextValue(activityId) + "' And " +
               "       roleid = '" + DataAgent.sqlFormatTextValue(roleId) + "'";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

   }

   @Override
   public PageContext formSendedEvent(PageContext pc, HttpServletRequest request, HttpServletResponse response)
   {
      DataAgent conn;
      WeatherManager wm;

      Weather weather = new Weather();
      weather.setCityName(HttpRequestUtils.getValue(request, "txtName"));
      weather.setTempMin(HttpRequestUtils.getInt(request, "txtTMin"));
View Full Code Here

   public User login(String login, String password) throws UserNotFoundException, AuthenticationException
   {
      String sql;
      User user = null;
      // DataSource ds;
      DataAgent conn = null;
     
      // Comprobaci�n de cuenta bloqueada
      if (agent.getParamBoolean(PARAM_LOCKCONTROL, false))
      {
         // Obtiene la configuraci�n del agente
         int attemps = agent.getParamInteger(PARAM_ATTEMPTS, 5);
         int timeout = agent.getParamInteger(PARAM_TIMEOUT, 30);

         // Determina si la cuenta del usuario est� o no bloqueada
         if (isLocked(login, attemps, timeout))
         {
            throw new AuthenticationException("La cuenta " + login + " est� bloqueada.");
         }
      }

      try
      {
         sql = "SELECT * " +
               "FROM  " + TABLE_NAME + " " +
               "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "' And " +
               "      usrpwd = '" + CryptoUtils.encrypt(password) + "'";

         conn = DataFactory.getInstance(workspace);
         // ds = this.workspace.getProperties().getDataProperties().getDataSource();
         // conn = new DataConnection(ds);
         // conn.connect();
         ResultSet rs = conn.executeSql(sql);
         if (rs.next())
         {
            user = new User();
            user.setLogin(rs.getString("usrlogin"));
            user.setMail(rs.getString("usrmail"));
            user.setName(rs.getString("usrname"));
            user.setCreated(rs.getDate("usrcreated"));
            user.setLastLogin(rs.getDate("usrlastlogin"));
            user.setLogonCount(rs.getInt("usrlogoncount"));
         }
         else
         {
            // Si tiene el control de bloqueo activado, actualiza la informaci�n de bloqueo
            if (agent.getParamBoolean(PARAM_LOCKCONTROL, false))
            {
               loginFail(login);
            }

            throw new UserNotFoundException();
         }

         // Actualiza los datos estadísticos y de control del usuario
         sql = "UPDATE " + TABLE_NAME + " " +
               "SET usrlastlogin  = current_timestamp, " +
               "    usrlogoncount = usrlogoncount + 1 " +
               "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "'";
         conn.execute(sql);

         // Confirma los cambios en la bbdd
         if (!conn.isAutoCommit()) conn.commit();
      }
      catch (SQLException ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      catch (GeneralSecurityException ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      catch (UserNotFoundException ex)
      {
         throw ex;
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         conn.disconnect();
      }             

      return user;
   }
View Full Code Here

   public boolean loginExist(String login) throws AuthenticationException
   {
      String sSQL;
      // DataSource ds;
      // DataConnection conn = null;
      DataAgent conn = null;

      try
      {
         // Comprueba si existe el usuario
         sSQL = "SELECT Count(*) " +
                "FROM " + TABLE_NAME + " " +
                "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "'";

         conn = DataFactory.getInstance(workspace);
         // ds = this.workspace.getProperties().getDataProperties().getDataSource();
         // conn = new DataConnection(ds);
         // conn.connect();

         return (conn.executeScalar(sSQL) > 0);
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         conn.disconnect();
      }
   }
View Full Code Here

   {
      String sSQL;
      ResultSet rs;
      // DataSource ds;
      // DataConnection conn = null;
      DataAgent conn;

      try
      {
         // Comprueba si existe alg�n usuario con mismo LOGIN o CORREO
         sSQL = "SELECT Count(*) " +
                "FROM " + TABLE_NAME + " " +
                "WHERE Lower(usrlogin) = '" + user.getLogin().trim().toLowerCase() + "' Or " +
                "      Lower(usrmail)  = '" + user.getMail().trim().toLowerCase()  + "'";

         conn = DataFactory.getInstance(workspace);
         // ds = this.workspace.getProperties().getDataProperties().getDataSource();
         // conn = new DataConnection(ds);
         // conn.connect();
         rs = conn.executeSql(sSQL);
         if (rs.next() && rs.getInt(1) > 0)
         {
            throw new UserAlreadyExistsException();
         }

         sSQL = "INSERT INTO " + TABLE_NAME + " (usrlogin, usrmail, usrpwd, usrname, usrcreated, usrlastlogin, usrlogoncount) " +
                "VALUES ('" + user.getLogin() + "', " +
                "        '" + user.getMail() + "', " +
                "        '" + CryptoUtils.encrypt(password) + "', " +
                "        '" + user.getName() + "', " +
                "             current_timestamp, " +
                "             null, " +
                "         " + 0 + ")";

         conn.execute(sSQL);

         // Confirma los cambios en la bbdd
         if (!conn.isAutoCommit()) conn.commit();
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
View Full Code Here

    * @throws AuthenticationException
    */
   public void update(User user) throws UserNotFoundException, AuthenticationException
   {
      String sSQL;
      DataAgent conn = null;

      // Comprueba si existe el usuario especificado
      if (!loginExist(user.getLogin()))
      {
         throw new UserNotFoundException();
      }

      try
      {
         sSQL = "UPDATE " + TABLE_NAME + " " +
                "SET   usrmail = '" + DataAgent.sqlFormatTextValue(user.getMail()) + "', " +
                "      usrname = '" + DataAgent.sqlFormatTextValue(user.getName()) + "' " +
                "WHERE Lower(usrlogin) = '" + user.getLogin().trim().toLowerCase() + "'";

         conn = DataFactory.getInstance(workspace);
         conn.execute(sSQL);

         // Confirma los cambios en la bbdd
         if (!conn.isAutoCommit()) conn.commit();
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthenticationException
    */
   public void delete(String login) throws UserNotFoundException, AuthenticationException
   {
      String sSQL;
      DataAgent conn = null;

      // Comprueba si existe el usuario especificado
      if (!loginExist(login))
      {
         throw new UserNotFoundException();
      }

      try
      {
         // Elimina el usuario
         sSQL = "DELETE FROM " + TABLE_NAME + " " +
                "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "'";

         conn = DataFactory.getInstance(workspace);
         conn.execute(sSQL);

         // Confirma los cambios en la bbdd
         if (!conn.isAutoCommit()) conn.commit();
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

TOP

Related Classes of com.cosmo.data.DataAgent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.