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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 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.

 CALL:        submit(a1, 'some comment')
              submit(a1,a2, 'some comment')
              submit([a1 a2], a3, 'some comment')

 VERSION:     $Id: submit.html,v 1.2 2007/07/10 05:37:08 hewitson Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = submit('Params')

 HISTORY: 09-05-07 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Wed 04-Jul-2007 19:03:10 by m2html © 2003