[Bio] / FigWebServices / ach_server.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/ach_server.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Wed May 13 20:01:02 2009 UTC revision 1.5, Mon May 18 17:00:26 2009 UTC
# Line 1  Line 1 
1  use strict;  use strict;
2  use FIG;  use FIG;
3  use CGI;  use CGI;
4    my $have_fcgi;
5    eval {
6        require CGI::Fast;
7        $have_fcgi = 1;
8    };
9    
10  use FIG_Config;  use FIG_Config;
11  use Data::Dumper;  use Data::Dumper;
12  use AnnoClearinghouse;  use AnnoClearinghouse;
# Line 9  Line 15 
15  use Tracer;  use Tracer;
16    
17  my $sapling = ERDB::GetDatabase('Sapling');  my $sapling = ERDB::GetDatabase('Sapling');
 my $cgi = new CGI;  
18  my $fig = new FIG;  my $fig = new FIG;
19    
20    #
21    # If no CGI vars, assume we are invoked as a fastcgi service.
22    #
23    if ($ENV{REQUEST_METHOD} eq '' && $have_fcgi)
24    {
25        #
26        # Make mysql autoreconnect.
27        #
28        if ($FIG_Config::dbms eq 'mysql')
29        {
30            my $dbh = $fig->db_handle()->{_dbh};
31            $dbh->{mysql_auto_reconnect} = 1;
32        }
33    
34        while (my $cgi = new CGI::Fast())
35        {
36            eval {
37                &process_request($cgi);
38            };
39            if ($@)
40            {
41                if (ref($@) ne 'ARRAY')
42                {
43                    warn "code died, returning error\n";
44                    print $cgi->header(-status => '500 error in body of cgi processing');
45                    print $@;
46                }
47            }
48        }
49        print STDERR "Clean shutdown\n";
50    }
51    else
52    {
53        my $cgi = new CGI();
54        print $cgi->header();
55        &process_request($cgi);
56    }
57    
58    exit;
59    
60    sub process_request
61    {
62        my($cgi) = @_;
63    
64  my $function = $cgi->param('function');  my $function = $cgi->param('function');
65  $function or myerror($cgi, "500 missing argument", "ACH server missing function argument");  $function or myerror($cgi, "500 missing argument", "ACH server missing function argument");
66    
# Line 57  Line 106 
106  } else {  } else {
107          myerror($cgi, "500 bad function argument $function", "usage:ACH function=equiv_precise | function=equiv_sequence");          myerror($cgi, "500 bad function argument $function", "usage:ACH function=equiv_precise | function=equiv_sequence");
108  }  }
109    }
110    
 exit;  
111  sub myerror  sub myerror
112  {  {
113      my($cgi, $stat, $msg) = @_;      my($cgi, $stat, $msg) = @_;
114      print $cgi->header(-status =>  $stat);      print $cgi->header(-status =>  $stat);
115    
116      print "$msg\n";      print "$msg\n";
117      exit;      die ['cgi error returned'];
 }  
   
 sub get_annotations {  
     my ($ids) = @_;  
   
     my $anno = new AnnoClearinghouse($FIG_Config::clearinghouse_data,  
                                      $FIG_Config::clearinghouse_contrib);  
   
     if (ref $ids) {  
 print "REF\n &Dumper($ids)";  
   
         my $result = {};  
         foreach my $id (@$ids) {  
             my $pid = $anno->lookup_principal_id($id);  
             my @r = $anno->get_annotations_by_pid($pid);  
             if (scalar(@r)) {  
                 $result->{$id} = \@r;  
             }  
         }  
         return $result;  
   
     }  
     else {  
 print "NOT REF\n";  
         my $pid = $anno->lookup_principal_id($ids);  
         my @res = $anno->get_annotations_by_pid($pid);  
         return \@res;  
     }  
118  }  }
119    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3