Commit 08308c0f authored by Robert Butora's avatar Robert Butora
Browse files

creates flat VOTable response (removes Subsurvey)

parent 32fdca74
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ AUTH_DIR := ../auth
# all sources
#IA2CONVFILTER = $(AUTH_DIR)/src/main/java/IA2TokenConvFilter.java
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/output:src/main/java/search:src/main/java/webapi:$(AUTH_DIR)/src/main/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)
SERVLETS = $(wildcard src/main/java/webapi/*Servlet.java)
@@ -23,12 +23,12 @@ CLASSPATH = $(LIB_DIR)/*

.PHONY: build
build:
	echo "class Version { static String asString = \"$(VERSION)\";}" > src/main/java/output/Version.java
	echo "class Version { static String asString = \"$(VERSION)\";}" > src/main/java/webapi/Version.java
	javac $(JFLAGS) -cp :$(CLASSPATH) -sourcepath $(SRC_DIR) -d $(CLASS_DIR) $(SERVLETS) $(FILTERS) $(AUTHFILTERS) $(VOSI)

.PHONY: clean
clean : 
	rm -fr src/main/java/output/Version.java target
	rm -fr src/main/java/webapi/Version.java target


.PHONY: install
+0 −117
Original line number Diff line number Diff line

import java.util.logging.Logger;

/* for loadSubsurveys from csv */
import com.opencsv.*;
import com.opencsv.exceptions.*;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.io.IOException;

/* NOTE originally was in search/output : designed for serializing search output xml */

class Subsurvey
{
   private static final Logger LOGGER = Logger.getLogger("Subsurvey");

   String description;
   String surveyname;
   String species;
   String transition;
   double rf; // rest frequency
   String rf_unit;
   String vel_unit;
   Dataset[] datasetArr;


   Subsurvey() { datasetArr = null; }
   Subsurvey(Subsurvey ss)
   {
    this.description = ss.description;;
    this.surveyname = ss.surveyname;
    this.species = ss.species;
    this.transition = ss.transition;
    this.rf = ss.rf; 
    this.rf_unit = ss.rf_unit;
    this.vel_unit = ss.vel_unit;
      this.datasetArr = null;
   }

   String id() { return (this.surveyname + " " + this.species + " "  + this.transition); }

   boolean matches(String id) { return id.equals(this.id()); }


   static public Subsurvey findSubsurvey(Subsurvey[] dbSubsurveys, String subsurvey_id)
   {
      for(Subsurvey curr : dbSubsurveys)
      {
         if(curr.matches(subsurvey_id))
         {
            return curr;
         }
      }

      throw new AssertionError(subsurvey_id + " not found in surveys table");
   }

   public static Subsurvey[] loadSubsurveys(String csvFilename)
   {
      List<Subsurvey> subsurveyList = new ArrayList<>();

      try
      {
         // FIXME parser not robust:
         // * eats space-character also within the field:  ,  hu ha ,  --> "huha" not "hu ha"
         // * double quote used inside string not escaped: ,"blabla 25\" res",
         // * last record (line) is missing if that line is not closed with EOL
         // * UTF-8 or US-ASACII ?
         // * else ? how to validate/verify correctness

         CSVReaderHeaderAware csvReader = new CSVReaderHeaderAware(new FileReader(csvFilename));

         Map<String, String> values;

         while ((values = csvReader.readMap()) != null)
         {
            Subsurvey subsurvey = new Subsurvey();

            subsurvey.description   = values.get("description");
            subsurvey.surveyname    = values.get("name");
            subsurvey.species       = values.get("species");
            subsurvey.transition    = values.get("transition");
            subsurvey.rf            = Double.parseDouble(values.get("rest_frequency"));
            subsurvey.rf_unit       = values.get("restf_fits_unit");
            subsurvey.vel_unit      = values.get("velocity_fits_unit");

            subsurveyList.add(subsurvey);
         }


      }
      catch(IOException ex) 
      {
         LOGGER.info("Error while loading [" + csvFilename + "]: " + ex.getMessage());
         //return null;
         //throw new IllegalStateException("Error while loading " + csvFilename + " file", ex);
      }
      catch(CsvValidationException ex) 
      {
         LOGGER.info("Error while reading [" + csvFilename + "]: " + ex.getMessage());
         //return null;
         //throw new IllegalStateException("Error while reading " + csvFilename + " file", ex);
      }

      return subsurveyList.toArray(new Subsurvey[0]);
   }





}

+0 −83
Original line number Diff line number Diff line
import java.util.logging.Logger;
import java.util.List;
import java.util.ArrayList;

class SearchOutputData
{
   private static final Logger LOGGER = Logger.getLogger("SearchOutputData");

   String description;
   int datacubeCount;
   String versionString;
   Subsurvey[] subsurveyArr;


   public static SearchOutputData  marshall(Dataset[] datasetArr,
         /*SubsurveyId subsurveyId,*/ Subsurvey[] dbSubsurveys,
         String mergeUrlRoot, String mergeQueryString)
   {
      SearchOutputData sod = new SearchOutputData();

      sod.description = "Via Lactea Knowledge Base response (Search by pgSphere)";
      sod.versionString = "Search (pgSphere) version " + Version.asString;
      sod.datacubeCount = datasetArr.length;

      sod.subsurveyArr = groupBySubsurveys(datasetArr, /*subsurveyId,*/ dbSubsurveys, mergeUrlRoot, mergeQueryString);
      return sod;
   }

   // assumes datasetArr is already ordered by subsurveys
   private static Subsurvey[] groupBySubsurveys(Dataset[] datasetArr,
         /*SubsurveyId subsurveyId,*/ Subsurvey[] dbSubsurveys,
         String mergeUrlRoot, String mergeQueryString)
   {
      List<Subsurvey> subsurveyList = new ArrayList<Subsurvey>();

      if(datasetArr.length > 0)
      {
         List<Dataset> datasetList  = new ArrayList<Dataset>();
         String prevSubsurveyId = datasetArr[0].subsurvey_id;

         for(Dataset dataset : datasetArr)
         {

            if( ! prevSubsurveyId.equals(dataset.subsurvey_id) )
            {
               if( false )//Dataset.areDatasetsMergeable(datasetList) )
               {
                  Dataset mergedDataset = new Dataset(datasetList, /*subsurveyId,*/ mergeUrlRoot, mergeQueryString);
                  datasetList.add(mergedDataset);
               }

               Subsurvey subsurvey = new Subsurvey(Subsurvey.findSubsurvey(dbSubsurveys, prevSubsurveyId));

               subsurvey.datasetArr = datasetList.toArray(new Dataset[0]);
               subsurveyList.add(subsurvey);

               datasetList.clear();
            }

            datasetList.add( dataset );

            prevSubsurveyId = dataset.subsurvey_id;
         }

         if( false )//Dataset.areDatasetsMergeable(datasetList) )
         {
            Dataset mergedDataset = new Dataset(datasetList, /*subsurveyId,*/ mergeUrlRoot, mergeQueryString);
            datasetList.add(mergedDataset);
         }

         Subsurvey subsurvey = new Subsurvey(Subsurvey.findSubsurvey(dbSubsurveys, prevSubsurveyId));

         subsurvey.datasetArr = datasetList.toArray(new Dataset[0]);
         subsurveyList.add(subsurvey);

         datasetList.clear();
      }

      return subsurveyList.toArray(new Subsurvey[0]);
   }

}
+0 −475

File deleted.

Preview size limit exceeded, changes collapsed.

Loading