0001 function as = retrieve(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 type = '';
0013 ids = [];
0014 for j=1:nargin
0015 if isnumeric(varargin{j})
0016 ids = [ids varargin{j}];
0017 elseif ischar(varargin{j})
0018 type = varargin{j};
0019 end
0020 end
0021
0022 as = [];
0023
0024
0025
0026
0027 conn = mysql_connect();
0028
0029
0030 switch type
0031 case 'AO'
0032
0033
0034 for j=1:length(ids)
0035
0036 id = ids(j);
0037 a = getAO(conn, id);
0038 as = [as a];
0039
0040
0041 p = provenance;
0042 a = as(end);
0043
0044 [userid, dbuser] = mysql_getUserID(conn);
0045
0046 submitted = reformate_date(sprintf('%s', datestr(now,31)));
0047 ip = get(p, 'ip');
0048 hostname = get(p, 'hostname');
0049
0050 colnames = {'aoid','UserId','Tdate','SrcIP','Hostname','Direction'};
0051 exdata = {a.tag,userid,submitted,ip,hostname,'out'};
0052 try
0053 fastinsert(conn, 'transactions', colnames, exdata);
0054 catch
0055 warning(sprintf('### error updating transaction table for submission of AO %s/%d', a.name, a.tag));
0056 end
0057
0058 end
0059
0060 case 'Collection'
0061
0062
0063 curs = exec(conn, sprintf('select aoids from collections where id=%d', ids(1)));
0064 curs = fetch(curs);
0065 AOidsStr = curs.Data{1};
0066 close(curs);
0067 AOids = str2num(AOidsStr);
0068
0069
0070 for j=1:length(AOids)
0071
0072 id = AOids(j);
0073 a = getAO(conn, id);
0074 as = [as a];
0075
0076 p = provenance;
0077 a = as(end);
0078
0079 [userid, dbuser] = mysql_getUserID(conn);
0080
0081 submitted = ltpda_reformate_date(sprintf('%s', datestr(now,31)));
0082 ip = get(p, 'ip');
0083 hostname = get(p, 'hostname');
0084
0085 colnames = {'aoid','UserId','Tdate','SrcIP','Hostname','Direction'};
0086 exdata = {a.tag,userid,submitted,ip,hostname,'out'};
0087 try
0088 fastinsert(conn, 'transactions', colnames, exdata);
0089 catch
0090 warning(sprintf('### error updating transaction table for submission of AO %s/%d', a.name, a.tag));
0091 end
0092 end
0093 end
0094
0095
0096
0097 close(conn);
0098
0099
0100
0101
0102 function a = getAO(conn, id)
0103
0104 curs = exec(conn, sprintf('select AO from aos where id=%d', id));
0105 curs = fetch(curs);
0106 Atxt = char([curs.Data{1}].');
0107 close(curs);
0108
0109
0110 str = java.lang.String(Atxt);
0111
0112 stream = java.io.StringBufferInputStream(str);
0113
0114 factory = javaMethod('newInstance',...
0115 'javax.xml.parsers.DocumentBuilderFactory');
0116 builder = factory.newDocumentBuilder;
0117
0118 xdoc = builder.parse(stream);
0119 a = xdoc2ao(xdoc);
0120
0121
0122