/** * Validate each input field against the related algorithm property. * @param inputFields :: The name of the input field and value of the field (key * => "StartDate", value => "00/00/0000"). * @return The name of the input field(s) marker to update and related error to * throw. */ const std::map<std::string, std::string> CatalogHelper::validateProperties( const std::map<std::string, std::string> &inputFields) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogSearch"); // Holds the name of the marker to update if an error is found, and the // related error message to use. // E.g. key => "StartDate_err", value => "The start date for..." std::map<std::string, std::string> errors; // Validate all input elements in the map. for (auto iter = inputFields.begin(); iter != inputFields.end(); ++iter) { try { catalogAlgorithm->setProperty(iter->first, iter->second); } catch (std::invalid_argument &) { std::string documentation = propertyDocumentation(catalogAlgorithm->getProperties(), iter->first); // Add the input name + "_err" (to indicate the error marker in the GUI, // rather than the input field) as the key, and the related error as the // value. errors.emplace(iter->first + "_err", documentation); } } return errors; }
/** * Retrieve the path(s) to the file that was downloaded (via HTTP) or is stored * in the archive. * @param userSelectedFiles :: The file(s) the user has selected and wants to * download. * @param downloadPath :: The location to save the datafile(s). * @param sessionID :: The sessions ID of the selected investigation. * @return A vector containing the paths to the file(s) the user wants. */ const std::vector<std::string> CatalogHelper::downloadDataFiles( const std::vector<std::pair<int64_t, std::string>> &userSelectedFiles, const std::string &downloadPath, const std::string &sessionID) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogDownloadDataFiles"); // Prepare for the ugly! // These two vectors are required by the "CatalogDownloadDataFiles" algorithm. std::vector<int64_t> fileIDs; fileIDs.reserve(userSelectedFiles.size()); std::vector<std::string> fileNames; fileNames.reserve(userSelectedFiles.size()); // For each pair in userSelectedFiles we want to add them to their related // vector to pass to the algorithm. for (auto it = userSelectedFiles.begin(); it != userSelectedFiles.end(); ++it) { fileIDs.push_back(it->first); fileNames.push_back(it->second); } // End of the ugly! // The file IDs and file names of the data file(s) the user wants to download. catalogAlgorithm->setProperty("FileIds", fileIDs); catalogAlgorithm->setProperty("FileNames", fileNames); catalogAlgorithm->setProperty("DownloadPath", downloadPath); catalogAlgorithm->setProperty("Session", sessionID); executeAsynchronously(catalogAlgorithm); // Return a vector containing the file paths to the files to download. return (catalogAlgorithm->getProperty("FileLocations")); }
/** * Obtain a list of instruments for specified catalogs based on session information. * @param sessionIDs :: The sessions information of each active catalog. * @return A vector containing the list of all instruments available. */ const std::vector<std::string> CatalogHelper::getInstrumentList( const std::vector<std::string> &sessionIDs) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogListInstruments"); auto session = Mantid::API::CatalogManager::Instance().getActiveSessions(); // If ONE or ALL catalogs are selected to search through use no session (empty). // This will invoke the compositeCatalog instead of specific catalogs for each session. if (session.size() == sessionIDs.size()) { executeAsynchronously(catalogAlgorithm); return catalogAlgorithm->getProperty("InstrumentList"); } else { // Use catalogs for the specified sessions. for (unsigned i = 0; i < sessionIDs.size(); ++i) { catalogAlgorithm->setProperty("Session", sessionIDs.at(i)); executeAsynchronously(catalogAlgorithm); } // Return the vector containing the list of instruments available. return catalogAlgorithm->getProperty("InstrumentList"); } }
/** * The number of results returned by the search query (based on values of input fields). * @param userInputFields :: A map containing the users' search input (key => FieldName, value => FieldValue). * @param sessionIDs :: The sessions information of each active catalog. * @return Number of results returned by the search query. */ int64_t CatalogHelper::getNumberOfSearchResults( const std::map<std::string, std::string> &userInputFields, const std::vector<std::string> &sessionIDs) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogSearch"); // Set the property to only perform a count search. catalogAlgorithm->setProperty("CountOnly", true); // Set the "search" properties to their related input fields. setSearchProperties(catalogAlgorithm, userInputFields); auto session = Mantid::API::CatalogManager::Instance().getActiveSessions(); if (session.size() == sessionIDs.size()) { executeAsynchronously(catalogAlgorithm); return catalogAlgorithm->getProperty("NumberOfSearchResults"); } else { for (unsigned i = 0; i < sessionIDs.size(); ++i) { catalogAlgorithm->setProperty("Session", sessionIDs.at(i)); executeAsynchronously(catalogAlgorithm); } return catalogAlgorithm->getProperty("NumberOfSearchResults"); } }
/** * Search the archives for all dataFiles related to an "investigation id" then * save results to workspace ("dataFileResults"). * @param sessionID :: The sessions ID of the selected investigation. * @param investigationId :: The investigation id to use for the search. */ void CatalogHelper::executeGetDataFiles(const std::string &investigationId, const std::string &sessionID) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogGetDataFiles"); catalogAlgorithm->setProperty("InvestigationId", investigationId); catalogAlgorithm->setPropertyValue("OutputWorkspace", "__dataFileResults"); catalogAlgorithm->setProperty("Session", sessionID); executeAsynchronously(catalogAlgorithm); }
/** * Obtain the list of investigation types for specified catalogs based on * session information. * @param sessionIDs :: The sessions information of each active catalog. * @return A vector containing the list of all investigation types available. */ const std::vector<std::string> CatalogHelper::getInvestigationTypeList( const std::vector<std::string> &sessionIDs) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogListInvestigationTypes"); auto session = Mantid::API::CatalogManager::Instance().getActiveSessions(); if (session.size() == sessionIDs.size()) { executeAsynchronously(catalogAlgorithm); return catalogAlgorithm->getProperty("InvestigationTypes"); } else { for (unsigned i = 0; i < sessionIDs.size(); ++i) { catalogAlgorithm->setProperty("Session", sessionIDs.at(i)); executeAsynchronously(catalogAlgorithm); } return catalogAlgorithm->getProperty("InvestigationTypes"); } }
/** * Search the archive with the user input terms provided and save them to a * workspace ("searchResults"). * @param userInputFields :: A map containing all users' search fields - (key => * FieldName, value => FieldValue). * @param offset :: skip this many rows and start returning rows from this * point. * @param limit :: limit the number of rows returned by the query. * @param sessionIDs :: The sessions information of each active catalog. */ void CatalogHelper::executeSearch( const std::map<std::string, std::string> &userInputFields, const int &offset, const int &limit, const std::vector<std::string> &sessionIDs) { auto catalogAlgorithm = createCatalogAlgorithm("CatalogSearch"); // Set the properties to limit the number of results returned for paging // purposes. catalogAlgorithm->setProperty("Limit", limit); catalogAlgorithm->setProperty("Offset", offset); // Set the "search" properties to their related input fields. setSearchProperties(catalogAlgorithm, userInputFields); auto session = Mantid::API::CatalogManager::Instance().getActiveSessions(); if (session.size() == sessionIDs.size()) { executeAsynchronously(catalogAlgorithm); } else { for (unsigned i = 0; i < sessionIDs.size(); ++i) { catalogAlgorithm->setProperty("Session", sessionIDs.at(i)); executeAsynchronously(catalogAlgorithm); } } }