Index: trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- trunk/pstamp/scripts/pstampparse.pl	(revision 38124)
+++ trunk/pstamp/scripts/pstampparse.pl	(revision 38131)
@@ -59,5 +59,5 @@
     die "req_id is required"  if !$req_id;
     die "outdir is required"  if !$outdir;
-    die "product is required" if !$product;
+#    die "product is required" if !$product;
 } else {
     # mode eq 'list_uri' (used for parser testing)
@@ -95,4 +95,20 @@
 # do not update the database
 $no_update = 1 if $mode ne "queue_job";
+
+$product = 'NULL' unless $product;
+
+# look up the default data store product.
+my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT');
+if (!defined $defaultDSProduct) {
+    # Don't panic yet that it's not defined.
+    #  exit ($PS_EXIT_CONFIG_ERROR);
+    $defaultDSProduct = ''; # set to empty string to simplify some comparisions below
+    print STDERR "Warning PSTAMP_DATA_STORE_PRODUCT not found in the site config.\n" if  $product eq 'NULL';
+}
+
+my $productIsDefault = 0;
+if ($product and $defaultDSProduct) {
+    $productIsDefault = ($product eq $defaultDSProduct);
+}
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -170,5 +186,5 @@
 
 
-# Adjust the label for requests coming in over the web interface
+# Adjust the label for requests coming in over the web upload interface
 
 my $label_changed = 0;
@@ -200,4 +216,31 @@
 }
 
+# product passed in is either one specific to the submitting pstampDataStore or the default
+# "pstampresults"
+# Here, we need to decide whether to change that based on email 
+# WE can't use label (yet) because the PSI cgi script sets it to PSI
+# Do we ever need to use label? Is it obsolete? Check test procedures.
+
+# XXX perhaps do this prior to label setting above after domain/user table is implemented
+my $productForUser;
+my $accessLevel = getUsersAccessLevel($email, \$label, \$productForUser);
+if ($accessLevel < 0) {
+    print STDERR "Data access is forbidden.\n";
+    insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED);
+}
+
+# if the product is the system default, set it to the product for the user@domain
+if ($productIsDefault or $product eq 'NULL') {
+    if ($productForUser) {
+        $product = $productForUser;
+    }
+} else {
+    if ($product eq 'NULL') {
+        $product = $defaultDSProduct;
+    }
+}
+if (!$product or $product eq 'NULL') {
+    my_die("No product found.\n", $PS_EXIT_CONFIG_ERROR);
+}
 
 {
@@ -219,4 +262,8 @@
 }
 
+if ($accessLevel < 0) {
+    exit 0;
+}
+
 if ($duplicate_req_name) {
     exit 0;
@@ -271,10 +318,4 @@
 my $num_jobs = 0;
 
-my $accessLevel = getUsersAccessLevel($email, $label);
-if ($accessLevel < 0) {
-    print STDERR "Data access forbidden.\n";
-    insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED);
-    exit 0;
-}
 
 foreach my $row (@$rows) {
@@ -534,4 +575,5 @@
         # We do not adjust dates for stacks since they are not well defined enough.
         # We'll need to filter them by accessLevel during the lookup
+        my $stage = $row->{IMG_TYPE};
         if ($stage ne 'stack' and adjustDateCuts($row, \$mjd_max)) {
             # if lower limit was supplied by user we can leave the value alone
@@ -1200,5 +1242,8 @@
 sub getUsersAccessLevel {
     my $email = shift;
-    my $label = shift;
+    my $r_label = shift;
+    my $r_product = shift;
+
+    my $label = $$r_label;
 
     my $level = -1;
@@ -1217,8 +1262,10 @@
         # we've got an email check the domain
         my ($user, $domain) = split '@', $email;
-        if ($domain) {
+        unless ($user and $domain) {
+            print STDERR "Error $email is not an acceptable email adddress.\n";
+        } else {
             $domain = lc($domain);
             if ($domain eq 'ifa.hawaii.edu' or $domain eq 'qub.ac.uk') {
-                $level = 0;
+                $level = 2;
             } else {
                 # XXX check for special users
@@ -1226,7 +1273,11 @@
                 $level = 1;
             }
-        } else {
-            print STDERR "Error: $email is not a valid email address\n";
-        }
+
+            # 
+            if ($user eq 'bills' and $domain eq 'ifa.hawaii.edu') {
+                $$r_product = 'bills-results';
+            }
+        }
+
     }
 
