Skip to content

Commit

Permalink
Merge branch 'feature/8126_icat4_external_download' into develop. Refs
Browse files Browse the repository at this point in the history
…#8126.

Conflicts:
	Code/Mantid/Framework/ICat/src/ICat4/ICat4Catalog.cpp
  • Loading branch information
jawrainey committed Oct 24, 2013
2 parents d677310 + cb7df24 commit 4b233e2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace Mantid
void exec();
/// get location of data file or download method
int doDownload( ICATPortBindingProxy & icat);
/// True if the stream is considered binary, false otherwise
bool isBinary(std::istream& stream);
/// True if the extension of the file is a datafile.
bool isDataFile(const std::string& fileName);
/// Saves the downloaded file to disc
std::string saveFiletoDisk(std::istream& rs,const std::string &fileName);
/// Saves downloaded file to local disk
Expand Down
27 changes: 19 additions & 8 deletions Code/Mantid/Framework/ICat/src/CatalogDownloadDataFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ if the data archive is not accessible, it downloads the files from the data serv
#include "MantidAPI/ICatalog.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/FileDescriptor.h"

#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
Expand Down Expand Up @@ -157,13 +156,25 @@ namespace Mantid
}

/**
* Checks to see if the file to be downloaded is a datafile.
* @param stream :: input stream
* @returns True if the stream is not considered ASCII (e.g. binary), false otherwise
*/
bool CatalogDownloadDataFiles::isBinary(std::istream& stream)
* Checks to see if the file to be downloaded is a datafile.
* @param fileName :: Name of data file to download.
* @returns True if the file is a data file.
*/
bool CatalogDownloadDataFiles::isDataFile(const std::string & fileName)
{
return !FileDescriptor::isAscii(stream);
std::string extension = Poco::Path(fileName).getExtension();
std::transform(extension.begin(),extension.end(),extension.begin(),tolower);

std::cerr << "The extension of this file is: " << extension << "\n";

if (extension.compare("raw") == 0 || extension.compare("nxs") == 0)
{
return true;
}
else
{
return false;
}
}

/**
Expand Down Expand Up @@ -232,7 +243,7 @@ namespace Mantid
Poco::Path path(downloadPath, fileName);
std::string filepath = path.toString();

std::ios_base::openmode mode = isBinary(rs) ? std::ios_base::binary : std::ios_base::out;
std::ios_base::openmode mode = isDataFile(fileName) ? std::ios_base::binary : std::ios_base::out;

std::ofstream ofs(filepath.c_str(), mode);
if ( ofs.rdstate() & std::ios::failbit )
Expand Down
18 changes: 4 additions & 14 deletions Code/Mantid/Framework/ICat/src/ICat4/ICat4Catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,19 @@ namespace Mantid
// If the user wants to search through their data in their archive.
if (inputs.getMyData())
{
query.insert(0, "DISTINCT Investigation INCLUDE Instrument, InvestigationParameter <-> InvestigationUser <-> User[name = :user] <-> ");
query.insert(0, "DISTINCT Investigation INCLUDE InvestigationInstrument, Instrument, InvestigationParameter <-> InvestigationUser <-> User[name = :user] <-> ");
}
// Otherwise, we search the entire archive.
else
{
query.insert(0, "DISTINCT Investigation INCLUDE Instrument, InvestigationParameter <-> ");
query.insert(0, "DISTINCT Investigation INCLUDE InvestigationInstrument, Instrument, InvestigationParameter <-> ");
}
}

// If the user has only selected the "My data only" button (E.g. they want to display all their "My data").
if (query.empty() && inputs.getMyData())
{
query.insert(0, "DISTINCT Investigation INCLUDE Instrument, InvestigationParameter <-> InvestigationUser <-> User[name = :user]");
query.insert(0, "DISTINCT Investigation INCLUDE InvestigationInstrument, Instrument, InvestigationParameter <-> InvestigationUser <-> User[name = :user]");
}

g_log.debug() << "Query: { " << query << " }" << std::endl;
Expand Down Expand Up @@ -471,19 +471,9 @@ namespace Mantid
std::string sessionID = Session::Instance().getSessionId();
request.sessionId = &sessionID;

std::ostringstream temp;
temp << investigationId;
std::string name = temp.str();

std::string query = "Datafile <-> Dataset <-> Investigation[id = '" + name + "']";
std::string query = "Datafile <-> Dataset <-> Investigation[id = '" + boost::lexical_cast<std::string>(investigationId) + "']";
request.query = &query;

// If the investigation name is not valid.
if(name == "0" || name.empty())
{
throw std::runtime_error("Invalid investigation ID supplied.");
}

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

if (result == 0)
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/MantidWidgets/src/ICatSearch2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ namespace MantidQt
if (workspace->rowCount() == 0)
{
clearDataFileFrame();
m_icatUiForm.dataFileLbl->setText(QString::number(workspace->rowCount()) + " 0 datafiles found.");
m_icatUiForm.dataFileLbl->setText(QString::number(workspace->rowCount()) + " datafiles found.");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/instrument/Facilities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<archiveSearch plugin="ISISDataSearch" />
</archive>

<catalog name="ICat3Catalog">
<soapendpoint url="https://facilities01.esc.rl.ac.uk:443/ICATService/ICAT"></soapendpoint>
<catalog name="ICat4Catalog">
<soapendpoint url="https://ndw1011.isis.cclrc.ac.uk:8181/ICATService/ICAT"></soapendpoint>
<externaldownload url="http://cloud089.gridpp.rl.ac.uk:8080/ids/"></externaldownload>
<filelocation>
<prefix regex="\\\\isis\\inst\$\\Instruments\$"></prefix>
Expand Down

0 comments on commit 4b233e2

Please sign in to comment.