Project

General

Profile

« Previous | Next » 

Revision 662

Added by berkley almost 23 years ago

removed dependence on MetacatURL for URL handling. Added more flexible support for identifiers in the subject and object fields. They can now be just a docid, an http url or a metacat url.

View differences:

src/edu/ucsb/nceas/metacat/RelationHandler.java
17 17
import java.sql.*;
18 18
import java.util.*;
19 19
import java.lang.Thread; 
20
import java.net.*;
20 21

  
21 22
public class RelationHandler implements Runnable
22 23
{
......
61 62

  
62 63
    // deletes all of the relations with a docid of @docid.
63 64
    deleteRelations(docid);
64

  
65 65
    //pseudo-code algorithm
66 66
    //for each new relation r in xml_nodes
67 67
    //  put r into xml_relation
......
73 73
      PreparedStatement pstmt = conn.prepareStatement(
74 74
                                QuerySpecification.printPackageSQL(docid));
75 75
      pstmt.execute();
76
      
76 77
      //get the new relations out of xml_nodes
77 78
      ResultSet rs = pstmt.getResultSet();
78 79
      boolean hasmorerows = rs.next();
79 80
      while(hasmorerows)
80 81
      {
81 82
        String subject = rs.getString(1);
82
        MetacatURL subjectMurl = new MetacatURL(subject);
83 83
        String subjectDoctype = null;
84
        if(subjectMurl.getProtocol().equals("metacat"))
84
        String paramDocid = null;
85
        URL subjectMurl = null;
86

  
87
        try
85 88
        {
86
          DocumentImpl subDoc = new DocumentImpl(conn, 
87
                                                 subjectMurl.getParam(0)[1]);
88
          subjectDoctype = subDoc.getDoctype();
89
          subjectMurl = new URL(subject);
90
          subjectDoctype = null;
91
          Hashtable murlParams = util.parseQuery(subjectMurl.getQuery());
92
          paramDocid = (String)murlParams.get("docid"); 
89 93
        }
94
        catch(MalformedURLException murle)
95
        { //assume this is just a docid not a url
96
          paramDocid = subject;
97
        }
98
        
99
        DocumentImpl subDoc = new DocumentImpl(conn, paramDocid);
100
        subjectDoctype = subDoc.getDoctype();
90 101
        String relationship = rs.getString(2);
91 102
        String object = rs.getString(3);
92 103
      
......
140 151
            pstmt.execute();
141 152
          }
142 153
          
143
          hasmorerelations = relations.next();
154
          hasmorerelations = relations.next(); 
144 155
        }
145 156
        
146 157
        //get the current relations information
147
        MetacatURL subMurl = new MetacatURL(subject);
148
        MetacatURL objMurl = new MetacatURL(object);
158
        String subDocid = null;
159
        String objDocid = null;
149 160
        String subDoctype = null;
150 161
        String objDoctype = null;
151
        if(subMurl.getProtocol().equals("metacat"))
162
        
163
        try
152 164
        {
153
          DocumentImpl subDoc = new DocumentImpl(conn, subMurl.getParam(0)[1]);
154
          subDoctype = subDoc.getDoctype();
165
          URL subMurl = new URL(subject);
166
          Hashtable subMurlParams = util.parseQuery(subMurl.getQuery());
167
          subDocid = (String)subMurlParams.get("docid");
155 168
        }
156
        if(objMurl.getProtocol().equals("metacat"))
169
        catch(MalformedURLException murle)
170
        { //assume this is just a docid not a url
171
          subDocid = subject;
172
        }
173
        
174
        try
157 175
        {
158
          DocumentImpl objDoc = new DocumentImpl(conn, objMurl.getParam(0)[1]);
159
          objDoc.getDoctype();
176
          URL objMurl = new URL(object); 
177
          Hashtable objMurlParams = util.parseQuery(objMurl.getQuery());
178
          objDocid = (String)objMurlParams.get("docid");
160 179
        }
180
        catch(MalformedURLException murle)
181
        { //assume this is just a docid
182
          objDocid = object;
183
        }
184
        
185
        subDoc = new DocumentImpl(conn, subDocid);
186
        subDoctype = subDoc.getDoctype();
187
        DocumentImpl objDoc = new DocumentImpl(conn, objDocid);
188
        objDoc.getDoctype();
189
        
161 190
        //now that the comparisons are done, the new relation can be put
162 191
        //into xml_relation
163 192
        StringBuffer insertStmt = new StringBuffer();

Also available in: Unified diff