Skip to content

Instantly share code, notes, and snippets.

@emilroz
Last active August 29, 2015 14:08
Show Gist options
  • Save emilroz/373f63dee3c3be7074a9 to your computer and use it in GitHub Desktop.
Save emilroz/373f63dee3c3be7074a9 to your computer and use it in GitHub Desktop.
Get Fileset file paths.
function [original_file_paths, client_file_paths] = ...
getFilePaths(session, image_id)
% GETFILEPATHS Retrieve the fileset's file paths.
%
% [original_file_path, client_file_paths] = getFilePaths(session, image_id)
% returns file paths to the Original Files and Client Paths (recorded on import).
%
% author: Emil Rozbicki <[email protected]
% Copyright (C) 2014 Glencoe Software, Inc.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
% ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
% Check input
ip = inputParser;
ip.addRequired('session');
ip.addRequired('image_id', @(x) isnumeric(x));
ip.parse(session, image_id);
queryService = session.getQueryService;
of_query = ['select f from Image i '...
'left outer join i.fileset as fs '...
'join fs.usedFiles as uf '...
'join uf.originalFile as f '...
'where i.id = ', num2str(image_id)];
uf_query = ['select uf from Image i '...
'left outer join i.fileset as fs '...
'join fs.usedFiles as uf '...
'where i.id = ', num2str(image_id)];
result_of = queryService.findAllByQuery(of_query, []);
result_uf = queryService.findAllByQuery(uf_query, []);
original_file_paths = '';
client_file_paths = '';
if result_of.size() == 0
disp('Query result 0');
return
end
if result_uf.size() == 0
disp('Query result 0');
return
end
if result_of.size() > 1
original_file_paths = cell(result_of.size(), 1);
for i = 1:result_of.size()
of = result_of.get(i - 1);
original_file_paths(i) = ...
{strcat(char(of.getPath.getValue), char(of.getName.getValue))};
end
else
of = result_of.get(0);
original_file_paths = [char(of.getPath.getValue), char(of.getName.getValue)];
end
if result_uf.size() > 1
client_file_paths = cell(result_of.size(), 1);
for i = 1:result_uf.size()
uf = result_uf.get(i - 1);
client_file_paths(i) = uf.getClientPath.getValue;
end
else
uf = result_uf.get(0);
client_file_paths = uf.getClientPath.getValue;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment