Project

General

Profile

« Previous | Next » 

Revision 3120

Added by perry over 17 years ago

Added preliminary support for multiple spatial schemas in the same metacat instance .. bug 2551

View differences:

lib/metacat.properties
233 233
runSpatialOption=true
234 234
regenerateCacheOnRestart=true
235 235

  
236
# Comma-seperated list of schemas containing spatial bounding boxes
237
# name corresponds to the docname stored in xml_documents table
238
spatialDocnameList=eml,fgdc
239

  
236 240
# XML paths to the four bounding coordinates
237
# these paths must be included in your indexPaths variable in build.properties
238
# these are the defaults for EML and have not been tested with other schemas
239
westBoundingCoordinatePath=geographicCoverage/boundingCoordinates/westBoundingCoordinate
240
eastBoundingCoordinatePath=geographicCoverage/boundingCoordinates/eastBoundingCoordinate
241
southBoundingCoordinatePath=geographicCoverage/boundingCoordinates/southBoundingCoordinate
242
northBoundingCoordinatePath=geographicCoverage/boundingCoordinates/northBoundingCoordinate
241
# These paths must be included in your indexPaths variable in build.properties
242
# Note the naming convention:
243
#   {docname}_{direction}BoundingCoordinatePath=.....
244
# Has not been tested with other schemas besides EML
245
eml_westBoundingCoordinatePath=geographicCoverage/boundingCoordinates/westBoundingCoordinate
246
eml_eastBoundingCoordinatePath=geographicCoverage/boundingCoordinates/eastBoundingCoordinate
247
eml_southBoundingCoordinatePath=geographicCoverage/boundingCoordinates/southBoundingCoordinate
248
eml_northBoundingCoordinatePath=geographicCoverage/boundingCoordinates/northBoundingCoordinate
249
fgdc_westBoundingCoordinatePath=spdom/bounding/westbc
250
fgdc_eastBoundingCoordinatePath=spdom/bounding/eastbc
251
fgdc_southBoundingCoordinatePath=spdom/bounding/southbc
252
fgdc_northBoundingCoordinatePath=spdom/bounding/northbc
243 253

  
244 254
docTitle=dataset/title
245 255
metacatUrl=@systemidserver@@servlet-path@
src/edu/ucsb/nceas/metacat/spatial/SpatialDocument.java
67 67
  Vector east = new Vector();
68 68
  Vector north = new Vector();
69 69

  
70
  String title = null;
70
  String title = "";
71 71
  String docid = null;
72 72

  
73 73
  /** 
......
75 75
   *
76 76
   * @param docid The document id to be represented spatially
77 77
   * @param dbconn The database connection shared from the refering method.
78
   * @todo Rewrite the title query to use xml_path_index
79 78
   */
80 79
  public SpatialDocument( String docid , DBConnection dbconn ) {
81 80

  
......
83 82
    PreparedStatement pstmt = null;
84 83
    ResultSet rs = null;
85 84
    this.dbconn = dbconn;
86

  
85
    boolean isSpatialDocument = false;
86
    String thisDocname = null;
87
    String westPath = null;
88
    String eastPath = null;
89
    String northPath = null;
90
    String southPath = null;
91
   
87 92
    /*
88
     * Get the bounding coordinates
93
     * Determine the docname/schema and decide how to proceed with
94
     * spatial harvest
89 95
     */
90
    String query = "SELECT path, nodedatanumerical, parentnodeid FROM xml_path_index"
91
    + " WHERE docid = '" + docid.trim() + "'"
92
    + " AND docid IN (SELECT distinct docid FROM xml_access WHERE docid = '" + docid.trim() 
93
    + "' AND principal_name = 'public' AND perm_type = 'allow')"
94
    + " AND (path = '" + MetaCatUtil.getOption("westBoundingCoordinatePath") + "'"
95
    + "  OR path = '" + MetaCatUtil.getOption("southBoundingCoordinatePath") + "'"
96
    + "  OR path = '" + MetaCatUtil.getOption("eastBoundingCoordinatePath") + "'"
97
    + "  OR path = '" + MetaCatUtil.getOption("northBoundingCoordinatePath") + "'"
98
    + " ) ORDER BY parentnodeid;";
99

  
96
    String query = "SELECT docname FROM xml_documents WHERE docid='" + docid.trim() + "';";
97
    String docname = "";
100 98
    try {
101 99
      pstmt = dbconn.prepareStatement(query);
102 100
      pstmt.execute();
103 101
      rs = pstmt.getResultSet();
104 102
      while (rs.next()) {
105
        if ( rs.getString(1).equals( MetaCatUtil.getOption("westBoundingCoordinatePath") ) )
106
            this.west.add( new Float(rs.getFloat(2)) );
107
        else if ( rs.getString(1).equals( MetaCatUtil.getOption("southBoundingCoordinatePath") ) )
108
            this.south.add( new Float(rs.getFloat(2)));
109
        else if ( rs.getString(1).equals( MetaCatUtil.getOption("eastBoundingCoordinatePath") ) )
110
            this.east.add( new Float(rs.getFloat(2)) );
111
        else if ( rs.getString(1).equals( MetaCatUtil.getOption("northBoundingCoordinatePath") ) )
112
            this.north.add( new Float(rs.getFloat(2)) );
113
        else
114
            log.error("** An xml path not related to your bounding coordinates was returned by this query \n" + query + "\n");
103
        docname = rs.getString(1);	
115 104
      }
116 105
      rs.close();
117 106
      pstmt.close();
118 107
    }
119 108
    catch(Exception e) {
120
      log.error(" ---- Could not get bounding coordinates for " + docid );
109
      log.error(" ---- Could not get docname for " + docid );
121 110
      e.printStackTrace();
122 111
    }      
112
    if (docname == null) 
113
	    docname = "";
123 114

  
124
    /*
125
     * Get the title
126
     */
127
    String docTitlePath = MetaCatUtil.getOption("docTitle");
128
    query = "select nodedata from xml_path_index where path = '" 
129
          + docTitlePath.trim() + "' and docid = '" + docid.trim() + "'";
115
    // Loop through all our spatial docnames and determine if the current document matches
116
    // If so, get the appropriate corner xpaths
117
    Vector spatialDocnames = MetaCatUtil.getOptionList( MetaCatUtil.getOption("spatialDocnameList") );
118
    for (int i = 0; i < spatialDocnames.size(); i++) {
119
	    thisDocname = ((String)spatialDocnames.elementAt(i)).trim();
120
	    if ( docname.trim().equals(thisDocname) ) {
121
		    isSpatialDocument = true;
130 122

  
131
    try {
132
      pstmt = dbconn.prepareStatement(query);
133
      pstmt.execute();
134
      rs = pstmt.getResultSet();
135
      if (rs.next())
136
        this.title = rs.getString(1);
137
        //log.warn(" \n\n****** TITLE query is " + query + " \n\n");
138
      rs.close();
139
      pstmt.close();
123
    		    //  determine its east,west,north and south coord xpaths
124
		    westPath = MetaCatUtil.getOption(thisDocname + "_westBoundingCoordinatePath");
125
		    eastPath = MetaCatUtil.getOption(thisDocname + "_eastBoundingCoordinatePath");
126
		    northPath = MetaCatUtil.getOption(thisDocname + "_northBoundingCoordinatePath");
127
		    southPath = MetaCatUtil.getOption(thisDocname + "_southBoundingCoordinatePath");
128
	    }
140 129
    }
141
    catch(Exception e) {
142
      log.error(" **** Error getting docids from getTitle for docid = "+docid);
143
      e.printStackTrace();
144
      log.error(" query ============== \n " + query);
145
      this.title = docid;
146
    }
147 130

  
148
    /* try {
149
        dbconn.close();
150
    } catch( java.sql.SQLException e ) {
151
        log.error("java.sql.SQLException");
131
    //  If it is a spatial document, harvest the corners and title 
132
    if (isSpatialDocument) {
133

  
134
	    /*
135
	     * Get the bounding coordinates
136
	     */
137
	    query = "SELECT path, nodedatanumerical, parentnodeid FROM xml_path_index"
138
	    + " WHERE docid = '" + docid.trim() + "'"
139
	    + " AND docid IN (SELECT distinct docid FROM xml_access WHERE docid = '" + docid.trim() 
140
	    + "' AND principal_name = 'public' AND perm_type = 'allow')"
141
	    + " AND (path = '" + westPath + "'"
142
	    + "  OR path = '" + southPath + "'"
143
	    + "  OR path = '" +  eastPath + "'"
144
	    + "  OR path = '" + northPath + "'"
145
	    + " ) ORDER BY parentnodeid;";
146

  
147
	    try {
148
	      pstmt = dbconn.prepareStatement(query);
149
	      pstmt.execute();
150
	      rs = pstmt.getResultSet();
151
	      while (rs.next()) {
152
		if ( rs.getString(1).equals(westPath) )
153
		    this.west.add( new Float(rs.getFloat(2)) );
154
		else if ( rs.getString(1).equals(southPath) )
155
		    this.south.add( new Float(rs.getFloat(2)) );
156
		else if ( rs.getString(1).equals(eastPath) )
157
		    this.east.add( new Float(rs.getFloat(2)) );
158
		else if ( rs.getString(1).equals(northPath) )
159
		    this.north.add( new Float(rs.getFloat(2)) );
160
		else
161
		    log.error("** An xml path not related to your bounding coordinates was returned by this query \n" + query + "\n");
162
	      }
163
	      rs.close();
164
	      pstmt.close();
165
	    }
166
	    catch(Exception e) {
167
	      log.error(" ---- Could not get bounding coordinates for " + docid );
168
	      e.printStackTrace();
169
	    }      
170

  
171
	    /*
172
	     * Get the title
173
	     */
174
	    String docTitlePath = MetaCatUtil.getOption("docTitle");
175
	    query = "select nodedata from xml_path_index where path = '" 
176
		  + docTitlePath.trim() + "' and docid = '" + docid.trim() + "'";
177

  
178
	    try {
179
	      pstmt = dbconn.prepareStatement(query);
180
	      pstmt.execute();
181
	      rs = pstmt.getResultSet();
182
	      if (rs.next())
183
		this.title = rs.getString(1);
184
	      rs.close();
185
	      pstmt.close();
186
	    }
187
	    catch(Exception e) {
188
	      log.error(" **** Error getting docids from getTitle for docid = "+docid);
189
	      e.printStackTrace();
190
	      this.title = docid;
191
	    }
152 192
    }
153
    */
154 193

  
155 194
  }
156 195

  

Also available in: Unified diff