/*
   * (non-Javadoc)
   *
   * @see at.researchstudio.sat.recommender.remote.store.dao.OperatorDAO#setApiKey(java.lang.String,
   *      java.lang.String)
   */
  public boolean activate(String id, String apiKey) {
    Operator o = get(id);

    if (o != null && apiKey.length() > 0) {
      if (apiKey.equals(o.getApiKey())) {

        Object[] args = {id};
        int[] argTypes = {Types.VARCHAR};

        try {
          getJdbcTemplate().update(SQL_ACTIVATE_OPERATOR, args, argTypes);
          operatorCache.remove(id);
          operatorTenantCache.clear();
        } catch (Exception e) {
          logger.debug(e);
          return false;
        }
        return true;
      }
    }
    return false;
  }
 /**
  * Gets an operator for a given security token. A token is genrated if an operator signs in and
  * stays valid until signed out.
  */
 public Operator getOperatorFromToken(String token) {
   Operator o = tokenCache.get(token);
   if (o != null) {
     return o;
   } else {
     try {
       o =
           getJdbcTemplate()
               .queryForObject(
                   SQL_GET_OPERATOR_FROM_TOKEN,
                   new Object[] {token},
                   new int[] {Types.VARCHAR},
                   operatorRowMapper);
       if (o.isActive()) {
         tokenCache.put(token, o);
       }
       return o;
     } catch (Exception e) {
       return null;
     }
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see at.researchstudio.sat.recommender.remote.store.dao.OperatorDAO#getOperator(java.lang.String)
  */
 public Operator get(String id) {
   Operator o = operatorCache.get(id);
   if (o != null) {
     return o;
   } else {
     try {
       o =
           getJdbcTemplate()
               .queryForObject(
                   SQL_GET_OPERATOR,
                   new Object[] {id},
                   new int[] {Types.VARCHAR},
                   operatorRowMapper);
       if (o.isActive()) {
         operatorCache.put(o.getOperatorId(), o);
       }
       return o;
     } catch (Exception e) {
       return null;
     }
   }
 }