Exemplo n.º 1
0
    /**
     * Updates the list of investigation types.
     * @param investTypes :: The list of investigation types.
     */
    void CICatHelper::listInvestigationTypes(std::vector<std::string>& investTypes)
    {
      ICATPortBindingProxy icat;
      setICATProxySettings(icat);

      ns1__listInvestigationTypes request;
      ns1__listInvestigationTypesResponse response;

      std::string sessionID = m_session->getSessionId();
      request.sessionId     = &sessionID;

      int result = icat.listInvestigationTypes(&request,&response);

      if (result == 0)
      {
        for(unsigned i = 0; i < response.return_.size(); ++i)
        {
          investTypes.push_back(response.return_[i]);
        }
      }
      else
      {
        CErrorHandling::throwErrorMessages(icat);
      }
    }
Exemplo n.º 2
0
/**
 * Authenticate the user against all catalogues in the container.
 * @param username :: The login name of the user.
 * @param password :: The password of the user.
 * @param endpoint :: The endpoint url of the catalog to log in to.
 * @param facility :: The facility of the catalog to log in to.
 */
API::CatalogSession_sptr CICatHelper::doLogin(const std::string &username,
                                              const std::string &password,
                                              const std::string &endpoint,
                                              const std::string &facility) {
  m_session = boost::make_shared<API::CatalogSession>("", facility, endpoint);

  // Obtain the ICAT proxy that has been securely set, including soap-endpoint.
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  // Output the soap end-point in use for debugging purposes.
  g_log.debug() << "The ICAT soap end-point is: " << icat.soap_endpoint << "\n";

  // CatalogLogin to icat
  ns1__login login;
  ns1__loginResponse loginResponse;

  std::string userName(username);
  std::string passWord(password);

  login.username = &userName;
  login.password = &passWord;

  int query_id = icat.login(&login, &loginResponse);
  if (query_id == 0) {
    m_session->setSessionId(*(loginResponse.return_));
  } else {
    throw std::runtime_error("Username or password supplied is invalid.");
  }
  return m_session;
}
Exemplo n.º 3
0
    /**This method calls ICat API getInvestigationIncludes and returns datasets details for a given investigation Id
     * @param invstId :: investigation id
     * @param include :: enum parameter for selecting the response data from iact db.
     * @param responsews_sptr :: table workspace to save the response data
     * @returns an integer zero if success if not an error number.
     */
    void CICatHelper::doDataSetsSearch(long long invstId,ns1__investigationInclude include,
        API::ITableWorkspace_sptr& responsews_sptr)
    {
      ICATPortBindingProxy icat;
      setICATProxySettings(icat);

      ns1__getInvestigationIncludes request;
      ns1__getInvestigationIncludesResponse response;

      std::string sessionID        = m_session->getSessionId();
      request.sessionId            = &sessionID;
      request.investigationInclude = &include;
      int64_t investigationID  = invstId;
      request.investigationId = &investigationID;

      int result = icat.getInvestigationIncludes(&request,&response);
      if(result == 0)
      {
        saveDataSets(response,responsews_sptr);
      }
      else
      {
        CErrorHandling::throwErrorMessages(icat);
      }
    }
Exemplo n.º 4
0
/**
 * This method calls ICat api getmyinvestigations and do returns the
 * investigations of the logged in user
 * @param ws_sptr :: shared pointer to table workspace which stores the
 * investigations search result
 */
void CICatHelper::doMyDataSearch(API::ITableWorkspace_sptr &ws_sptr) {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__getMyInvestigationsIncludes request;
  ns1__getMyInvestigationsIncludesResponse response;
  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;
  // investigation include
  boost::shared_ptr<ns1__investigationInclude> invstInculde_sptr(
      new ns1__investigationInclude);
  request.investigationInclude = invstInculde_sptr.get();
  *request.investigationInclude =
      ns1__investigationInclude__INVESTIGATORS_USCORESHIFTS_USCOREAND_USCORESAMPLES;

  int ret = icat.getMyInvestigationsIncludes(&request, &response);
  if (ret != 0) {
    CErrorHandling::throwErrorMessages(icat);
  }
  if (response.return_.empty()) {
    g_log.information()
        << "ICat Mydata search is complete.There are no results to display\n";
    return;
  }
  // save response to a table workspace
  saveMyInvestigations(response, ws_sptr);
}
Exemplo n.º 5
0
/**
 * Uses user input fields to perform a search & obtain the COUNT of results for
 * paging.
 * @return The number of investigations returned by the search performed.
 */
int64_t
CICatHelper::getNumberOfSearchResults(const CatalogSearchParam &inputs) {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__searchByAdvanced request;
  ns1__searchByAdvancedResponse response;

  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;
  request.advancedSearchDetails = buildSearchQuery(inputs);

  int result = icat.searchByAdvanced(&request, &response);

  int64_t numOfResults = 0;

  if (result == 0) {
    numOfResults = response.return_.size();
  } else {
    CErrorHandling::throwErrorMessages(icat);
  }

  g_log.debug() << "CICatHelper::getNumberOfSearchResults -> Number of results "
                   "returned is: { " << numOfResults << " }\n";

  return numOfResults;
}
Exemplo n.º 6
0
    const std::string CICatHelper::getlocationString(const long long& fileid)
    {
      ICATPortBindingProxy icat;
      setICATProxySettings(icat);

      ns1__getDatafile request;
      ns1__getDatafileResponse response;
      
      std::string filelocation;

      std::string sessionID = m_session->getSessionId();
      request.sessionId     = &sessionID;
      int64_t fileID = fileid;
      request.datafileId    = &fileID;

      int ret=icat.getDatafile(&request,&response);

      if(ret==0)
      {
        if(response.return_->location)
        {
          filelocation = *response.return_->location;
        }
      }
      return filelocation;
    }
Exemplo n.º 7
0
    const std::string CICatHelper::getdownloadURL(const long long& fileId)
    {
      ICATPortBindingProxy icat;
      setICATProxySettings(icat);

      ns1__downloadDatafile request;
      ns1__downloadDatafileResponse response;
      
      std::string downloadURL;

      std::string sessionID = m_session->getSessionId();
      request.sessionId     = &sessionID;
      int64_t fileID = fileId;
      request.datafileId    = &fileID;

      int ret = icat.downloadDatafile(&request,&response);

      if(ret == 0)
      {
        downloadURL = *response.URL;
      }
      else
      {
        CErrorHandling::throwErrorMessages(icat);
      }
      return downloadURL;
    }
Exemplo n.º 8
0
/**
 * Creates a dataset for an investigation (based on ID) named 'mantid' if it
 * does not already exist.
 * @param investigationID :: The investigation to create a dataset for.
 * @return The ID of the mantid dataset.
 */
int64_t ICat4Catalog::createMantidDataset(const std::string &investigationID) {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  // We need to obtain an already existing datasetType as it's not recommended
  // to create a new one.
  auto datasetTypeSearch = performSearch(icat, "DatasetType[name ='analyzed']");
  auto datasetType = dynamic_cast<ns1__datasetType *>(datasetTypeSearch.at(0));

  auto investigationSearch =
      performSearch(icat, "Investigation[name = '" + investigationID + "']");
  auto investigation =
      dynamic_cast<ns1__investigation *>(investigationSearch.at(0));

  ns1__dataset dataset;
  std::string datasetName = "mantidTempNotDuplicate";

  dataset.name = &datasetName;
  dataset.complete = false;
  dataset.type = datasetType;
  dataset.investigation = investigation;

  int64_t datasetID = -1;

  if (isAccessAllowed(ns1__accessType__CREATE, dataset)) {
    ns1__create createRequest;
    ns1__createResponse createResponse;

    // We have to re-set the dataset name as when performing isAccessAllowed
    // an error will be thrown if the dataset already exists.
    std::string mantidName = "mantid";
    dataset.name = &mantidName;

    std::string sessionID = m_session->getSessionId();
    createRequest.sessionId = &sessionID;
    createRequest.bean = &dataset;

    if (icat.create(&createRequest, &createResponse) == SOAP_OK) {
      g_log.debug() << "Creating a new dataset named: " << *(dataset.name)
                    << " with investigationID " << investigationID << "\n";
      datasetID = createResponse.return_;
    }
    // Do not throw error from ICAT as we want to continue on GUI. Instead,
    // return -1 below.
  }

  g_log.debug()
      << "The dataset ID returned from ICat4Catalog::createMantidDataset was: "
      << datasetID << "\n";
  return datasetID; // Since we did not have access or could not create the file
                    // the default value (-1).
}
Exemplo n.º 9
0
/**
 * Keep the current session alive.
 */
void ICat4Catalog::keepAlive() {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__refresh request;
  ns1__refreshResponse response;

  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;

  int result = icat.refresh(&request, &response);
  // An error occurred!
  if (result != 0)
    throwErrorMessage(icat);
}
Exemplo n.º 10
0
/**
 *This method calls ICat api logout and disconnects from ICat DB
 * @returns zero if successful otherwise error code
 */
int CICatHelper::doLogout() {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__logout request;
  ns1__logoutResponse response;
  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;
  int ret = icat.logout(&request, &response);
  if (ret != 0) {
    throw std::runtime_error(
        "You are not currently logged into the cataloging system.");
  }
  m_session->setSessionId("");
  return ret;
}
Exemplo n.º 11
0
/**
 * Disconnects the client application from ICat4 based catalog services.
 */
void ICat4Catalog::logout() {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__logout request;
  ns1__logoutResponse response;

  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;

  int result = icat.logout(&request, &response);

  if (result == 0) {
    m_session->setSessionId("");
  } else {
    throwErrorMessage(icat);
  }
}
Exemplo n.º 12
0
    /* This method does advanced search and returns investigation data
     * @param inputs :: reference to class containing search inputs
     * @param outputws :: shared pointer to output workspace
     * @param offset   :: skip this many rows and start returning rows from this point.
     * @param limit    :: limit the number of rows returned by the query.
     */
    void CICatHelper::doAdvancedSearch(const CatalogSearchParam& inputs,API::ITableWorkspace_sptr &outputws,
        const int &offset, const int &limit)
    {
      // Show "my data" (without paging).
      if (inputs.getMyData())
      {
        doMyDataSearch(outputws);
        return;
      }

      ns1__searchByAdvancedPagination request;
      ns1__searchByAdvancedPaginationResponse response;

      // If offset or limit is default value then we want to return as
      // we just wanted to perform the getSearchQuery to build our COUNT query.
      if (offset == -1 || limit == -1) return;

      std::string sessionID = m_session->getSessionId();
      request.sessionId     = &sessionID;
      // Setup paging information to search with paging enabled.
      request.numberOfResults = limit;
      request.startIndex      = offset;
      request.advancedSearchDetails = buildSearchQuery(inputs);

      ICATPortBindingProxy icat;
      setICATProxySettings(icat);

      int result = icat.searchByAdvancedPagination(&request, &response);

      if(result != 0)
      {
        //replace with mantid error routine
        CErrorHandling::throwErrorMessages(icat);
      }
      if(response.return_.empty())
      {
        g_log.information()<<"ICat investigations search is complete.There are no results to display"<<std::endl;
        return ;
      }
      //save response to a table workspace
      saveSearchRessults(response,outputws);
    }
Exemplo n.º 13
0
/**
 * Updates the list of instruments.
 * @param instruments :: instruments list
 */
void CICatHelper::listInstruments(std::vector<std::string> &instruments) {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__listInstruments request;
  ns1__listInstrumentsResponse response;

  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;

  int result = icat.listInstruments(&request, &response);

  if (result == 0) {
    for (const auto &instrument : response.return_) {
      instruments.push_back(instrument);
    }
  } else {
    CErrorHandling::throwErrorMessages(icat);
  }
}
Exemplo n.º 14
0
bool ICat4Catalog::isAccessAllowed(ns1__accessType accessType, T &bean) {
  ICATPortBindingProxy icat;
  setICATProxySettings(icat);

  ns1__isAccessAllowed request;
  ns1__isAccessAllowedResponse response;

  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;

  ns1__accessType_ type;
  type.__item = accessType;

  request.accessType = &type.__item;
  request.bean = &bean;

  if (icat.isAccessAllowed(&request, &response) == SOAP_OK)
    return response.return_;
  else
    throwErrorMessage(icat);
  return false;
}
Exemplo n.º 15
0
    /* This method calls ICat API searchbydavanced and do the basic run search
     * @param icat :: Proxy object for ICat
     * @param request :: request object
     * @param response :: response object
     */
    int CICatHelper::doSearch(ICATPortBindingProxy& icat,boost::shared_ptr<ns1__searchByAdvanced>& request,ns1__searchByAdvancedResponse& response)
    {
      setICATProxySettings(icat);

      clock_t start=clock();
      int ret_advsearch=icat.searchByAdvanced(request.get(),&response);
      if(ret_advsearch!=0)
      {

        CErrorHandling::throwErrorMessages(icat);
      }
      clock_t end=clock();
      float diff = float(end -start)/CLOCKS_PER_SEC;
      g_log.information()<<" Time taken to do  search is "<<diff<< "  seconds "<<std::endl;
      return ret_advsearch;
    }
Exemplo n.º 16
0
/**
 * Returns the results of a search against ICAT for a given query.
 * Note: The ICatProxy object takes care of the deletion of the response object.
 * @param icat  :: The proxy object used to interact with gSOAP.
 * @param query :: The query to send to ICAT.
 */
std::vector<xsd__anyType *>
ICat4Catalog::performSearch(ICATPortBindingProxy &icat, std::string query) {
  ns1__search request;
  ns1__searchResponse response;

  std::string sessionID = m_session->getSessionId();
  request.sessionId = &sessionID;
  request.query = &query;

  g_log.debug() << "The search query sent to ICAT was: \n" << query << '\n';

  std::vector<xsd__anyType *> searchResults;

  if (icat.search(&request, &response) == SOAP_OK) {
    searchResults = response.return_;
  } else {
    throwErrorMessage(icat);
  }

  return searchResults;
}
Exemplo n.º 17
0
/**
 * Throws an error message (returned by gsoap) to Mantid upper layer.
 * @param icat :: ICATPortBindingProxy object.
 */
void ICat4Catalog::throwErrorMessage(ICATPortBindingProxy &icat) {
  char buf[600];
  const int len = 600;
  icat.soap_sprint_fault(buf, len);
  std::string error(buf);
  std::string begmsg("<message>");
  std::string endmsg("</message>");

  std::basic_string<char>::size_type start = error.find(begmsg);
  std::basic_string<char>::size_type end = error.find(endmsg);
  std::string exception;

  if (start != std::string::npos && end != std::string::npos) {
    exception =
        error.substr(start + begmsg.length(), end - (start + begmsg.length()));
  }
  // If no error is returned by ICAT then there is a connection problem.
  if (exception.empty())
    exception = "ICAT appears to be offline. Please check your connection or "
                "report this issue.";

  throw std::runtime_error(exception);
}