示例#1
0
  /**
   * \brief Function to treat the ListUsersServer options
   * \param userServer the object which encapsulates user information
   * \param options The object which encapsulates the information of ListUsersServer  options
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListUsersOptions_ptr& options, std::string& sqlRequest) {


    if(! userServer.isAdmin()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }
    std::string  userId = options->getUserId();
    if(userId.size()!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());
      addOptionRequest("userid", userId, sqlRequest);
    }

    std::string  authSystemId = options->getAuthSystemId();
    if(authSystemId.size()!=0) {
      //To check if the authSystem identifier is correct
      checkAuthSystemId(authSystemId);
      //addOptionRequest("authsystemid", authSystemId, sqlRequest);
      std::string luserCmd = boost::str(boost::format("SELECT userid "
                                                      " FROM authsystem, users, authaccount "
                                                      " WHERE authaccount.authsystem_authsystemid=authsystem.numauthsystemid"
                                                      " AND authaccount.users_numuserid=users.numuserid"
                                                      " AND authsystemid='%1%'"
                                                      " AND authsystem.status!=%2%"
                                                      " AND users.status!=%2%"
                                                      " AND authaccount.status!=%2%"
                                                      )
                                        % mdatabaseInstance->escapeData(authSystemId)
                                        % vishnu::STATUS_DELETED);
      sqlRequest.append(" AND userid IN ("+mdatabaseInstance->escapeData(luserCmd)+")");
    }

  }
RequestOut<TGetLabInfoListReplyData> LabService::getLabInfoList(const RequestIn<TGetLabInfoListRequestData> &in,
        quint64 userId)
{
    typedef RequestOut<TGetLabInfoListReplyData> Out;
    Translator t(in.locale());
    QString error;
    if (!commonCheck(t, &error))
        return Out(error);
    if (!checkUserId(t, userId, &error))
        return Out(error);
    QDateTime dt = QDateTime::currentDateTime();
    bool ok = false;
    int lvlSelf = UserRepo->findAccessLevel(userId, &ok).level();
    if (!ok)
        return Out(t.translate("LabService", "Failed to get user access level (internal)", "error"));
    TIdList groups = (lvlSelf < TAccessLevel::ModeratorLevel) ? getGroups(userId, &ok) : getAllGroups(&ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to get user group list (internal)", "error"));
    QList<Lab> entities = LabRepo->findAllNewerThan(userId, in.lastRequestDateTime(), groups, &ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to get lab list (internal)", "error"));
    TLabInfoList newLabs;
    TIdList deletedLabs = LabRepo->findAllDeletedNewerThan(userId, in.lastRequestDateTime(), groups, &ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to get deleted lab list (internal)", "error"));
    foreach (const Lab &entity, entities) {
        newLabs << labToLabInfo(entity, &ok);
        if (!ok)
            return Out(t.translate("LabService", "Failed to create lab info (internal)", "error"));
    }
示例#3
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);
    }

 }
RequestOut<TAddSampleReplyData> SampleService::addSample(const RequestIn<TAddSampleRequestData> &in, quint64 userId)
{
    typedef RequestOut<TAddSampleReplyData> Out;
    Translator t(in.locale());
    QString error;
    const TAddSampleRequestData &requestData = in.data();
    if (!commonCheck(t, requestData, &error))
        return Out(error);
    if (!checkUserId(t, userId, &error))
        return Out(error);
    bool ok = false;
    Sample entity;
    entity.setSenderId(userId);
    entity.setAuthors(requestData.authors());
    entity.setDescription(requestData.description());
    entity.setSource(requestData.project());
    entity.setPreviewMainFile(compilePreview(requestData.project(), &ok));
    if (!ok)
        return Out(t.translate("SampleService", "Failed to compile project", "error"));
    entity.setTags(requestData.tags());
    entity.setTitle(requestData.title());
    TransactionHolder holder(Source);
    quint64 id = SampleRepo->add(entity, &ok);
    if (!ok || !id)
        return Out(t.translate("SampleService", "Failed to add sample (internal)", "error"));
    entity = SampleRepo->findOne(id, &ok);
    if (!ok || !entity.isValid())
        return Out(t.translate("SampleService", "Failed to get sample (internal)", "error"));
    TSampleInfo info = sampleToSampleInfo(entity, &ok);
    if (!ok)
        return Out(t.translate("SampleService", "Failed to create sample info (internal)", "error"));
    if (!commit(t, holder, &error))
        return Out(error);
    TAddSampleReplyData replyData;
    replyData.setSampleInfo(info);
    return Out(replyData, info.creationDateTime());
}
RequestOut<TAddLabReplyData> LabService::addLab(const RequestIn<TAddLabRequestData> &in, quint64 userId)
{
    typedef RequestOut<TAddLabReplyData> Out;
    Translator t(in.locale());
    QString error;
    const TAddLabRequestData &requestData = in.data();
    if (!commonCheck(t, requestData, &error))
        return Out(error);
    if (!checkUserId(t, userId, &error))
        return Out(error);
    bool ok = false;
    Lab entity;
    entity.setAuthors(requestData.authors());
    entity.setDataList(requestData.dataList());
    entity.setDescription(requestData.description());
    entity.setExtraFiles(requestData.extraFiles());
    entity.setGroups(requestData.groups());
    entity.setSenderId(userId);
    entity.setTags(requestData.tags());
    entity.setTitle(requestData.title());
    entity.setType(requestData.dataList().first().type());
    TransactionHolder holder(Source);
    quint64 id = LabRepo->add(entity, &ok);
    if (!ok || !id)
        return Out(t.translate("LabService", "Failed to add lab (internal)", "error"));
    entity = LabRepo->findOne(id, &ok);
    if (!ok || !entity.isValid())
        return Out(t.translate("LabService", "Failed to get lab (internal)", "error"));
    TLabInfo info = labToLabInfo(entity, &ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to create lab info (internal)", "error"));
    if (!commit(t, holder, &error))
        return Out(error);
    TAddLabReplyData replyData;
    replyData.setLabInfo(info);
    return Out(replyData, info.creationDateTime());
}
示例#6
0
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& sqlRequest)
  {
    boost::posix_time::ptime pt;
    size_t userIdSize = options->getUserId().size();
    bool listAll = options->isAdminListOption();

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

    if(options->getMachineId().size()!=0) {
      //To check if the name of the machine is correct
      checkClientMachineName(options->getMachineId());

      sqlRequest = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect,"
                   "creation, closure, authid from vsession, users, clmachine where vsession.users_numuserid=users.numuserid"
                   " and vsession.clmachine_numclmachineid=clmachine.numclmachineid";
      addOptionRequest("name", options->getMachineId(), sqlRequest);
    }

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

      addOptionRequest("userid", options->getUserId(), sqlRequest);
    } else {
      if(!listAll) {
        addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }
    //To check the status value
    checkStatus(status);

    addIntegerOptionRequest("state", status, sqlRequest);

    int closePolicy = options->getSessionClosePolicy();
    //To check the closePolicy value
    checkClosePolicy(closePolicy);

    if(closePolicy) {
      addIntegerOptionRequest("closepolicy", closePolicy, sqlRequest);
    }

    int timeOut = options->getSessionInactivityDelay();
    if(timeOut < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }
    if(timeOut) {
      addIntegerOptionRequest("timeout", timeOut, sqlRequest);
    }

    if(options->getSessionId().size()!=0) {
      //To check if the session id is correct
      checkSessionId(options->getSessionId());

      addOptionRequest("vsessionid", options->getSessionId(), sqlRequest);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if(startDate!=-1) {
      pt =  boost::posix_time::from_time_t(startDate);
      std::string startDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("creation", startDateStr, sqlRequest, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if(endDate!=-1) {
      pt =  boost::posix_time::from_time_t(endDate);
      std::string endDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("closure", endDateStr, sqlRequest, "<=");
    }

  }