Commit e293dad4 authored by Robert Butora's avatar Robert Butora
Browse files

adds Interval-param and SingleString-param constraints to SQL-query

parent d9d55530
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class DbPSearch
            = "((em_min > " + Double.toString(coord.band.getMax())
            + ") OR (em_max < " + Double.toString(coord.band.getMin()) + "))";

         theQuery += " AND ( (NOT " + vel_no_overlap + ") OR (em_min is null) OR (em_max is null))";
         theQuery += " AND ( (em_min is null) OR (em_max is null) OR (NOT " + vel_no_overlap + "))";
         /* NOTE '... OR (em_min is null)' statement causes to include 2D datasets if they overlap in sky
          * It is the legacy-search behaviour - however is that useful ?
          */
@@ -79,6 +79,20 @@ public class DbPSearch
         if(addSS.length() > 0) theQuery += " AND (" + addSS + ")";
      }

      theQuery += appendIntervalConstraint(coord.fov,     "s_fov");
      theQuery += appendIntervalConstraint(coord.spatres, "s_resolution");
      theQuery += appendIntervalConstraint(coord.specrp,  "em_res_power");
      theQuery += appendIntervalConstraint(coord.exptime, "t_exptime");
      theQuery += appendIntervalConstraint(coord.timeres, "t_resolution");

      theQuery += appendStringMatchConstraint(coord.id,         "obs_publisher_did");
      theQuery += appendStringMatchConstraint(coord.facility,   "facility_name");
      theQuery += appendStringMatchConstraint(coord.instrument, "instrument_name");
      theQuery += appendStringMatchConstraint(coord.dptype,     "dataproduct_type");

      theQuery += appendStringMatchConstraint(coord.target, "target_name");
      theQuery += appendStringMatchConstraint(coord.format, "access_format");

      //theQuery += " ORDER BY obs_collection";

      LOGGER.info(theQuery);
@@ -112,6 +126,33 @@ public class DbPSearch
      return pubdidArr;
   }

   private String appendIntervalConstraint(Interval interval, String colName)
   {
      if(interval != null)
      {
         String no_overlap
            = "((" + colName + " > " + Double.toString(interval.getMax())
            + ") OR (" + colName + " < " + Double.toString(interval.getMin()) + "))";

         return " AND ( (" + colName + " is null) OR (NOT " + no_overlap + "))";
      }
      else
      {
         return "";
      }
   }

   private String appendStringMatchConstraint(String str, String colName)
   {
      if(str != null)
      {
         return " AND ( (" + colName + " is null) OR ('" + str.trim() + "' = " + colName + "))";
      }
      else
      {
         return "";
      }
   }