1
2
3
4
5
6
7 package org.astrogrid.dataservice.metadata.queryable;
8 import java.io.IOException;
9 import org.astrogrid.cfg.ConfigFactory;
10 import org.astrogrid.tableserver.metadata.TableInfo;
11 import org.astrogrid.tableserver.metadata.TableMetaDocInterpreter;
12 import org.astrogrid.dataservice.metadata.MetadataException;
13 import org.astrogrid.tableserver.test.SampleStarsPlugin;
14 import org.astrogrid.cfg.ConfigFactory;
15 import org.astrogrid.dataservice.queriers.DatabaseAccessException;
16
17 /***
18 * An implementation of QueryableResourceReader that looks in the config file
19 * for what to search on for cones
20 */
21
22 public class ConeConfigQueryableResource extends TableMetaDocInterpreter {
23
24 /*** Key used to look up the column containing RA for cone searches */
25 public static final String CONE_SEARCH_TABLE_KEY = "conesearch.table";
26 public static final String CONE_SEARCH_RA_COL_KEY = "conesearch.ra.column";
27 public static final String CONE_SEARCH_DEC_COL_KEY = "conesearch.dec.column";
28
29 /*** A temporary key specifying whether the db columns asre in degrees or radians */
30 public static final String CONE_SEARCH_COL_UNITS_KEY = "conesearch.columns.units";
31
32 public ConeConfigQueryableResource() throws IOException {
33 super();
34 try {
35
36
37 String plugin = ConfigFactory.getCommonConfig().getString(
38 "datacenter.querier.plugin");
39 if (plugin.equals(
40 "org.astrogrid.tableserver.test.SampleStarsPlugin")) {
41
42 SampleStarsPlugin.initialise();
43 }
44 }
45 catch (DatabaseAccessException dbe) {
46 throw new IOException(dbe.getMessage());
47 }
48 }
49
50
51 /*** Special case for spatial searches. Returns the groups that contain
52 * fields suitable for spatial searching */
53 public SearchGroup[] getSpatialGroups()
54 {
55 String configTable = ConfigFactory.getCommonConfig().getString(CONE_SEARCH_TABLE_KEY);
56 SearchGroup table = new TableInfo();
57 table.setId(configTable);
58 table.setName(configTable);
59 return new SearchGroup[] { table };
60
61 }
62
63 /*** botch botch botch */
64 public SearchField[] getSpatialFields(SearchGroup parent) throws IOException
65 {
66 if (parent.getId().equals(ConfigFactory.getCommonConfig().getString(CONE_SEARCH_TABLE_KEY))) {
67
68 String[] catalogNames = getCatalogs();
69 if (catalogNames.length == 0) {
70 throw new MetadataException("Server error: no catalog or table metadata are defined for this DSA/catalog installation; please check your metadoc file and/or configuration!");
71 }
72
73 SearchField[] fields = {
74 getColumn(catalogNames[0], parent.getName(), ConfigFactory.getCommonConfig().getString(CONE_SEARCH_RA_COL_KEY)),
75 getColumn(catalogNames[0], parent.getName(), ConfigFactory.getCommonConfig().getString(CONE_SEARCH_DEC_COL_KEY))
76 };
77 return fields;
78 }
79 else {
80 return null;
81 }
82 }
83 }
84
85