Home > classes > @ao > submit.m

submit

PURPOSE ^

SUBMIT AO(s) to the MySQL server.

SYNOPSIS ^

function [AOids, Cid] = submit(varargin)

DESCRIPTION ^

 SUBMIT AO(s) to the MySQL server.
 
 The input AOs will be submitted to the MySQL server configured in
 ltpda_startup.m. If multiple AOs are submitted together, a corresponding
 AO Collection entry will be made.
 
 usage: submit(a1, 'some comment')
        submit(a1,a2, 'some comment')
        submit([a1 a2], a3, 'some comment')
 
 M Hewitson 09-05-07
 
 $Id: submit.html,v 1.1 2007/06/08 14:15:03 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [AOids, Cid] = submit(varargin)
0002 
0003 % SUBMIT AO(s) to the MySQL server.
0004 %
0005 % The input AOs will be submitted to the MySQL server configured in
0006 % ltpda_startup.m. If multiple AOs are submitted together, a corresponding
0007 % AO Collection entry will be made.
0008 %
0009 % usage: submit(a1, 'some comment')
0010 %        submit(a1,a2, 'some comment')
0011 %        submit([a1 a2], a3, 'some comment')
0012 %
0013 % M Hewitson 09-05-07
0014 %
0015 % $Id: submit.html,v 1.1 2007/06/08 14:15:03 hewitson Exp $
0016 %
0017 
0018 %--------------------------------------------------------------------------
0019 % collect all AOs from input
0020 as      = [];
0021 comment = [];
0022 for j=1:nargin
0023   a = varargin{j};
0024   if isa(a, 'ao')
0025     as = [as a];
0026   end
0027   if ischar(a)
0028     comment = varargin{j};
0029   end
0030 end
0031 na = length(as);
0032 if na < 1
0033   error('### Incorrect inputs: please supply at least one AO to submit.');
0034 end
0035 if isempty(comment) || length(comment)<10
0036   error('### Incorrect inputs: please supply a comment of at least 10 characters in length.');
0037 end
0038 disp(sprintf('** Submitting %d AOs.', na));
0039 
0040 %--------------------------------------------------------------------------
0041 % open mysql connection
0042 
0043 conn = mysql_connect();
0044 
0045 %--------------------------------------------------------------------------
0046 % Now process each AO
0047 
0048 AOids = [];
0049 Cid   = -1;
0050 
0051 for j=1:na
0052   
0053   a = as(j);
0054   % Tag this AO
0055   a = tag(a, conn);
0056   
0057   disp(sprintf('** Submitting AO: %06d/%s', a.tag, a.name));
0058     
0059   % Get UserID from Username
0060   [userid, dbuser] = mysql_getUserID(conn);
0061   disp(sprintf('** submitting as user %s/%d', dbuser, userid));
0062 
0063   % Collect together all info for this entry
0064   name      = a.name;
0065   data      = a.data;
0066   dinfo     = whos('data');
0067   dtype     = dinfo.class;
0068   dname     = data.name;
0069   submitted = ltpda_reformat_date(sprintf('%s', datestr(now,31)));
0070   prov      = a.provenance;
0071   created   = ltpda_reformat_date(get(prov, 'created'));
0072   ip        = get(prov, 'ip');
0073   hostname  = get(prov, 'hostname');
0074   os        = get(prov, 'os');
0075   filename  = sprintf('AO%06d.xml', a.tag);
0076   
0077   % convert ao to text
0078   x = xml(a); % first to DOM
0079   atxt = xmlwrite(x.docNode); % then to string
0080   
0081   % Insert into aos table
0082   colnames = {'name','dtype','dname','ndata',...
0083               'UserID','Comment','Creation','Submitted',...
0084               'IP','Hostname','OS','Filename','AO'};
0085   exdata   = {name,dtype,dname,len(a),...
0086               userid,comment,created,submitted,...
0087               ip,hostname,os,filename,atxt};
0088             
0089   fastinsert(conn, 'aos', colnames, exdata);  
0090      
0091   % Update transactions table
0092   colnames = {'aoid','UserId','Tdate','SrcIP','Hostname','Direction'};
0093   exdata   = {a.tag,userid,submitted,ip,hostname,'in'};            
0094   try
0095     fastinsert(conn, 'transactions', colnames, exdata);  
0096   catch
0097     warning(sprintf('### error updating transaction table for submission of AO %s/%d', a.name, a.tag));
0098   end
0099 
0100   % collect submitted IDs
0101   AOids = [AOids a.tag];
0102    
0103 end
0104 
0105 % Update collections table.
0106 colnames = {'num','aoids','UserId','submitted','SrcIP','Hostname','Comment'};
0107 exdata   = {length(AOids),csv(AOids),userid,submitted,ip,hostname,comment};
0108 if ~isempty(AOids)
0109   try
0110     fastinsert(conn, 'collections', colnames, exdata);
0111     % get assigned collection ID
0112     curs = exec(conn, 'select max(id) from collections');
0113     curs = fetch(curs);
0114     Cid  = curs.Data{1};
0115     close(curs);
0116   catch
0117     warning('### error submitting AO collection.');
0118   end
0119 end
0120 
0121 
0122 
0123 
0124 %--------------------------------------------------------------------------
0125 % close MySQL connection
0126 close(conn);
0127 
0128 %--------------------------------------------------------------------------
0129 % make comma separated list of numbers
0130 function s = csv(x)
0131 
0132 s = sprintf('%g,', x);
0133 s = s(1:end-1);
0134 
0135 
0136 % END

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003