Commit 0eef59a5 authored by Robert Butora's avatar Robert Butora
Browse files

includes vlkb-volib and modifies Coord to use volib/VO-params (Parser still...

includes vlkb-volib and modifies Coord to use volib/VO-params (Parser still recognizes VLKB-legacy params)
parent 2520f90e
Loading
Loading
Loading
Loading
+78 −63
Original line number Diff line number Diff line
@@ -2,13 +2,15 @@ import java.util.logging.Logger;
import java.util.Map;
import java.io.PrintWriter;

import vo.parameter.*;

class Coord
{
   private static final Logger LOGGER = Logger.getLogger(Coord.class.getName());

   String skySystem; // FIXME make enum
//   String skySystem; // FIXME make enum

   // center
   /*/ center
   double lon;
   double lat;

@@ -21,10 +23,22 @@ class Coord
   public boolean vel_valid;
   String vel_type; // FIXME make enum
   double vel_up;
   double vel_low;
   double vel_low;*/

   private boolean API_VLKB_legacy = false;
// Begin ..................................

//   String specSystem; // FIXME enum VELO_LSRK | WAVE_Barycentric | NONE

   Pos  pos;
   Band band;
   Time time;
   Pol  pol;

// End ....................................


   private boolean API_VLKB_legacy = false;
/*
   Coord(Map<String, String[]> params)
   {
      String api_l = getFirstValue(params, "l");
@@ -39,8 +53,8 @@ class Coord

      LOGGER.info("Parse result: " + toQueryString());
   }


*/
/*
   protected void parseSoda(Map<String, String[]> params)
   {
      LOGGER.info("trace");
@@ -72,12 +86,12 @@ class Coord
         if(specSystem == null) specSystem = "2"; // 2=WAVE BARY
         if( (vel != null) && (vel.length >= 2) )
         {
            this.vel_type = specSystem; // FIXME add sanity checks / use enum
            this.specSystem = specSystem; // FIXME add sanity checks / use enum

            if((vel[0] != null) && (vel[1] != null))
            {
               this.vel_low = Double.parseDouble(vel[0]);
               this.vel_up  = Double.parseDouble(vel[1]);
               this.band.wavelength[0] = Double.parseDouble(vel[0]);
               this.band.wavelength[1]  = Double.parseDouble(vel[1]);
               this.vel_valid = true;
            }
            else
@@ -92,8 +106,8 @@ class Coord
         throw new IllegalArgumentException("Request with incorrect parameters: " + illArg.getMessage());
      }
   } 


*/
/*
   protected void parseVlkb(Map<String, String[]> params)
   {
      LOGGER.info("trace");
@@ -144,12 +158,12 @@ class Coord
         vel_type = cvtype;
      }
   }
*/



   void setSkySystem(String skySystem) { this.skySystem = skySystem; }
   void setSpecSystem(String velType) { this.vel_type = velType; }

//   void setSkySystem(String skySystem) { this.skySystem = skySystem; }
//   void setSpecSystem(String velType) { this.vel_type = velType; }
/*
   void setVelocity(double vel_low, double vel_up, String vel_type)
   {
      this.vel_type  = vel_type;
@@ -157,7 +171,7 @@ class Coord
      this.vel_up    = vel_up;
      this.vel_valid = true;
   }

*/



@@ -166,47 +180,47 @@ class Coord

   String toQueryString()
   {
      if(API_VLKB_legacy)
         return toVlkbLegacyQueryString();
      else
      //if(API_VLKB_legacy)
      //   return toVlkbLegacyQueryString();
      //else
         return toVoQueryString();
   }


/*
   String toVlkbLegacyQueryString()
   {
      LOGGER.info("trace");

      StringBuilder sb = new StringBuilder();

      sb.append("skysystem=" + skySystem);
      sb.append("&l=" + lon );
      sb.append("&b=" + lat );
      sb.append("skysystem=" + pos.skySystem);
      sb.append("&l=" + pos.circle.lon );
      sb.append("&b=" + pos.circle.lat );

      switch(shape)
      {
         case "CIRCLE" : sb.append("&r="  + radius   );
         case "CIRCLE" : sb.append("&r="  + pos.circle.radius   );
                         break;
         case "RECT"   :
                         sb.append("&dl=" + dlon  );
                         sb.append("&db=" + dlat  );
//                         sb.append("&dl=" + dlon  );
//                         sb.append("&db=" + dlat  );
                         break;
         default:
            LOGGER.info("Coord::toVlkbLegacyQueryString: unknown shape: " + shape);
      }

      if(vel_valid)
 /*     if(vel_valid)
      {
         sb.append("&vl=" + vel_low);
         sb.append("&vu=" + vel_up );
         sb.append("&specsystem=" + vel_type );
      }

* /
      sb.append("&pubdid="); // FIXME id-value will be added in FormatResponseFilter

      return sb.toString();
   }

*/

   String toVoQueryString()
   {
@@ -214,35 +228,34 @@ class Coord

      StringBuilder sb = new StringBuilder();

      sb.append("skysystem=" + skySystem);
      sb.append("skysystem=" + pos.system);

      switch(shape)
      switch(pos.shape)
      {
         case "CIRCLE" :
            sb.append("&POS=CIRCLE "  + lon + " " + lat + " " + + radius );
            sb.append("&POS=CIRCLE "  + pos.circle.lon + " " + pos.circle.lat + " " + pos.circle.radius);
            break;

         case "RECT" :
            if(vel_valid)
            if(band != null)
               sb.append("&POS=RANGE="
                     + " " + (lon - dlon)  + " " + (lon + dlon)  
                     + " " + (lat - dlat)  + " " + (lat + dlat)  
                     + " " + vel_low  + " " + vel_up );

                     + " " + pos.range.lon1 + " " + pos.range.lon2
                     + " " + pos.range.lat1 + " " + pos.range.lat2
                     + " " + band.wavelength[0]  + " " + band.wavelength[1]);
            else
               sb.append("&POS=RANGE="
                     + " " + (lon - dlon)  + " " + (lon + dlon)  
                     + " " + (lat - dlat)  + " " + (lat + dlat) );
                     + " " + pos.range.lon1 + " " + pos.range.lon2
                     + " " + pos.range.lat1 + " " + pos.range.lat2);
            break;

         default:
            LOGGER.info("Coord::toVoQueryString: unknown shape: " + shape);
            LOGGER.info("Coord::toVoQueryString: unknown shape: " + pos.shape);
      }

      if(vel_valid)
      if(band != null)
      {
         sb.append("&BAND= " + vel_low + " " + vel_up);
         sb.append("&specsystem=" + vel_type );
         sb.append("&BAND= " + band.wavelength[0] + " " + band.wavelength[1]);
         sb.append("&specsystem=" + band.system );
      }

      sb.append("&ID="); // FIXME id-value will be added in FormatResponseFilter
@@ -258,17 +271,17 @@ class Coord

   public String toString()
   {
      String area = null;
      switch(shape)
      String area = "";//null;
      /*switch(shape)
      {
         case "CIRCLE" : area = String.valueOf(radius); break;
         case "CIRCLE" : area = String.valueOf(pos.circle.radius); break;
         case "RECT"   : area = dlon + ", " + dlat; break;
         default: // FIXME leave with exception
                         area = "err: " + shape;
      }

      */
      String resourceSearchArea 
         = "(P; area) = (" + lon + ", " + lat + "; " + area + ") [deg]";
         = "(P; area) = (" + pos.circle.lon + ", " + pos.circle.lat + "; " + area + ") [deg]";

      return resourceSearchArea;
   }
@@ -277,25 +290,27 @@ class Coord
   void toXML(PrintWriter writer)
   {
      // center is mandatory -> create no Coord if center not valid
      writer.println("<SkySystem>"+skySystem+"</SkySystem>");
      writer.println("<l>"+lon+"</l>");
      writer.println("<b>"+lat+"</b>");

      switch(shape)
      writer.println("<SkySystem>"+pos.system+"</SkySystem>");
      switch(pos.shape)
      {
         case "CIRCLE" :  writer.println("<r>"+String.valueOf(radius)+"</r>"); break;
         case "CIRCLE" :  
            writer.println("<l>"+pos.circle.lon+"</l>");
            writer.println("<b>"+pos.circle.lat+"</b>");
            writer.println("<r>"+String.valueOf(pos.circle.radius)+"</r>"); break;
         case "RECT"   :
                          writer.println("<dl>"+String.valueOf(dlon)+"</dl>");
                          writer.println("<db>"+String.valueOf(dlat)+"</db>");
            writer.println("<l>"  + (pos.range.lon1 + pos.range.lon2)/2.0 + "</l>");
            writer.println("<b>"  + (pos.range.lat1 + pos.range.lat2)/2.0 + "</b>");
            writer.println("<dl>" + (pos.range.lon2 - pos.range.lon1) + "</dl>");
            writer.println("<db>" + (pos.range.lat2 - pos.range.lat1) + "</db>");
            break;
         default:
                          writer.println("<shape> unknown shape: "+ shape +" </shape>");
            writer.println("<shape> unknown shape: " + pos.shape + " </shape>");
      }
      if(vel_valid)
      if(band != null)
      {
         writer.println("<vl>"   + String.valueOf(vel_low)  +"</vl>");
         writer.println("<vu>"   + String.valueOf(vel_up)   +"</vu>");
         writer.println("<vtype>"+ vel_type                 +"</vtype>");
         writer.println("<vl>"   + String.valueOf(band.wavelength[0])  +"</vl>");
         writer.println("<vu>"   + String.valueOf(band.wavelength[1])   +"</vu>");
         writer.println("<vtype>"+ band.system                 +"</vtype>");
      }
   }

+7 −7
Original line number Diff line number Diff line
@@ -104,23 +104,23 @@ class Dataset
   }

/*
   private Vertices mergeVertices(List<Dataset> datasetList, Coord coord)
//   private Vertices mergeVertices(List<Dataset> datasetList, Coord coord)
   {
      // FIXME for now simply return input defined rectangle vertices
      // which is not correct on edges of survey coverage

      double ll=coord.lon, bb=coord.lat;
//      double ll=coord.lon, bb=coord.lat;
      double dll=0, dbb=0; // FIXME why compilers errors (not warning): need to be inited ?

      switch(coord.shape)
//      switch(coord.shape)
      {
         case "CIRCLE" :
            dll = coord.radius;
            dbb = coord.radius;
//            dll = coord.radius;
//            dbb = coord.radius;
            break;
         case "RECT" :
            dll = coord.dlon;
            dbb = coord.dlat;
 //           dll = coord.dlon;
 //           dbb = coord.dlat;
            break;
         default:
            // FIXME internnal error
+23 −15
Original line number Diff line number Diff line
@@ -167,25 +167,33 @@ final class XmlSerializer
   private static String serialize(Coord coord)
   {
      StringBuilder xml = new StringBuilder();
      xml.append("<SkySystem>"+coord.skySystem+"</SkySystem>");
      xml.append("<l>"+coord.lon+"</l>");
      xml.append("<b>"+coord.lat+"</b>");
      switch(coord.shape)
      if(coord.pos != null)
      {
         case "CIRCLE" :  xml.append("<r>"+String.valueOf(coord.radius)+"</r>"); break;
         xml.append("<SkySystem>"+coord.pos.system+"</SkySystem>");
         switch(coord.pos.shape)
         {
            case "CIRCLE" :
               xml.append("<l>"+coord.pos.circle.lon+"</l>");
               xml.append("<b>"+coord.pos.circle.lat+"</b>");
               xml.append("<r>"+String.valueOf(coord.pos.circle.radius)+"</r>"); break;
            case "RECT"   :
                          xml.append("<dl>"+String.valueOf(coord.dlon)+"</dl>");
                          xml.append("<db>"+String.valueOf(coord.dlat)+"</db>");
               xml.append("<l>"+(coord.pos.range.lon1+ coord.pos.range.lon2)/2.0 + "</l>");
               xml.append("<b>"+(coord.pos.range.lat1+ coord.pos.range.lat2)/2.0 + "</b>");
               xml.append("<dl>"+String.valueOf(coord.pos.range.lon2 - coord.pos.range.lon1)+"</dl>");
               xml.append("<db>"+String.valueOf(coord.pos.range.lat2 - coord.pos.range.lat1)+"</db>");
               break;
            default:
                          xml.append("<shape> unknown shape: "+ coord.shape +" </shape>");
               xml.append("<shape> unknown shape: "+ coord.pos.shape +" </shape>");
         }
      }
      if(coord.vel_valid)

      if(coord.band != null)
      {
         xml.append("<vl>"   + String.valueOf(coord.vel_low)  +"</vl>");
         xml.append("<vu>"   + String.valueOf(coord.vel_up)   +"</vu>");
         xml.append("<vtype>"+ coord.vel_type                 +"</vtype>");
         xml.append("<vl>"   + String.valueOf(coord.band.wavelength[0])  +"</vl>");
         xml.append("<vu>"   + String.valueOf(coord.band.wavelength[1])   +"</vu>");
         xml.append("<vtype>"+ coord.band.system                 +"</vtype>");
      }

      return xml.toString();
   }

+136 −71
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import java.util.ArrayList;

import java.lang.ClassNotFoundException;

import vo.parameter.*;

public class DbPSearch
{
@@ -36,35 +37,31 @@ public class DbPSearch
   {
      LOGGER.info("trace");

	   double lon = coord.lon;
	   double lat = coord.lat;
	   double radius = coord.radius;
	   double dlon = coord.dlon;
	   double dlat = coord.dlat;
//      String skySystem = coord.skySystem;
      String shape = coord.pos.shape;

	   boolean  vel_valid   = coord.vel_valid;
	   String   vel_type    = coord.vel_type;
	   double   vel_low     = coord.vel_low;
	   double   vel_up      = coord.vel_up;
      double lon;
      double lat;
      double radius;
      double dlon;
      double dlat;

      String inputRegion = null;

	   if(coord.shape.equals("CIRCLE"))
      if(shape.equals("CIRCLE"))
      {
         lon = coord.pos.circle.lon;
         lat = coord.pos.circle.lat;
         radius = coord.pos.circle.radius;
          inputRegion = "scircle '<(" + Double.toString(lon) + "d," + Double.toString(lat) + "d),"
            + Double.toString(radius) + "d>'";
      }
	   else if( coord.shape.equals("RECT") )
      else if (shape.equals("RECT"))
      {
		   /*Vert vert[] = toVertices(lon, lat, dlon, dlat);

		     inputRegion = "spoly '{" 
		     + "(" + Double.toString(vert[0].lon) + "d," + Double.toString(vert[0].lat) + "d)," 
		     + "(" + Double.toString(vert[1].lon) + "d," + Double.toString(vert[1].lat) + "d)," 
		     + "(" + Double.toString(vert[2].lon) + "d," + Double.toString(vert[2].lat) + "d)," 
		     + "(" + Double.toString(vert[3].lon) + "d," + Double.toString(vert[3].lat) + "d)" 
		     + "}'";
		     */
         lon =  (coord.pos.range.lon1 + coord.pos.range.lon2)/2.0;
         lat =  (coord.pos.range.lat1 + coord.pos.range.lat2)/2.0;
         dlon = (coord.pos.range.lon2 - coord.pos.range.lon1)/2.0;
         dlat = (coord.pos.range.lat2 - coord.pos.range.lat1)/2.0;
  
         /* South-West and North-East corners of a box */
         String sw_lon = Double.toString(lon - dlon/2.0);
@@ -75,13 +72,21 @@ public class DbPSearch
         inputRegion = "sbox '( ("+ sw_lon + "d, " + sw_lat + "d), (" + ne_lon +"d, " + ne_lat + "d) )'";
      }
      else
	   {
		   throw new IllegalArgumentException("Coord::shape was: " + coord.shape + " but valid is CIRCLE or RECT");
      { // FIXME how to deal with Polygon ? -> use enclose-RECT -> RANGE
        /* lon = coord.lon;
         lat = coord.lat;
         radius = coord.radius;
         dlon = coord.dlon;
         dlat = coord.dlat;*/

         throw new IllegalArgumentException("Coord::shape was: " + shape + " but valid is CIRCLE or RECT");
      }

      boolean  vel_valid = (coord.band != null) && (coord.band.system != Band.System.NONE);//coord.vel_valid;
//      String   vel_type    = coord.vel_type;

      String theQuery;
      if(coord.skySystem.equals("GALACTIC"))
      if(coord.pos.system == Pos.System.GALACTIC)
      {
         theQuery ="SELECT obs_publisher_did FROM obscore WHERE ("+inputRegion+"  && polygon_region_galactic)";
      }
@@ -92,10 +97,12 @@ public class DbPSearch

      if(vel_valid)
      {
         String vel_no_overlap = "((em_min > " + Double.toString(vel_up) + ") OR (em_max < " + Double.toString(vel_low) + "))";
         String vel_no_overlap
            = "((em_min > " + Double.toString(coord.band.wavelength[1])
            + ") OR (em_max < " + Double.toString(coord.band.wavelength[0]) + "))";

         theQuery += " AND ( (NOT " + vel_no_overlap + ") OR (em_min is null) OR (em_max is null))";
         /* NOTE '... OR (em_min is null)' statement causes to include 2D-continuum datasets if they overlap in sky
         /* 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 ?
          */
      }
@@ -162,6 +169,59 @@ public class DbPSearch
   public FormatResponseFilter.ObsCore[] queryOutputData(String[] pubdidArr, Coord coord/*, SubsurveyId subsurveyId*/)
   {
      LOGGER.info("");

      String skySystem = coord.pos.system.toString();
      String shape = coord.pos.shape;

      double lon;
      double lat;
      double radius;
      double dlon;
      double dlat;

      String inputRegion = null;

      if(shape.equals("CIRCLE"))
      {
         lon = coord.pos.circle.lon;
         lat = coord.pos.circle.lat;
         radius = coord.pos.circle.radius;
         inputRegion = "scircle '<(" + Double.toString(lon) + "d," + Double.toString(lat) + "d),"
            + Double.toString(radius) + "d>'";
      }
      else if (shape.equals("RECT"))
      {
         lon =  (coord.pos.range.lon1 + coord.pos.range.lon2)/2.0;
         lat =  (coord.pos.range.lat1 + coord.pos.range.lat2)/2.0;
         dlon = (coord.pos.range.lon2 - coord.pos.range.lon1)/2.0;
         dlat = (coord.pos.range.lat2 - coord.pos.range.lat1)/2.0;

         /* South-West and North-East corners of a box */
         String sw_lon = Double.toString(lon - dlon/2.0);
         String sw_lat = Double.toString(lat - dlat/2.0);
         String ne_lon = Double.toString(lon + dlon/2.0);
         String ne_lat = Double.toString(lat + dlat/2.0);

         inputRegion = "sbox '( ("+ sw_lon + "d, " + sw_lat + "d), (" + ne_lon +"d, " + ne_lat + "d) )'";
      }
      else
      { // FIXME how to deal with Polygon ? -> use enclose-RECT -> RANGE
         /* lon = coord.lon;
            lat = coord.lat;
            radius = coord.radius;
            dlon = coord.dlon;
            dlat = coord.dlat;*/

         throw new IllegalArgumentException("Coord::shape was: " + shape + " but valid is CIRCLE or RECT");
      }

      boolean  vel_valid = (coord.band != null) && (coord.band.system != Band.System.NONE);//coord.vel_valid;
     //      String   vel_type    = coord.vel_type;
    //  double   vel_low   = coord.band.wavelength[0];//vel_low;
    //  double   vel_up    = coord.band.wavelength[1];//vel_up;


      /*
         double lon = coord.lon;
         double lat = coord.lat;
         double radius = coord.radius;
@@ -204,13 +264,18 @@ public class DbPSearch
         {
         throw new IllegalArgumentException("Coord::shape was: " + coord.shape + " but valid is CIRCLE or RECT");
         }
         */





      String commaSepPubdids  = String.join("\',\'", pubdidArr);


      //String theQuery ="SELECT dataproduct_type,obs_publisher_did,obs_collection,polygon_region_galactic,access_url,em_min,em_max," 
      String theQuery;
      if(coord.skySystem.equals("GALACTIC"))
      if(coord.pos.system == Pos.System.GALACTIC)
      {
         theQuery ="SELECT *," 
            + inputRegion + " <@ polygon_region_galactic AS inputInsideDb, " 
+16 −8
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletResponseWrapper;
 
import java.nio.charset.Charset;

import vo.parameter.*;

class FormatResponseWrapper extends HttpServletResponseWrapper
{
@@ -95,10 +96,17 @@ public class FormatResponseFilter implements Filter
         PrintWriter responseWriter = ((HttpServletResponse)response).getWriter();

         Map<String, String[]> params = request.getParameterMap();
         Coord       coord            = new Coord(params);
//         Coord       coord            = new Coord(params);
         SubsurveyId subsurveyId      = new SubsurveyId(params);
         // FIXME add invalid param excpetions -> params already parsed in servlet

         Coord coord = new Coord();
         coord.pos  = Pos.parsePos(params);
         coord.pos.setSystem(Pos.System.ICRS);
         coord.band = Band.parseBand(params);
         coord.time = Time.parseTime(params);
         coord.pol  = Pol.parsePol(params);

         ObsCore[] obsCoreArr = queryObsCore(pubdidArr,
               coord); // VLKB: calc overlap-code for sky

@@ -283,18 +291,18 @@ public class FormatResponseFilter implements Filter

   private int convertToOverlapCodeVel(Coord coord, boolean v_valid, double v_min, double v_max)
   {
      if(coord.vel_valid && v_valid)
      if((coord.band != null) && v_valid)
      {
         if(coord.vel_type.equals("1"))
         if(coord.band.system == Band.System.VELO_LSRK)
         {
            // FIXME assert coord: vel_min <= vel_max
            // FIXME assert cube:  v_min   <= v_max

            boolean dbInInp = (coord.vel_low <= v_min) && (v_min <= coord.vel_up)
               && (coord.vel_low <= v_max) && (v_max <= coord.vel_up);
            boolean dbInInp = (coord.band.wavelength[0] <= v_min) && (v_min <= coord.band.wavelength[1])
               && (coord.band.wavelength[0] <= v_max) && (v_max <= coord.band.wavelength[1]);

            boolean inpInDb = (v_min <= coord.vel_low) && (coord.vel_low <= v_max)
               && (v_min <= coord.vel_up ) && (coord.vel_up  <= v_max);
            boolean inpInDb = (v_min <= coord.band.wavelength[0]) && (coord.band.wavelength[0] <= v_max)
               && (v_min <= coord.band.wavelength[1] ) && (coord.band.wavelength[1] <= v_max);

            return convertToOverlapCodeSky(inpInDb, dbInInp);

Loading