From 5a4ae6631bc7da98e4fc17c2b8c0238b96185f79 Mon Sep 17 00:00:00 2001 From: Robert Butora <robert.butora@gmail.com> Date: Thu, 28 Mar 2024 10:10:04 -0400 Subject: [PATCH] cleans up Corrd (and removes last remaining & escapes) --- .../src/main/java/vlkb/common/Coord.java | 234 +++++++----------- 1 file changed, 91 insertions(+), 143 deletions(-) diff --git a/data-discovery/src/main/java/vlkb/common/Coord.java b/data-discovery/src/main/java/vlkb/common/Coord.java index 7384304..50618eb 100644 --- a/data-discovery/src/main/java/vlkb/common/Coord.java +++ b/data-discovery/src/main/java/vlkb/common/Coord.java @@ -146,87 +146,10 @@ class Coord } - // if param present -> must have at least one value - static private String getFirstValue(Map<String, String[]> map, String key) - { - String[] value = map.get(key); - - if(value == null) - return null; - - if(value.length > 0) // key-value present at least once: return first occurance - return value[0].toString(); - else // length=0: no values present (array exists but is empty) - throw new IllegalArgumentException("parameter " + key + " has no value."); - } - -/* - Coord(String lon, String lat, String radius, String velLow, String velUp) - { - try - { - this.skySystem = "GALACTIC"; - this.lon = Double.parseDouble(lon); - this.lat = Double.parseDouble(lat); - this.radius = Double.parseDouble(radius); - } - catch(Exception e) - { - throw new IllegalArgumentException("lon and lat are mandatory: " + e.getMessage()); - } - - if(this.radius <= 0.0) throw new IllegalArgumentException("radius must be positive and not zero"); - this.shape = "CIRCLE"; - - if((velLow != null) && (velUp != null)) - { - this.vel_low = Double.parseDouble(velLow); - this.vel_up = Double.parseDouble(velUp); - this.vel_type = "1"; // VELO + LSRK - //this.vel_type = "2"; // WAVE + Barycentric - this.vel_valid = true; - } - else - { - this.vel_valid = false; - } - } - - - - Coord(double lon, double lat, double radius) - { - if(radius < 0.0) - throw new IllegalArgumentException("radius must be bigger than zero: " + radius); - - this.skySystem = "GALACTIC"; - this.lon = lon; - this.lat = lat; - this.radius = radius; - this.shape = "CIRCLE"; - this.vel_valid = false; - } - - Coord(double lon, double lat, double dlon, double dlat) - { - if((dlon < 0.0) || (dlat < 0.0)) - throw new IllegalArgumentException("both dlon and dlat must be bigger than zero: " + dlon + " " + dlat); - - this.skySystem = "GALACTIC"; - this.lon = lon; - this.lat = lat; - this.dlon = dlon; - this.dlat = dlat; - this.shape = "RECT"; - this.vel_valid = false; - } -*/ void setSkySystem(String skySystem) { this.skySystem = skySystem; } void setSpecSystem(String velType) { this.vel_type = velType; } - // spectral axis - void setVelocity(double vel_low, double vel_up, String vel_type) { this.vel_type = vel_type; @@ -235,51 +158,11 @@ class Coord this.vel_valid = true; } - // utils - public String toString() - { - String area = null; - switch(shape) - { - case "CIRCLE" : area = String.valueOf(radius); break; - case "RECT" : area = dlon + ", " + dlat; break; - default: // FIXME leave with exception - area = "err: " + shape; - } - String resourceSearchArea - = "(P; area) = (" + lon + ", " + lat + "; " + area + ") [deg]"; - return resourceSearchArea; - } - - - 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) - { - case "CIRCLE" : writer.println("<r>"+String.valueOf(radius)+"</r>"); break; - case "RECT" : - writer.println("<dl>"+String.valueOf(dlon)+"</dl>"); - writer.println("<db>"+String.valueOf(dlat)+"</db>"); - break; - default: - writer.println("<shape> unknown shape: "+ shape +" </shape>"); - } - if(vel_valid) - { - writer.println("<vl>" + String.valueOf(vel_low) +"</vl>"); - writer.println("<vu>" + String.valueOf(vel_up) +"</vu>"); - writer.println("<vtype>"+ vel_type +"</vtype>"); - } - } + // generate cutout/merge queryStrings String toQueryString() { @@ -289,38 +172,34 @@ class Coord return toVoQueryString(); } - // FIXME separate keywords into dictionary key-string (LON->"l" LAT->"b" SKYSYSTEM->"skysystem") - // to be part of api/QueryStringParams.java + String toVlkbLegacyQueryString() { + LOGGER.info("trace"); + StringBuilder sb = new StringBuilder(); sb.append("skysystem=" + skySystem); - sb.append("&l=" + lon ); - sb.append("&b=" + lat ); + sb.append("&l=" + lon ); + sb.append("&b=" + lat ); switch(shape) { - case "CIRCLE" : sb.append("&r=" + radius ); - break;// writer.println("<r>"+String.valueOf(radius)+"</r>"); break; + case "CIRCLE" : sb.append("&r=" + radius ); + break; case "RECT" : - sb.append("&dl=" + dlon ); - sb.append("&db=" + dlat ); - //writer.println("<dl>"+String.valueOf(dlon)+"</dl>"); - //writer.println("<db>"+String.valueOf(dlat)+"</db>"); + sb.append("&dl=" + dlon ); + sb.append("&db=" + dlat ); break; default: - // ERROR internal err FIXME writer.println("<shape> unknown shape: "+ shape +" </shape>"); + LOGGER.info("Coord::toVlkbLegacyQueryString: unknown shape: " + shape); } if(vel_valid) { - sb.append("&vl=" + vel_low); - sb.append("&vu=" + vel_up ); - sb.append("&vt=" + vel_type ); - // writer.println("<vl>" + String.valueOf(vel_low) +"</vl>"); - // writer.println("<vu>" + String.valueOf(vel_up) +"</vu>"); - // writer.println("<vtype>"+ vel_type +"</vtype>"); + sb.append("&vl=" + vel_low); + sb.append("&vu=" + vel_up ); + sb.append("&specsystem=" + vel_type ); } return sb.toString(); @@ -329,6 +208,8 @@ class Coord String toVoQueryString() { + LOGGER.info("trace"); + StringBuilder sb = new StringBuilder(); sb.append("skysystem=" + skySystem); @@ -353,12 +234,86 @@ class Coord break; default: - ;// ERROR internal err FIXME writer.println("<shape> unknown shape: "+ shape +" </shape>"); + LOGGER.info("Coord::toVoQueryString: unknown shape: " + shape); + } + + if(vel_valid) + { + sb.append("&BAND= " + vel_low + " " + vel_up); + sb.append("&specsystem=" + vel_type ); } return sb.toString(); } + + + + + // utils + + public String toString() + { + String area = null; + switch(shape) + { + case "CIRCLE" : area = String.valueOf(radius); break; + case "RECT" : area = dlon + ", " + dlat; break; + default: // FIXME leave with exception + area = "err: " + shape; + } + + String resourceSearchArea + = "(P; area) = (" + lon + ", " + lat + "; " + area + ") [deg]"; + + return resourceSearchArea; + } + + + 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) + { + case "CIRCLE" : writer.println("<r>"+String.valueOf(radius)+"</r>"); break; + case "RECT" : + writer.println("<dl>"+String.valueOf(dlon)+"</dl>"); + writer.println("<db>"+String.valueOf(dlat)+"</db>"); + break; + default: + writer.println("<shape> unknown shape: "+ shape +" </shape>"); + } + if(vel_valid) + { + writer.println("<vl>" + String.valueOf(vel_low) +"</vl>"); + writer.println("<vu>" + String.valueOf(vel_up) +"</vu>"); + writer.println("<vtype>"+ vel_type +"</vtype>"); + } + } + + + + // used in constructor and parseVlkb + // if param present -> must have at least one value + static private String getFirstValue(Map<String, String[]> map, String key) + { + String[] value = map.get(key); + + if(value == null) + return null; + + if(value.length > 0) // key-value present at least once: return first occurance + return value[0].toString(); + else // length=0: no values present (array exists but is empty) + throw new IllegalArgumentException("parameter " + key + " has no value."); + } + + + // used in parseSoda String getFirstString(Map<String, String[]> params, String key) { String[] values = params.get(key); @@ -386,11 +341,4 @@ class Coord return stringArray; } - - - - - - - } -- GitLab