Exemplo n.º 1
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string query = (boost::format("SELECT DISTINCT vsessionid, userid, sessionkey, state, closepolicy, "
                                       "                timeout, lastconnect, creation, closure, authid "
                                       " FROM vsession, users, clmachine"
                                       " WHERE vsession.state            = %1%"
                                       "    AND users.status             = %1%"
                                       "    AND vsession.users_numuserid = users.numuserid"
                                       "    AND vsession.clmachine_numclmachineid=clmachine.numclmachineid")
                         % vishnu::STATUS_ACTIVE).str();

    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListSessions();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();

    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

    processOptions(userServer, option, query);
    query.append(" order by creation");
    //To get the list of sessions from the database
    boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabase->getResult(query));

    if (ListOfSessions->getNbTuples() != 0){
      for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = ListOfSessions->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::Session_ptr session = ecoreFactory->createSession();
        session->setSessionId(*(dbResultIter));
        session->setUserId(*(++dbResultIter));
        session->setSessionKey(*(++dbResultIter));
        session->setStatus(vishnu::convertToInt(*(++dbResultIter)));
        session->setClosePolicy(vishnu::convertToInt(*(++dbResultIter)));
        session->setTimeout(vishnu::convertToInt(*(++dbResultIter)));
        session->setDateLastConnect(convertToTimeType(*(++dbResultIter)));
        session->setDateCreation(convertToTimeType(*(++dbResultIter)));
        session->setDateClosure(convertToTimeType(*(++dbResultIter)));
        session->setAuthenId(*(++dbResultIter));
        mlistObject->getSessions().push_back(session);
      }
    }

    return mlistObject;
  }
Exemplo n.º 2
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string sqlListOfSessions = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect, "
                                    "creation, closure, authid from vsession, users where vsession.users_numuserid=users.numuserid";

    std::vector<std::string>::iterator ii;
    std::vector<std::string> results;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListSessions();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      processOptions(userServer, option, sqlListOfSessions);
      sqlListOfSessions.append(" order by creation");
      //To get the list of sessions from the database
      boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabaseInstance->getResult(sqlListOfSessions.c_str()));

      if (ListOfSessions->getNbTuples() != 0){
        for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
          results.clear();
          results = ListOfSessions->get(i);
          ii = results.begin();

          UMS_Data::Session_ptr session = ecoreFactory->createSession();
          session->setSessionId(*(ii));
          session->setUserId(*(++ii));
          session->setSessionKey(*(++ii));
          session->setStatus(vishnu::convertToInt(*(++ii)));
          session->setClosePolicy(vishnu::convertToInt(*(++ii)));
          session->setTimeout(vishnu::convertToInt(*(++ii)));
          session->setDateLastConnect(convertToTimeType(*(++ii)));
          session->setDateCreation(convertToTimeType(*(++ii)));
          session->setDateClosure(convertToTimeType(*(++ii)));
          session->setAuthenId(*(++ii));

          mlistObject->getSessions().push_back(session);
        }
      }
    }
    else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }