From 8c13b1f87cff8d2e658ba3fc5e344db22a44ee4d Mon Sep 17 00:00:00 2001 From: Robert Butora <robert.butora@inaf.it> Date: Thu, 24 Oct 2024 22:30:20 +0200 Subject: [PATCH] removes authz and eliminates Dataset (uses directly obsCoreArr) builds with mvn/pom.xml --- data-discovery/Makefile | 2 +- data-discovery/mvn-build.sh | 4 + data-discovery/mvn-install-own-deps.sh | 30 ++ data-discovery/pom.xml | 66 ++-- .../src/main/java/search/DbPSearch.java | 119 ++++++- .../AuthorizationResponseFilter.java | 83 ----- .../AuthorizationResponseSettings.java | 85 ----- .../java/webapi/formatfilter/Dataset.java | 142 --------- .../formatfilter/FormatResponseFilter.java | 294 ++---------------- .../formatfilter/FormatResponseWrapper.java | 27 ++ .../java/webapi/formatfilter/ObscoreExt.java | 104 +++---- .../webapi/formatfilter/XmlSerializer.java | 14 +- 12 files changed, 306 insertions(+), 664 deletions(-) create mode 100755 data-discovery/mvn-build.sh create mode 100755 data-discovery/mvn-install-own-deps.sh delete mode 100644 data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseFilter.java delete mode 100644 data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseSettings.java delete mode 100644 data-discovery/src/main/java/webapi/formatfilter/Dataset.java create mode 100644 data-discovery/src/main/java/webapi/formatfilter/FormatResponseWrapper.java diff --git a/data-discovery/Makefile b/data-discovery/Makefile index b48fd27..7a61daf 100644 --- a/data-discovery/Makefile +++ b/data-discovery/Makefile @@ -14,7 +14,7 @@ AUTH_DIR := ../auth AUTHFILTERS = $(wildcard $(AUTH_DIR)/src/main/java/*Filter.java) $(AUTH_DIR)/src/main/java/AuthPolicy.java SRC_DIR = src/main/java/common:src/main/java/search:src/main/java/webapi:src/main/java/webapi/formatfilter:src/main/java/webapi/authzfilter:$(AUTH_DIR)/src/main/java VOSI = src/main/java/vosi/VlkbServletFile.java -FILTERS = $(wildcard src/main/java/webapi/*Filter.java) +FILTERS = $(wildcard src/main/java/webapi/formatfilter/*Filter.java) SERVLETS = $(wildcard src/main/java/webapi/*Servlet.java) #=============================================================================== JFLAGS = -g diff --git a/data-discovery/mvn-build.sh b/data-discovery/mvn-build.sh new file mode 100755 index 0000000..d8e39ed --- /dev/null +++ b/data-discovery/mvn-build.sh @@ -0,0 +1,4 @@ + +JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.9.0.9-3.fc38.x86_64 mvn clean package + + diff --git a/data-discovery/mvn-install-own-deps.sh b/data-discovery/mvn-install-own-deps.sh new file mode 100755 index 0000000..adcacca --- /dev/null +++ b/data-discovery/mvn-install-own-deps.sh @@ -0,0 +1,30 @@ + + + + + +mvn install:install-file \ + -Dfile=../java-libs/lib/auth-lib-2.0.0-SNAPSHOT.jar \ + -DgroupId=it.inaf.ia2 \ + -DartifactId=auth-lib \ + -Dversion=2.0.0-SNAPSHOT \ + -Dpackaging=jar \ + -DgeneratePom=true + +mvn install:install-file \ + -Dfile=../java-libs/lib/rap-client-1.0-SNAPSHOT.jar \ + -DgroupId=it.inaf.ia2 \ + -DartifactId=rap-client \ + -Dversion=1.0-SNAPSHOT \ + -Dpackaging=jar \ + -DgeneratePom=true + +mvn install:install-file \ + -Dfile=../java-libs/lib/vlkb-volib-0.9.1.jar \ + -DgroupId=vo \ + -DartifactId=vlkb-volib \ + -Dversion=0.9.1 \ + -Dpackaging=jar \ + -DgeneratePom=true + + diff --git a/data-discovery/pom.xml b/data-discovery/pom.xml index d59c3a1..453f498 100644 --- a/data-discovery/pom.xml +++ b/data-discovery/pom.xml @@ -2,9 +2,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>vlkb</groupId> - <artifactId>psearch</artifactId> + <artifactId>vlkb-siav2</artifactId> <packaging>war</packaging> - <version>1.0-SNAPSHOT</version> + <version>1.6.5</version> <name>psearch Maven Webapp</name> <url>http://maven.apache.org</url> @@ -34,6 +34,21 @@ <version>1.0-SNAPSHOT</version> <scope>provided</scope> </dependency> + + <!-- local --> + <dependency> + <groupId>vo</groupId> + <artifactId>vlkb-volib</artifactId> + <version>0.9.1</version> + <!-- scope>provided</scope --> + </dependency> + + <dependency> + <groupId>uk.ac.starlink</groupId> + <artifactId>stil</artifactId> + <version>4.3</version> + </dependency> + <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> @@ -95,6 +110,12 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.clerezza.ext</groupId> + <artifactId>org.json.simple</artifactId> + <version>0.4</version> + </dependency> + <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api --> <dependency> <groupId>io.jsonwebtoken</groupId> @@ -107,32 +128,39 @@ <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-jackson</artifactId> <version>0.11.5</version> - <!-- scope>runtime</scope --> - </dependency> - - <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> - <dependency> - <groupId>org.postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>42.6.0</version> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> + </dependency> + + <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.2.5</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> </dependencies> <build> - <finalName>psearch</finalName> + <finalName>vlkb-siav2</finalName> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.3.2</version> </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <compilerArgument>-Xlint:unchecked</compilerArgument> + </configuration> + </plugin> + </plugins> </build> diff --git a/data-discovery/src/main/java/search/DbPSearch.java b/data-discovery/src/main/java/search/DbPSearch.java index f24e38b..bf9148d 100644 --- a/data-discovery/src/main/java/search/DbPSearch.java +++ b/data-discovery/src/main/java/search/DbPSearch.java @@ -33,6 +33,54 @@ public class DbPSearch } + static class ObsCore + { + String dataproduct_type; + Integer calib_level; + String obs_collection; + String obs_title; + String obs_id; + String obs_publisher_did; + String bib_reference; + String data_rights; + + String access_url; + String access_format; + Long access_estsize; + + String target_name; + + Double s_ra, s_dec, s_fov; + String s_region; + Long s_xel1, s_xel2; + Double s_resolution; + + Double t_min, t_max, t_exptime, t_resolution; + Long t_xel; + + Double em_min, em_max, em_res_power; + Long em_xel; + boolean em_valid; + + String o_ucd; + + String pol_states; + Long pol_xel; + + String facility_name; + String instrument_name; + + // VLKB extesnion + + Integer overlapCodeSky; + Integer overlapCodeVel; + Integer overlapCode; + + String s_region_galactic; + Double vel_min, vel_max; + } + + public String[] queryOverlapingPubdid(Coord coord) @@ -153,7 +201,7 @@ public class DbPSearch - public FormatResponseFilter.ObsCore[] queryOutputData(String[] pubdidArr, Pos pos) + public ObsCore[] queryOutputData(String[] pubdidArr, Pos pos, Band band) throws Exception { LOGGER.fine("trace"); @@ -172,7 +220,7 @@ public class DbPSearch //LOGGER.fine(theQuery); - List<FormatResponseFilter.ObsCore> obsCoreList = new ArrayList<>(); + List<ObsCore> obsCoreList = new ArrayList<>(); LOGGER.fine("Connecting to: " + dbConn.uri() + " with optional user/pwd: " + dbConn.userName() +" / "+ dbConn.password() ); @@ -183,7 +231,7 @@ public class DbPSearch { while (res.next()) { - FormatResponseFilter.ObsCore obsCore = new FormatResponseFilter.ObsCore(); + ObsCore obsCore = new ObsCore(); obsCore.dataproduct_type = this.getString(res,"dataproduct_type"); obsCore.calib_level = this.getInt(res,"calib_level"); @@ -205,7 +253,6 @@ public class DbPSearch obsCore.s_dec = this.getDouble(res,"s_dec"); obsCore.s_fov = this.getDouble(res,"s_fov"); obsCore.s_region = this.getString(res,"s_region"); - obsCore.s_region_galactic = this.getString(res,"s_region_galactic"); obsCore.s_xel1 = this.getLong(res,"s_xel1"); obsCore.s_xel2 = this.getLong(res,"s_xel2"); obsCore.s_resolution = this.getDouble(res,"s_resolution"); @@ -216,9 +263,6 @@ public class DbPSearch obsCore.t_resolution = this.getDouble(res,"t_resolution"); obsCore.t_xel = this.getLong(res,"t_xel"); - obsCore.vel_min = this.getDouble(res,"vel_min"); //boolean em_min_valid = !res.wasNull(); - obsCore.vel_max = this.getDouble(res,"vel_max"); //boolean em_max_valid = !res.wasNull(); - obsCore.em_min = this.getDouble(res,"em_min"); boolean em_min_valid = !res.wasNull(); obsCore.em_max = this.getDouble(res,"em_max"); boolean em_max_valid = !res.wasNull(); obsCore.em_valid = em_min_valid && em_max_valid;; @@ -233,9 +277,20 @@ public class DbPSearch obsCore.facility_name = this.getString(res,"facility_name"); obsCore.instrument_name = this.getString(res,"instrument_name"); - obsCore.vertices_str = this.getString(res,"polygon_region_galactic"); - obsCore.inputInsideDb = res.getBoolean("inputInsideDb"); - obsCore.dbInsideInput = res.getBoolean("dbInsideInput"); + // VLKB extension + + obsCore.s_region_galactic = this.getString(res,"s_region_galactic"); + obsCore.vel_min = this.getDouble(res,"vel_min"); //boolean em_min_valid = !res.wasNull(); + obsCore.vel_max = this.getDouble(res,"vel_max"); //boolean em_max_valid = !res.wasNull(); + + boolean inputInsideDb = res.getBoolean("inputInsideDb"); + boolean dbInsideInput = res.getBoolean("dbInsideInput"); + obsCore.overlapCodeSky = convertToOverlapCodeSky(inputInsideDb, dbInsideInput); + + obsCore.overlapCodeVel = convertToOverlapCodeVel(band,obsCore.em_valid,obsCore.em_min,obsCore.em_max); + + obsCore.overlapCode = convertToOverlapCode(obsCore.overlapCodeSky, obsCore.overlapCodeVel); + obsCoreList.add(obsCore); } @@ -249,11 +304,53 @@ public class DbPSearch throw new Exception(se.toString()); } - FormatResponseFilter.ObsCore[] cubes = obsCoreList.toArray(new FormatResponseFilter.ObsCore[0]); + ObsCore[] cubes = obsCoreList.toArray(new ObsCore[0]); return cubes; } + /* convert overlap codes */ + + private Integer convertToOverlapCodeSky(boolean inpInDb, boolean dbInInp) + { + if(!inpInDb && !dbInInp) return 4; // parial overlap + else if( inpInDb && !dbInInp) return 3; // input region completely inside fits-datacube + else if(!inpInDb && dbInInp) return 2; // datacube completely inside input-region + else return 5; // exact match: both inpInDb dbInInp are true + } + + private Integer convertToOverlapCodeVel(Band band, boolean v_valid, double v_min, double v_max) + { + if((band != null) && v_valid) + { + if(band.system == Band.System.VELO_LSRK) + { + // FIXME assert coord: vel_min <= vel_max + // FIXME assert cube: v_min <= v_max + + boolean dbInInp = (band.getMin() <= v_min) && (v_min <= band.getMax()) + && (band.getMin() <= v_max) && (v_max <= band.getMax()); + + boolean inpInDb = (v_min <= band.getMin()) && (band.getMin() <= v_max) + && (v_min <= band.getMax() ) && (band.getMax() <= v_max); + + return convertToOverlapCodeSky(inpInDb, dbInInp); + + } + else return null;// FIXME other v_type NotImplemented yet + } + + return null; + } + + private Integer convertToOverlapCode(Integer ovcSky, Integer ovcVel) + { + if(ovcVel == null) return ovcSky; // 2D images + else if(ovcSky == ovcVel) return ovcSky; + else return 4;// partial overlap + } + + /* conversions tolerate missing columns */ private Integer getInt(ResultSet res, String colLabel) diff --git a/data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseFilter.java b/data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseFilter.java deleted file mode 100644 index cd75f32..0000000 --- a/data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseFilter.java +++ /dev/null @@ -1,83 +0,0 @@ - -import java.util.logging.Logger; -import java.util.List; -import java.io.*; - -import javax.servlet.*; -//import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletResponse; - -import javax.servlet.http.*; - - - - - -//@WebFilter("/*") -public class AuthorizationResponseFilter implements Filter -{ - private static final Logger LOGGER = Logger.getLogger("ResponseFilter"); - private static final AuthorizationResponseSettings settings = AuthorizationResponseSettings.getInstance("authpolicy.properties"); - - - @Override - public void init(FilterConfig filterConfig) throws ServletException - { - LOGGER.info("trace"); - } - - - - - - - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException - { - LOGGER.info("trace"); - - chain.doFilter(request, response); - - if(response instanceof FormatResponseWrapper) - { - FormatResponseWrapper pw = (FormatResponseWrapper) response; - LOGGER.info("after doFilter : " + pw.getPubdidArr().length); - - //if (pubdidWrapper.getContentType().contains("text/plain")) - { - String[] pubdidArr = pw.getPubdidArr(); - - AuthPolicy auth = null; - try - { - HttpServletRequest req = (HttpServletRequest) request; - auth = new AuthPolicy(req.getUserPrincipal()); - } - catch(IllegalArgumentException ex) - { - throw new IllegalArgumentException("Authorization : UserPrincipal is not of expected type"); - } - - pw.setAuth(auth); - String[] authorizedPubdidArr = auth.filterAuthorized(pubdidArr, - settings.dbConn.uri(), settings.dbConn.userName(), settings.dbConn.password()); - - pw.setPubdidArr(authorizedPubdidArr); - } - } - else - { - throw new IllegalStateException("Response is not of expected type. Cannot performs authorization check for pubdid array."); - } - } - - @Override - public void destroy() - { - LOGGER.info(""); - } - -} - diff --git a/data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseSettings.java b/data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseSettings.java deleted file mode 100644 index 37d921e..0000000 --- a/data-discovery/src/main/java/webapi/authzfilter/AuthorizationResponseSettings.java +++ /dev/null @@ -1,85 +0,0 @@ - -import java.util.logging.Logger; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.io.PrintWriter; - - -class AuthorizationResponseSettings -{ - private static final Logger LOGGER = Logger.getLogger("AuthorizationResponseSettings"); - - - public static class DBConn - { - private String uri; - private String schema; - private String user_name; - private String password; - - public String uri() {return uri;} - public String schema() {return schema;} - public String userName() {return user_name;} - public String password() {return password;} - - public String toString() - { - return uri + " schema[" + schema + "] " + user_name + " / " + password; - } - } - - public DBConn dbConn; - - - // will not start without config-file; no reasonable code-defaults can be invented - public static AuthorizationResponseSettings getInstance(String settingsFileName) - { - try - { - InputStream ins = AuthorizationResponseSettings.class.getClassLoader().getResourceAsStream(settingsFileName); - - if (ins != null) - { - Properties properties = new Properties(); - properties.load(ins); - - DBConn dbConn = loadDBConn(properties); - - return new AuthorizationResponseSettings(dbConn); - } - else - { - throw new IllegalStateException(settingsFileName + " not found in classpath"); - } - - } - catch(IOException ex) - { - throw new IllegalStateException("Error while loading " + settingsFileName + " file", ex); - } - } - - - - - private AuthorizationResponseSettings(DBConn dbConn) - { - this.dbConn = dbConn; - } - - - private static DBConn loadDBConn(Properties properties) - { - DBConn dbConn = new AuthorizationResponseSettings.DBConn(); - dbConn.uri = properties.getProperty("db_uri","jdbc:postgresql://localhost:5432/vialactea").strip(); - dbConn.schema = properties.getProperty("db_schema","datasets").strip(); - dbConn.user_name = properties.getProperty("db_user_name","").strip(); - dbConn.password = properties.getProperty("db_password","").strip(); - - return dbConn; - } - -} - diff --git a/data-discovery/src/main/java/webapi/formatfilter/Dataset.java b/data-discovery/src/main/java/webapi/formatfilter/Dataset.java deleted file mode 100644 index 717ddec..0000000 --- a/data-discovery/src/main/java/webapi/formatfilter/Dataset.java +++ /dev/null @@ -1,142 +0,0 @@ - -import java.util.List; -import java.util.ArrayList; -import java.util.ListIterator; -import java.util.Iterator; - - - -class Dataset -{ - - FormatResponseFilter.ObsCore obsCore; - - class Access - { - String accessFileUrl; - String accessCutoutUrl; - String accessMosaicUrl; - } - - static class Vertices - { - final int VERT_COUNT = 4; - double[] lon = new double[VERT_COUNT]; - double[] lat = new double[VERT_COUNT]; - } - - - Integer overlapCodeSky; - Integer overlapCodeVel; - Integer overlapCode; - String dataType; - String publisherDid; - Access access; - Vertices vertices_deg; - - Dataset() - { - access = new Access(); - vertices_deg = new Vertices(); - } - - - // create merged dataset if possible - - - public static boolean areDatasetsMergeable(List<Dataset> datasetList) - { - if(datasetList.size() > 1 ) - { - String dataType = datasetList.get(0).dataType; - for(Dataset ds : datasetList) - { - if(!ds.dataType.equals(dataType)) return false; - } - } - return (datasetList.size() > 1) && (! hasFullOverlap(datasetList)); - } - - - public Dataset(List<Dataset> datasetList, String mergeUrlRoot, String mergeQueryString) - { - this.overlapCode = 5; // 5: exact match --> legacy used 0 here FIXME 5 will not be correct on edges of subsurvey-coverage - this.publisherDid = mergePublisherDids(datasetList); - this.dataType = datasetList.get(0).dataType; - - this.access = new Access(); - this.access.accessFileUrl = null; - this.access.accessCutoutUrl = null; - this.access.accessMosaicUrl = mergeUrlRoot + "?" + mergeQueryString + "&ID=" + publisherDid; - - //this.vertices_deg = mergeVertices(datasetList, /*inputs.*/coord); - } - - - private static boolean hasFullOverlap(List<Dataset> datasetList) - { - Iterator<Dataset> it = datasetList.iterator(); - while(it.hasNext()) - { - Dataset dataset = it.next(); - // 2: datacube inside inout, 3: inpout inside datacube, 5: two regions are identical - boolean fullOverlapExist = (dataset.overlapCode == 2) || (dataset.overlapCode == 3) || (dataset.overlapCode == 5); - if(fullOverlapExist) return true; - } - return false; - } - - - private String mergePublisherDids(List<Dataset> datasetList) - { - StringBuilder sb = new StringBuilder(); - - for (ListIterator<Dataset> it = datasetList.listIterator(); it.hasNext(); ) - { - Dataset ds = it.next(); - // FIXME max URL line length(?) iNet: recommendation 8000 octets or use POST - sb.append(";" + ds.publisherDid); - } - - return sb.toString(); - } - -/* -// 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 dll=0, dbb=0; // FIXME why compilers errors (not warning): need to be inited ? - -// switch(coord.shape) - { - case "CIRCLE" : -// dll = coord.radius; -// dbb = coord.radius; - break; - case "RECT" : - // dll = coord.dlon; - // dbb = coord.dlat; - break; - default: - // FIXME internnal error - } - - Vertices vert = new Vertices(); - - vert.lon[0] = ll + dll; - vert.lat[0] = bb + dbb; - vert.lon[1] = ll + dll; - vert.lat[1] = bb - dbb; - vert.lon[2] = ll - dll; - vert.lat[2] = bb + dbb; - vert.lon[3] = ll - dll; - vert.lat[3] = bb - dbb; - - return vert; - } -*/ -} - diff --git a/data-discovery/src/main/java/webapi/formatfilter/FormatResponseFilter.java b/data-discovery/src/main/java/webapi/formatfilter/FormatResponseFilter.java index 6ccca2d..42c0f4f 100644 --- a/data-discovery/src/main/java/webapi/formatfilter/FormatResponseFilter.java +++ b/data-discovery/src/main/java/webapi/formatfilter/FormatResponseFilter.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.*; - + import javax.servlet.ServletException; import javax.servlet.ServletRequest; @@ -16,36 +16,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; - + import java.nio.charset.Charset; import vo.parameter.*; -class FormatResponseWrapper extends HttpServletResponseWrapper -{ - AuthPolicy auth; - - String[] pubdidArr; - - public FormatResponseWrapper(HttpServletResponse response) - { - super(response); - auth = null; - } - - public void setPubdidArr(String[] pubdidArr) { this.pubdidArr = pubdidArr; } - public String[] getPubdidArr() { return this.pubdidArr; } - - public void setAuth(AuthPolicy auth) - { - // assert (this.search.inputs.auth != null); - this.auth = auth; - } -} - - - - public class FormatResponseFilter implements Filter { @@ -53,56 +28,52 @@ public class FormatResponseFilter implements Filter private static final FormatResponseSettings settings = FormatResponseSettings.getInstance( "formatresponsefilter.properties"); - final String RESPONSE_ENCODING = "UTF-8"; - final String DEFAULT_RESPONSEFORMAT = settings.defaults.responseFormat; - final String DEFAULT_SKY_SYSTEM = settings.defaults.skySystem; - final String DEFAULT_SPEC_SYSTEM = settings.defaults.specSystem; - final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file - - private String reqQueryString; - - @Override + //@Override public void init(FilterConfig filterConfig) throws ServletException { - LOGGER.fine("trace"); - - String surveysAbsPathname = settings.serviceUrls.surveysAbsPathname(); LOGGER.config("Default charset: " + Charset.defaultCharset()); LOGGER.config("DB: " + settings.dbConn.toString()); } // FIXME move error handling funcs to VOlib - protected void doMultiValuedParamNotSupported(String message, PrintWriter printWriter) + private void doMultiValuedParamNotSupported(String message, PrintWriter printWriter) { printWriter.println("MultiValuedParamNotSupported : " + message); } - protected void doUsageError(String message, PrintWriter printWriter) + private void doUsageError(String message, PrintWriter printWriter) { printWriter.println("UsageError : " + message); } - protected void doError(String message, PrintWriter printWriter) + private void doError(String message, PrintWriter printWriter) { printWriter.println("Error : " + message); } - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException + //@Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { LOGGER.fine("trace"); LOGGER.fine("REQUEST START ============================================================================================="); + final String RESPONSE_ENCODING = "UTF-8"; + final String DEFAULT_RESPONSEFORMAT = settings.defaults.responseFormat; + final String DEFAULT_SKY_SYSTEM = settings.defaults.skySystem; + final String DEFAULT_SPEC_SYSTEM = settings.defaults.specSystem; + final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file + + FormatResponseWrapper responseWrapper = new FormatResponseWrapper((HttpServletResponse) response); try { long startTime_msec = System.currentTimeMillis(); - chain.doFilter(request, responseWrapper); String[] pubdidArr = responseWrapper.getPubdidArr(); @@ -111,20 +82,11 @@ public class FormatResponseFilter implements Filter { PrintWriter responseWriter = ((HttpServletResponse)response).getWriter(); - // VLKB: reconstruct cutout/merge queryStrings and overlap code Map<String, String[]> params = request.getParameterMap(); Pos pos = Pos.parsePos(params, DEFAULT_SKY_SYSTEM); Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM); - String queryStringBase = toQueryString(pos, band); - // VLKB: calc overlap-code for sky - ObsCore[] obsCoreArr = queryObsCore(pubdidArr, pos); - - // VLKB: calc overlap-code for velocity - // convert overlap-codes and adds access-urls for cutout, merge - Dataset[] datasetArr = convert(obsCoreArr, band, - settings.serviceUrls.cutoutUrl(), - queryStringBase); + DbPSearch.ObsCore[] obsCoreArr = queryObsCore(pubdidArr, pos, band); String respFormat; String respFormatReq[] = params.get("RESPONSEFORMAT"); @@ -147,8 +109,9 @@ public class FormatResponseFilter implements Filter boolean showDuration = false; XmlSerializer.serializeToVoTable(responseWriter, RESPONSE_ENCODING, - datasetArr, - settings.serviceUrls.cutoutUrl(),settings.serviceUrls.mergeUrl(), + obsCoreArr, + settings.serviceUrls.cutoutUrl(), + settings.serviceUrls.mergeUrl(), showDuration,startTime_msec); } else @@ -192,7 +155,7 @@ public class FormatResponseFilter implements Filter catch(Exception ex) { LOGGER.warning("Exception: " + ex.getMessage()); - // ex.printStackTrace(); + ex.printStackTrace(); responseWrapper.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); responseWrapper.setContentType("text/plain"); @@ -205,224 +168,27 @@ public class FormatResponseFilter implements Filter LOGGER.fine("REQUEST END ============================================================================================="); } - - - @Override + //@Override public void destroy() { LOGGER.fine("trace"); } - /////////////////////////////////////////////////////////////////// - // collect output data from DB - - - /* FIXME type needed in DbPSearch */ - static class ObsCore - { - String dataproduct_type; - Integer calib_level; - String obs_collection; - String obs_title; - String obs_id; - String obs_publisher_did; - String bib_reference; - String data_rights; - - String access_url; - String access_format; - Long access_estsize; - - String target_name; - - Double s_ra, s_dec, s_fov; - String s_region; - Long s_xel1, s_xel2; - Double s_resolution; - - Double t_min, t_max, t_exptime, t_resolution; - Long t_xel; - - Double em_min, em_max, em_res_power; - Long em_xel; - boolean em_valid; - - String o_ucd; - - String pol_states; - Long pol_xel; - - String facility_name; - String instrument_name; - - String vertices_str; - boolean inputInsideDb; - boolean dbInsideInput; - - String s_region_galactic; - Double vel_min, vel_max; - } - - - - private FormatResponseFilter.ObsCore[] queryObsCore(String[] pubdidArr, Pos pos)//, String fitsRemotePath) - throws Exception - { - LOGGER.fine("trace"); - - DbPSearch dbps; - synchronized(DbPSearch.class) - { - dbps = new DbPSearch(settings.dbConn); - } - - return dbps.queryOutputData(pubdidArr, pos); - //FormatResponseFilter.ObsCore[] obsCoreArr = dbps.queryOutputData(pubdidArr, coord); - //return convert(obsCoreArr, coord, fitsRemotePath); - } - - - - - - private Dataset[] convert(FormatResponseFilter.ObsCore[] obsCoreArr, Band band, - String cutoutUrlRoot, String cutoutQueryString) - { - List<Dataset> datasetList = new ArrayList<Dataset>(); - - for(FormatResponseFilter.ObsCore obsCore : obsCoreArr) - { - Dataset dataset = new Dataset(); - - dataset.obsCore = obsCore; - - dataset.overlapCodeSky = convertToOverlapCodeSky(obsCore.inputInsideDb, obsCore.dbInsideInput); - dataset.overlapCodeVel = convertToOverlapCodeVel(band,obsCore.em_valid,obsCore.em_min,obsCore.em_max); - dataset.overlapCode = convertToOverlapCode(dataset.overlapCodeSky, dataset.overlapCodeVel); - dataset.dataType = obsCore.dataproduct_type; - dataset.publisherDid = obsCore.obs_publisher_did; - - dataset.access.accessFileUrl = obsCore.access_url; - dataset.access.accessCutoutUrl = cutoutUrlRoot + "?" + cutoutQueryString + "&ID=" + dataset.publisherDid; - dataset.access.accessMosaicUrl = null; - - dataset.vertices_deg = convertToVertices(obsCore.vertices_str); - - datasetList.add(dataset); - } - - return datasetList.toArray(new Dataset[0]); - } - - - private Integer convertToOverlapCodeSky(boolean inpInDb, boolean dbInInp) - { - if(!inpInDb && !dbInInp) return 4; // parial overlap - else if( inpInDb && !dbInInp) return 3; // input region completely inside fits-datacube - else if(!inpInDb && dbInInp) return 2; // datacube completely inside input-region - else return 5; // exact match: both inpInDb dbInInp are true - } - - - private Integer convertToOverlapCodeVel(Band band, boolean v_valid, double v_min, double v_max) - { - if((band != null) && v_valid) + private DbPSearch.ObsCore[] queryObsCore(String[] pubdidArr, Pos pos, Band band) + throws Exception { - if(band.system == Band.System.VELO_LSRK) - { - // FIXME assert coord: vel_min <= vel_max - // FIXME assert cube: v_min <= v_max - - boolean dbInInp = (band.getMin() <= v_min) && (v_min <= band.getMax()) - && (band.getMin() <= v_max) && (v_max <= band.getMax()); - - boolean inpInDb = (v_min <= band.getMin()) && (band.getMin() <= v_max) - && (v_min <= band.getMax() ) && (band.getMax() <= v_max); - - return convertToOverlapCodeSky(inpInDb, dbInInp); - - } - else return null;// FIXME other v_type NotImplemented yet - } - - return null; - } - - - private Integer convertToOverlapCode(Integer ovcSky, Integer ovcVel) - { - if(ovcVel == null) return ovcSky; // 2D images - else if(ovcSky == ovcVel) return ovcSky; - else return 4;// partial overlap - } - - - private Dataset.Vertices convertToVertices(String polygon) - { - final double RAD2DEG = 180.0 / Math.PI; - - Dataset.Vertices vert = new Dataset.Vertices(); - - polygon = polygon.replace("("," "); - polygon = polygon.replace(")"," "); - polygon = polygon.replace("{"," "); - polygon = polygon.replace("}"," "); - - String[] verts = polygon.split(","); - - vert.lon[0] = RAD2DEG * Double.parseDouble(verts[0]); - vert.lat[0] = RAD2DEG * Double.parseDouble(verts[1]); - vert.lon[1] = RAD2DEG * Double.parseDouble(verts[2]); - vert.lat[1] = RAD2DEG * Double.parseDouble(verts[3]); - vert.lon[2] = RAD2DEG * Double.parseDouble(verts[4]); - vert.lat[2] = RAD2DEG * Double.parseDouble(verts[5]); - vert.lon[3] = RAD2DEG * Double.parseDouble(verts[6]); - vert.lat[3] = RAD2DEG * Double.parseDouble(verts[7]); - - return vert; - } - - - - // generate cutout/merge queryStrings - private String toQueryString(Pos pos, Band band) - { - LOGGER.fine("trace"); + LOGGER.fine("trace"); - StringBuilder sb = new StringBuilder(); - - if(pos!=null) - { - switch(pos.shape) + DbPSearch dbps; + synchronized(DbPSearch.class) { - case CIRCLE: - sb.append("POS=" + pos.circle.toString()); - break; - - case RANGE: - sb.append("POS=" + pos.range.toString()); - break; - - case POLYGON: - sb.append("POS=" + pos.polygon.toString()); - break; - - default: - LOGGER.warning("Coord::toQueryString: unknown shape: " + pos.shape.toString()); + dbps = new DbPSearch(settings.dbConn); } - } - sb.append("&POSSYS=" + pos.system.toString()); - if(band != null) - { - sb.append("&" + band.toString()); + return dbps.queryOutputData(pubdidArr, pos, band); } - return sb.toString(); - } - - - } + diff --git a/data-discovery/src/main/java/webapi/formatfilter/FormatResponseWrapper.java b/data-discovery/src/main/java/webapi/formatfilter/FormatResponseWrapper.java new file mode 100644 index 0000000..36e8a64 --- /dev/null +++ b/data-discovery/src/main/java/webapi/formatfilter/FormatResponseWrapper.java @@ -0,0 +1,27 @@ + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + + +class FormatResponseWrapper extends HttpServletResponseWrapper +{ +// AuthPolicy auth; + String[] pubdidArr; + + public FormatResponseWrapper(HttpServletResponse response) + { + super(response); + // auth = null; + } + + public void setPubdidArr(String[] pubdidArr) { this.pubdidArr = pubdidArr; } + + public String[] getPubdidArr() { return this.pubdidArr; } +/* + public void setAuth(AuthPolicy auth) + { + // assert (this.search.inputs.auth != null); + this.auth = auth; + }*/ +} + diff --git a/data-discovery/src/main/java/webapi/formatfilter/ObscoreExt.java b/data-discovery/src/main/java/webapi/formatfilter/ObscoreExt.java index 1ae4ab0..aeaa583 100644 --- a/data-discovery/src/main/java/webapi/formatfilter/ObscoreExt.java +++ b/data-discovery/src/main/java/webapi/formatfilter/ObscoreExt.java @@ -75,52 +75,52 @@ class ObscoreExt new ColumnInfo( "instrument_name", String.class, "Instrument" ), }; - public static Object[] obscoreRow( Dataset dataset ) + public static Object[] obscoreRow( DbPSearch.ObsCore obsCore ) { return new Object[] { - dataset.obsCore.dataproduct_type, - dataset.obsCore.calib_level, - dataset.obsCore.obs_collection, - dataset.obsCore.obs_title, - dataset.obsCore.obs_id, - dataset.obsCore.obs_publisher_did, - dataset.obsCore.bib_reference, - dataset.obsCore.data_rights, - - dataset.obsCore.access_url, - dataset.obsCore.access_format, - dataset.obsCore.access_estsize, - - dataset.obsCore.target_name, - - dataset.obsCore.s_ra, - dataset.obsCore.s_dec, - dataset.obsCore.s_fov, - - dataset.obsCore.s_region, - dataset.obsCore.s_xel1, - dataset.obsCore.s_xel2, - dataset.obsCore.s_resolution, - - dataset.obsCore.t_min, - dataset.obsCore.t_max, - dataset.obsCore.t_exptime, - dataset.obsCore.t_resolution, - dataset.obsCore.t_xel, - - dataset.obsCore.em_min, - dataset.obsCore.em_max, - dataset.obsCore.em_res_power, - dataset.obsCore.em_xel, - - dataset.obsCore.o_ucd, - - dataset.obsCore.pol_states, - dataset.obsCore.pol_xel, - - dataset.obsCore.facility_name, - dataset.obsCore.instrument_name, + obsCore.dataproduct_type, + obsCore.calib_level, + obsCore.obs_collection, + obsCore.obs_title, + obsCore.obs_id, + obsCore.obs_publisher_did, + obsCore.bib_reference, + obsCore.data_rights, + + obsCore.access_url, + obsCore.access_format, + obsCore.access_estsize, + + obsCore.target_name, + + obsCore.s_ra, + obsCore.s_dec, + obsCore.s_fov, + + obsCore.s_region, + obsCore.s_xel1, + obsCore.s_xel2, + obsCore.s_resolution, + + obsCore.t_min, + obsCore.t_max, + obsCore.t_exptime, + obsCore.t_resolution, + obsCore.t_xel, + + obsCore.em_min, + obsCore.em_max, + obsCore.em_res_power, + obsCore.em_xel, + + obsCore.o_ucd, + + obsCore.pol_states, + obsCore.pol_xel, + + obsCore.facility_name, + obsCore.instrument_name, }; } @@ -138,18 +138,18 @@ class ObscoreExt new ColumnInfo( "vel_max", Double.class, "Velocity max" ), }; - public static Object[] vlkbRow( Dataset dataset ) + public static Object[] vlkbRow( DbPSearch.ObsCore obsCore ) { return new Object[] { - dataset.overlapCode, - dataset.overlapCodeSky, - dataset.overlapCodeVel, + obsCore.overlapCode, + obsCore.overlapCodeSky, + obsCore.overlapCodeVel, - dataset.obsCore.s_region_galactic, + obsCore.s_region_galactic, - dataset.obsCore.vel_min, - dataset.obsCore.vel_max, + obsCore.vel_min, + obsCore.vel_max, }; } @@ -157,9 +157,9 @@ class ObscoreExt public static final ColumnInfo[] OBSCORE_VLKB_COLINFO = concat(OBSCORE_COLINFO, VLKB_COLINFO); - public static Object[] obscoreVlkbRow( Dataset dataset ) + public static Object[] obscoreVlkbRow( DbPSearch.ObsCore obsCore ) { - return concat(obscoreRow(dataset),vlkbRow(dataset)); + return concat(obscoreRow(obsCore),vlkbRow(obsCore)); } diff --git a/data-discovery/src/main/java/webapi/formatfilter/XmlSerializer.java b/data-discovery/src/main/java/webapi/formatfilter/XmlSerializer.java index 6e36122..37efb66 100644 --- a/data-discovery/src/main/java/webapi/formatfilter/XmlSerializer.java +++ b/data-discovery/src/main/java/webapi/formatfilter/XmlSerializer.java @@ -22,15 +22,15 @@ final class XmlSerializer public static void serializeToVoTable( PrintWriter writer, String charEncoding, - Dataset[] datasetArr, + DbPSearch.ObsCore[] obsCoreArr, String cutoutUrl, String mergeUrl, boolean showDuration, long startTime_msec) throws IOException { - StarTable dstable = makeSearchResultsTable( datasetArr ); + StarTable dstable = makeSearchResultsTable( obsCoreArr ); dstable.setParameter(new DescribedValue( new DefaultValueInfo("datacubeCount", Integer.class, "Count of all datacubes from VLKB-search" ), - datasetArr.length ) ); + obsCoreArr.length ) ); BufferedWriter out = new BufferedWriter( writer ); @@ -56,15 +56,15 @@ final class XmlSerializer out.flush(); } - private static StarTable makeSearchResultsTable(Dataset[] datasetArr) + private static StarTable makeSearchResultsTable(DbPSearch.ObsCore[] obsCoreArr) { RowListStarTable astro = new RowListStarTable( ObscoreExt.OBSCORE_VLKB_COLINFO ); - for(Dataset dataset : datasetArr) + for(DbPSearch.ObsCore obsCore : obsCoreArr) { - if(dataset.obsCore == null) continue; // FIXME skip mergeable datasets + if(obsCore == null) continue; // FIXME skip mergeable datasets - astro.addRow( ObscoreExt.obscoreVlkbRow(dataset) ); + astro.addRow( ObscoreExt.obscoreVlkbRow(obsCore) ); } return astro; -- GitLab