Skip to content
Snippets Groups Projects
Commit 142bfea0 authored by Robert Butora's avatar Robert Butora
Browse files

cleans Coord (leaves Coord a 'struct' of Pos Band Time Pol)

parent 0eef59a5
No related branches found
No related tags found
No related merge requests found
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
/*/ center
double lon;
double lat;
// extent < EXT_LIMIT = 4deg
String shape; // FIXME enum CIRCLE | RECT
double radius;
double dlon;
double dlat;
public boolean vel_valid;
String vel_type; // FIXME make enum
double vel_up;
double vel_low;*/
// 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");
String api_b = getFirstValue(params, "b");
API_VLKB_legacy = ((api_l != null) && (api_b != null));
if(API_VLKB_legacy)
parseVlkb(params);
else
parseSoda(params);
LOGGER.info("Parse result: " + toQueryString());
}
*/
/*
protected void parseSoda(Map<String, String[]> params)
{
LOGGER.info("trace");
try
{
String pubdid = null;
Coord coord = null;
pubdid = getFirstString(params, "ID");
String[] circle = getFirstStringArray(params,"CIRCLE", " ", 3);
String[] vel = getFirstStringArray(params,"BAND", " ", 2);
String skySystem = getFirstString(params, "skysystem"); // FIXME add sanity checks / use enum
if(skySystem == null) skySystem = "ICRS";
this.skySystem = skySystem;
this.lon = Double.parseDouble(circle[0]);
this.lat = Double.parseDouble(circle[1]);
this.radius = Double.parseDouble(circle[2]);
if(this.radius <= 0.0) throw new IllegalArgumentException("radius must be positive and not zero");
this.shape = "CIRCLE";
String specSystem = getFirstString(params, "specsystem");
if(specSystem == null) specSystem = "2"; // 2=WAVE BARY
if( (vel != null) && (vel.length >= 2) )
{
this.specSystem = specSystem; // FIXME add sanity checks / use enum
if((vel[0] != null) && (vel[1] != null))
{
this.band.wavelength[0] = Double.parseDouble(vel[0]);
this.band.wavelength[1] = Double.parseDouble(vel[1]);
this.vel_valid = true;
}
else
{
this.vel_valid = false;
}
}
}
catch (IllegalArgumentException illArg)
{
// response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request with incorrect parameters: " + illArg.getMessage());
throw new IllegalArgumentException("Request with incorrect parameters: " + illArg.getMessage());
}
}
*/
/*
protected void parseVlkb(Map<String, String[]> params)
{
LOGGER.info("trace");
// (l,b) is mandatory
this.skySystem = "GALACTIC";
String lcl = getFirstValue(params, "l");
String lcb = getFirstValue(params, "b");
if((lcl == null) || (lcb == null))
throw new IllegalArgumentException("parameters (l,b) are mandatory.");
lon = Double.parseDouble(lcl);
lat = Double.parseDouble(lcb);
// one of: radius r OR (dlon,dlat) is mandatory
if(params.containsKey("r"))
{
String lcr = getFirstValue(params, "r");
radius = Double.parseDouble(lcr);
this.shape = "CIRCLE";
}
else if (params.containsKey("dl") && params.containsKey("db"))
{
String lcdl = getFirstValue(params, "dl");
String lcdb = getFirstValue(params, "db");
dlon = Double.parseDouble(lcdl);
dlat = Double.parseDouble(lcdb);
this.shape = "RECT";
}
else
throw new IllegalArgumentException("area extent is mandatory: either radius r or (dl,db) must be given.");
// velocity is optional
String cvlow = getFirstValue(params, "vl");
String cvup = getFirstValue(params, "vu");
String cvtype = "1"; // VLKB: VELO LSRK
vel_valid = (cvlow != null) && (cvup != null);
if(vel_valid)
{
vel_low = Double.parseDouble(cvlow);
vel_up = Double.parseDouble(cvup);
vel_type = cvtype;
}
}
*/
// 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;
this.vel_low = vel_low;
this.vel_up = vel_up;
this.vel_valid = true;
}
*/
// generate cutout/merge queryStrings
String toQueryString()
{
//if(API_VLKB_legacy)
// return toVlkbLegacyQueryString();
//else
return toVoQueryString();
}
/*
String toVlkbLegacyQueryString()
{
LOGGER.info("trace");
StringBuilder sb = new StringBuilder();
sb.append("skysystem=" + pos.skySystem);
sb.append("&l=" + pos.circle.lon );
sb.append("&b=" + pos.circle.lat );
switch(shape)
{
case "CIRCLE" : sb.append("&r=" + pos.circle.radius );
break;
case "RECT" :
// sb.append("&dl=" + dlon );
// sb.append("&db=" + dlat );
break;
default:
LOGGER.info("Coord::toVlkbLegacyQueryString: unknown shape: " + shape);
}
/* 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()
{
LOGGER.info("trace");
StringBuilder sb = new StringBuilder();
sb.append("skysystem=" + pos.system);
switch(pos.shape)
{
case "CIRCLE" :
sb.append("&POS=CIRCLE " + pos.circle.lon + " " + pos.circle.lat + " " + pos.circle.radius);
break;
case "RECT" :
if(band != null)
sb.append("&POS=RANGE="
+ " " + pos.range.lon1 + " " + pos.range.lon2
+ " " + pos.range.lat1 + " " + pos.range.lat2
+ " " + band.wavelength[0] + " " + band.wavelength[1]);
else
sb.append("&POS=RANGE="
+ " " + pos.range.lon1 + " " + pos.range.lon2
+ " " + pos.range.lat1 + " " + pos.range.lat2);
break;
default:
LOGGER.info("Coord::toVoQueryString: unknown shape: " + pos.shape);
}
if(band != null)
{
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
return sb.toString();
}
// utils
public String toString()
{
String area = "";//null;
/*switch(shape)
{
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) = (" + pos.circle.lon + ", " + pos.circle.lat + "; " + area + ") [deg]";
return resourceSearchArea;
}
void toXML(PrintWriter writer)
{
// center is mandatory -> create no Coord if center not valid
writer.println("<SkySystem>"+pos.system+"</SkySystem>");
switch(pos.shape)
{
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("<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: " + pos.shape + " </shape>");
}
if(band != null)
{
writer.println("<vl>" + String.valueOf(band.wavelength[0]) +"</vl>");
writer.println("<vu>" + String.valueOf(band.wavelength[1]) +"</vu>");
writer.println("<vtype>"+ band.system +"</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);
if (values == null) return null;
if (values.length < 1)
throw new IllegalArgumentException(key + " has no valid value");
else
return values[0];// FIXME if values[0] is null -> canot distinguish from key not found
}
String[] getFirstStringArray(Map<String, String[]> params, String key, String separator, int arrayLength)
{
String array = getFirstString(params, key);
if (array == null) return null;
String[] stringArray = array.split(separator);
if(stringArray.length != arrayLength)
throw new IllegalArgumentException(
key + " parameter has incorrect number of elements ("
+ stringArray.length + " vs " + arrayLength + ") or incorrect separator used");
return stringArray;
}
}
......@@ -113,13 +113,13 @@ public class FormatResponseFilter implements Filter
Dataset[] datasetArr = convert(obsCoreArr,
coord, // VLKB: calc overlap-code for velocity
settings.serviceUrls.cutoutUrl(),
coord.toQueryString());
toQueryString(coord));
SearchOutputData searchOutputData = SearchOutputData.marshall(datasetArr,
subsurveyId,
dbSubsurveyArr,
settings.serviceUrls.mergeUrl(),
coord.toQueryString());
toQueryString(coord));
String respFormat;
String respFormatReq[] = params.get("RESPONSEFORMAT");
......@@ -349,4 +349,50 @@ public class FormatResponseFilter implements Filter
}
// generate cutout/merge queryStrings
private String toQueryString(Coord coord)
{
LOGGER.info("trace");
StringBuilder sb = new StringBuilder();
sb.append("skysystem=" + coord.pos.system);
switch(coord.pos.shape)
{
case "CIRCLE" :
sb.append("&POS=CIRCLE " + coord.pos.circle.lon
+ " " + coord.pos.circle.lat + " " + coord.pos.circle.radius);
break;
case "RECT" :
if(coord.band != null)
sb.append("&POS=RANGE="
+ " " + coord.pos.range.lon1 + " " + coord.pos.range.lon2
+ " " + coord.pos.range.lat1 + " " + coord.pos.range.lat2
+ " " + coord.band.wavelength[0] + " " + coord.band.wavelength[1]);
else
sb.append("&POS=RANGE="
+ " " + coord.pos.range.lon1 + " " + coord.pos.range.lon2
+ " " + coord.pos.range.lat1 + " " + coord.pos.range.lat2);
break;
default:
LOGGER.info("Coord::toVoQueryString: unknown shape: " + coord.pos.shape);
}
if(coord.band != null)
{
sb.append("&BAND= " + coord.band.wavelength[0] + " " + coord.band.wavelength[1]);
sb.append("&specsystem=" + coord.band.system );
}
sb.append("&ID="); // FIXME id-value will be added in FormatResponseFilter
return sb.toString();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment