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

eliminates SubsurveyId uses COLLECTION instead

parent 08308c0f
No related branches found
No related tags found
No related merge requests found
import java.io.PrintWriter;
import java.util.Map;
class SubsurveyId
{
public String surveyName;
public String species;
public String transition;
public SubsurveyId(String surveyName, String species, String transition)
{
this.surveyName = surveyName;
this.species = species;
this.transition = transition;
}
public SubsurveyId(Map<String, String[]> params)
{
this.surveyName = getFirstValue(params, "surveyname");
this.species = getFirstValue(params, "species");
this.transition = getFirstValue(params, "transition");
}
// FIXME extend map with this and reuse in both Coord and Subsurvey
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
throw new IllegalArgumentException("parameter " + key + " has no value.");
}
public String toString()
{
return surveyName + " " + species + " "+ transition;
}
public void toXML(PrintWriter writer)
{
if(surveyName != null) writer.println("<SurveyName>"+surveyName+"</SurveyName>");
if(species != null) writer.println("<Species>"+species+"</Species>");
if(transition != null) writer.println("<Transition>"+transition+"</Transition>");
}
}
......@@ -35,7 +35,7 @@ public class DbPSearch
public String[] queryOverlapingPubdid(Coord coord, SubsurveyId subsurveyId)
public String[] queryOverlapingPubdid(Coord coord)
{
LOGGER.info("trace");
......@@ -58,26 +58,13 @@ public class DbPSearch
*/
}
if(subsurveyId != null)
if(coord.collection != null)
{
/* FIXME replace this implementation with exact string match once survey_id is defined in obs_core */
String addColl = "";
if(coord.collection.length() > 0)
addColl += "(obs_collection LIKE '%" + coord.collection + "%')";
String addSS = "";
if((subsurveyId.surveyName != null) && (subsurveyId.surveyName.length() > 0))
addSS += "(obs_collection LIKE '" + subsurveyId.surveyName + "%')";
if((subsurveyId.species != null) && (subsurveyId.species.length() > 0) )
{
if(addSS.length() > 0) addSS += " OR ";
addSS += "(obs_collection LIKE '%" + subsurveyId.species + "%')";
}
if((subsurveyId.transition != null) && (subsurveyId.transition.length() > 0) )
{
if(addSS.length() > 0) addSS += " OR ";
addSS += "(obs_collection LIKE '%" + subsurveyId.transition + "')";
};
if(addSS.length() > 0) theQuery += " AND (" + addSS + ")";
if(addColl.length() > 0) theQuery += " AND (" + addColl + ")";
}
theQuery += appendIntervalConstraint(coord.fov, "s_fov");
......
......@@ -64,8 +64,6 @@ public class SearchServlet extends javax.servlet.http.HttpServlet
{
Map<String, String[]> params = request.getParameterMap();
SubsurveyId subsurveyId = new SubsurveyId(params);
Coord coord = new Coord();
coord.pos = Pos.parsePos(params, DEFAULT_SKY_SYSTEM);
coord.band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM);
......@@ -105,7 +103,7 @@ public class SearchServlet extends javax.servlet.http.HttpServlet
{
dbps = new DbPSearch(settings.dbConn);
}
String[] pubdidArr = dbps.queryOverlapingPubdid(coord, subsurveyId);
String[] pubdidArr = dbps.queryOverlapingPubdid(coord);
final String RESPONSE_ENCODING = "UTF-8";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment