Example #1
0
  /**
   * \brief Function to treat the ListMachinesServer options
   * \fn void processOptions(UserServer userServer,
   *                         const UMS_Data::ListMachineOptions_ptr& options,
   *                         std::string& sqlRequest)
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListMachinesServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void processOptions(UserServer userServer, const UMS_Data::ListMachineOptions_ptr& options, std::string& sqlRequest)
  {
    std::string sqlListofMachinesWithJointure = "SELECT machineid, name, site, machine.status, lang, description, userid "
    " from machine, description, account, users where machine.nummachineid = description.machine_nummachineid "
    " and account.machine_nummachineid=machine.nummachineid and account.users_numuserid=users.numuserid";

    std::string sqlListofMachinesIntial =  sqlRequest;

    size_t userIdSize = options->getUserId().size();
    size_t machineIdSize = options->getMachineId().size();
    bool isListAll = options->isListAllMachine();

    if ((!userServer.isAdmin()) && userIdSize!=0) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if(!isListAll) {
       sqlRequest = sqlListofMachinesWithJointure;
       addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if(userIdSize!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());

      sqlRequest = sqlListofMachinesWithJointure;
      addOptionRequest("userid", options->getUserId(), sqlRequest);
    }

    if(machineIdSize!=0) {
      //To check if the machine id is correct
      checkMachineId(options->getMachineId());

      if(!isListAll && userIdSize==0) {
         sqlRequest=sqlListofMachinesIntial;
      }
      addOptionRequest("machineid", options->getMachineId(), sqlRequest);
    }

 }
Example #2
0
  /**
   * \brief Function to treat the ListMachinesServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListMachinesServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListMachineOptions_ptr& options, std::string& sqlRequest)
  {
    std::string sqlJoinLstMachines = boost::str(boost::format("SELECT DISTINCT machineid, address, machine.status, description, userid "
                                                              " FROM machine, account, users"
                                                              " WHERE account.machine_nummachineid = machine.nummachineid "
                                                              " AND account.users_numuserid = users.numuserid "
                                                              " AND machine.status != %1%"
                                                              " AND account.status != %1%"
                                                              " AND users.status   != %1%"
                                                              ) % vishnu::STATUS_DELETED);
    std::string sqlListofMachinesIntial = sqlRequest;
    bool isListAll = options->isListAllMachine();

    if (! userServer.isAdmin() && ! options->getUserId().empty()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! isListAll) {
      sqlRequest = sqlJoinLstMachines;
      addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if (! options->getUserId().empty()) {
      sqlRequest = sqlJoinLstMachines;
      addOptionRequest("users.numuserid", getNumUser(options->getUserId()), sqlRequest);
    }

    if (! options->getMachineId().empty()) {
      getNumMachine( options->getMachineId() );

      if(! isListAll && options->getUserId().empty()) {
        sqlRequest = sqlListofMachinesIntial;
      }

      addOptionRequest("machineid", options->getMachineId(), sqlRequest);
    }
  }