Revision 743
Added by Matt Jones almost 23 years ago
RelationHandler.java | ||
---|---|---|
48 | 48 |
} |
49 | 49 |
catch(Exception e) |
50 | 50 |
{ |
51 |
System.out.println("unable to get db connection in relationhandler." +
|
|
51 |
MetaCatUtil.debugMessage("unable to get db connection in " +
|
|
52 | 52 |
"relationhandler: " + e.getMessage()); |
53 | 53 |
} |
54 | 54 |
this.xmldoc = xmldoc; |
... | ... | |
65 | 65 |
*/ |
66 | 66 |
public void run() |
67 | 67 |
{ |
68 |
MetaCatUtil.debugMessage("Running relation handler!"); |
|
68 | 69 |
Connection dbconn = null; |
69 | 70 |
String docid = xmldoc.getDocID(); |
71 |
String packagetype = xmldoc.getDoctype(); |
|
70 | 72 |
// deletes all of the relations with a docid of @docid. |
71 | 73 |
deleteRelations(docid); |
72 | 74 |
//pseudo-code algorithm |
... | ... | |
79 | 81 |
{ |
80 | 82 |
dbconn = MetacatReplication.getDBConnection("RelationHandler." + |
81 | 83 |
"run"); |
84 |
|
|
82 | 85 |
PreparedStatement pstmt = dbconn.prepareStatement( |
83 | 86 |
QuerySpecification.printPackageSQL(docid)); |
84 | 87 |
pstmt.execute(); |
... | ... | |
89 | 92 |
while(hasmorerows) |
90 | 93 |
{ |
91 | 94 |
String subject = rs.getString(1); |
95 |
String relationship = rs.getString(2); |
|
96 |
String object = rs.getString(3); |
|
97 |
|
|
92 | 98 |
String subjectDoctype = null; |
93 | 99 |
String paramDocid = null; |
94 | 100 |
URL subjectMurl = null; |
95 | 101 |
|
96 |
try |
|
97 |
{ |
|
98 |
subjectMurl = new URL(subject); |
|
99 |
subjectDoctype = null; |
|
100 |
Hashtable murlParams = util.parseQuery(subjectMurl.getQuery()); |
|
101 |
paramDocid = (String)murlParams.get("docid"); |
|
102 |
} |
|
103 |
catch(MalformedURLException murle) |
|
104 |
{ //assume this is just a docid not a url |
|
105 |
paramDocid = subject; |
|
106 |
} |
|
107 |
|
|
108 |
DocumentImpl subDoc = new DocumentImpl(dbconn, paramDocid); |
|
109 |
subjectDoctype = subDoc.getDoctype(); |
|
110 |
String relationship = rs.getString(2); |
|
111 |
String object = rs.getString(3); |
|
112 |
|
|
113 |
//compare r to each relation in xml_relation |
|
114 |
|
|
115 |
pstmt = dbconn.prepareStatement("select subject, subdoctype, " + |
|
116 |
"relationship, object, objdoctype " + |
|
117 |
"from xml_relation"); |
|
118 |
pstmt.execute(); |
|
119 |
//get each relation in xml_relation for comparison |
|
120 |
ResultSet relations = pstmt.getResultSet(); |
|
121 |
boolean hasmorerelations = relations.next(); |
|
122 |
while(hasmorerelations) |
|
123 |
{ |
|
124 |
String currentSub = relations.getString(1); |
|
125 |
String currentSubDoctype = relations.getString(2); |
|
126 |
String currentRelationship = relations.getString(3); |
|
127 |
String currentObj = relations.getString(4); |
|
128 |
String currentObjDoctype = relations.getString(5); |
|
129 |
|
|
130 |
if(object.equals(currentObj)) |
|
131 |
{//there is a transitive relation so add a new relation to the table |
|
132 |
StringBuffer insertTransRelation = new StringBuffer(); |
|
133 |
insertTransRelation.append("insert into xml_relation (docid, "); |
|
134 |
insertTransRelation.append(" subject, "); |
|
135 |
insertTransRelation.append("subdoctype, relationship, object, "); |
|
136 |
insertTransRelation.append("objdoctype) values ('"); |
|
137 |
insertTransRelation.append(docid).append("', '"); |
|
138 |
insertTransRelation.append(currentSub).append("', '"); |
|
139 |
insertTransRelation.append(currentSubDoctype).append("', "); |
|
140 |
insertTransRelation.append("'hasTransitiveRelationTo', '"); |
|
141 |
insertTransRelation.append(subject).append("', '"); |
|
142 |
insertTransRelation.append(subjectDoctype).append("')"); |
|
143 |
//System.out.println("sql1: " + insertTransRelation.toString()); |
|
144 |
pstmt = dbconn.prepareStatement(insertTransRelation.toString()); |
|
145 |
pstmt.execute(); |
|
146 |
|
|
147 |
insertTransRelation = new StringBuffer(); |
|
148 |
//put the same relation in with the subject and object switched |
|
149 |
insertTransRelation.append("insert into xml_relation (docid, "); |
|
150 |
insertTransRelation.append(" subject, "); |
|
151 |
insertTransRelation.append("subdoctype, relationship, object, "); |
|
152 |
insertTransRelation.append("objdoctype) values ('"); |
|
153 |
insertTransRelation.append(docid).append("', '"); |
|
154 |
insertTransRelation.append(subject).append("', '"); |
|
155 |
insertTransRelation.append(subjectDoctype).append("', "); |
|
156 |
insertTransRelation.append("'hasTransitiveRelationTo', '"); |
|
157 |
insertTransRelation.append(currentSub).append("', '"); |
|
158 |
insertTransRelation.append(currentSubDoctype).append("')"); |
|
159 |
//System.out.println("sql2: " + insertTransRelation.toString()); |
|
160 |
pstmt = dbconn.prepareStatement(insertTransRelation.toString()); |
|
161 |
pstmt.execute(); |
|
162 |
} |
|
163 |
|
|
164 |
hasmorerelations = relations.next(); |
|
165 |
} |
|
166 |
|
|
167 | 102 |
//get the current relations information |
168 | 103 |
String subDocid = null; |
169 | 104 |
String objDocid = null; |
... | ... | |
179 | 114 |
subDocid = (String)subMurlParams.get("docid"); |
180 | 115 |
if(subMurl.getProtocol().equals("metacat")) |
181 | 116 |
{ |
182 |
subDoc = new DocumentImpl(dbconn, subDocid); |
|
117 |
DocumentImpl subDoc = new DocumentImpl(dbconn, subDocid);
|
|
183 | 118 |
subDoctype = subDoc.getDoctype(); |
184 | 119 |
} |
185 | 120 |
} |
... | ... | |
220 | 155 |
//now that the comparisons are done, the new relation can be put |
221 | 156 |
//into xml_relation |
222 | 157 |
StringBuffer insertStmt = new StringBuffer(); |
223 |
insertStmt.append("insert into xml_relation (docid, subject, ");
|
|
224 |
insertStmt.append("subdoctype, "); |
|
158 |
insertStmt.append("insert into xml_relation (docid, packagetype, ");
|
|
159 |
insertStmt.append("subject, subdoctype, ");
|
|
225 | 160 |
insertStmt.append("relationship, object, objdoctype) values ('"); |
226 | 161 |
insertStmt.append(docid).append("', '"); |
162 |
insertStmt.append(packagetype).append("', '"); |
|
227 | 163 |
insertStmt.append(subject).append("', '"); |
228 | 164 |
insertStmt.append(subDoctype).append("', '"); |
229 | 165 |
insertStmt.append(relationship).append("', '"); |
... | ... | |
244 | 180 |
} |
245 | 181 |
catch(Exception e) |
246 | 182 |
{ |
247 |
System.out.println("Error in relationHandler.run: " + e.getMessage()); |
|
248 |
util.debugMessage("Error in relationHandler.run: " + e.getMessage()); |
|
249 |
e.printStackTrace(System.out); |
|
183 |
MetaCatUtil.debugMessage("Error in relationHandler.run: " + |
|
184 |
e.getMessage()); |
|
250 | 185 |
btThread = null; |
251 | 186 |
try |
252 | 187 |
{ |
... | ... | |
270 | 205 |
} |
271 | 206 |
catch(Exception ee) |
272 | 207 |
{ |
273 |
System.out.println("error in relationHandler.deleteRelations: " +
|
|
208 |
MetaCatUtil.debugMessage("error in relationHandler.deleteRelations: " +
|
|
274 | 209 |
ee.getMessage()); |
275 | 210 |
} |
276 | 211 |
|
... | ... | |
284 | 219 |
} |
285 | 220 |
catch(Exception e) |
286 | 221 |
{ |
287 |
System.out.println("error in RelationHandler.deleteRelations(): " +
|
|
222 |
MetaCatUtil.debugMessage("error in RelationHandler.deleteRelations(): " +
|
|
288 | 223 |
e.getMessage()); |
289 |
e.printStackTrace(System.out); |
|
290 | 224 |
try |
291 | 225 |
{ |
292 | 226 |
dbconn.rollback(); |
... | ... | |
294 | 228 |
} |
295 | 229 |
catch (SQLException sqle) {} |
296 | 230 |
} |
297 |
|
|
298 | 231 |
} |
299 | 232 |
} |
Also available in: Unified diff
Modifications that change the package handling behavior of metacat. Package
membership is now determined by an identifier being used as either the subject
or object in a triple. One can not request arbitrary returndocs -- only
those types that have package information embedded can be "returndoctype"
document types. Right now only one "returndoctype" field can be provided.
This needs to be changed to support multiple potential returndoctype fields.
Packages are now defined by triple elements in the eml-dataset-2.0 module,
and so changes reflect this.
Added a new column (packagetype) to xml_relation that defines the document type
of the package for that record.
In addition, I changed the behavior of metacat queries when "back tracing" is
requested. If a "returndoc" element is present in the pathquery, then the
documents are searched, and any hits are traced back to the package with
which the hit document is linked, if it is of type returndoc. Thus, any
hit returns all of the package documents with which the hit document is
associated. If a hit does not have an associated package, no record is
returned for that hit (this is different from previous metacat behavior).
If no returndoc parameter is provided, all docs are searched and all hits
returned.
A new query parameter was added to pathquery that allows us to filter which
document types are searched (independent of the back tracing feature). If
one or more "filterdoctype" element is included, only documents which are
in that list of types will be searched. If you search for doctype A, but
request that doctype B be returned, only documents of type B that have a
package member of type A and match the search criteria will be returned.
To implement this I had to modify many html files, and change substantial
code in DBQuery, QuerySepcification, and MetaCatServlet.
These changes break the URL handling code that was present previously --
now all identifiers are assumed to be from the metacat system, not in
URL format. This probably needs to be revisited.