Revision 6268
Added by ben leinfelder almost 13 years ago
CNResourceHandler.java | ||
---|---|---|
28 | 28 |
import java.io.IOException; |
29 | 29 |
import java.io.InputStream; |
30 | 30 |
import java.io.OutputStream; |
31 |
import java.io.PrintWriter; |
|
31 | 32 |
import java.util.Date; |
32 | 33 |
import java.util.Hashtable; |
33 | 34 |
import java.util.Iterator; |
... | ... | |
56 | 57 |
import org.dataone.service.exceptions.NotImplemented; |
57 | 58 |
import org.dataone.service.exceptions.ServiceFailure; |
58 | 59 |
import org.dataone.service.exceptions.UnsupportedType; |
60 |
import org.dataone.service.types.AccessPolicy; |
|
59 | 61 |
import org.dataone.service.types.Checksum; |
60 | 62 |
import org.dataone.service.types.Event; |
61 | 63 |
import org.dataone.service.types.Identifier; |
... | ... | |
196 | 198 |
} |
197 | 199 |
// reserve the ID (in params) |
198 | 200 |
if (httpVerb == GET) { |
199 |
asserRelation(objectId); |
|
201 |
assertRelation(objectId);
|
|
200 | 202 |
status = true; |
201 | 203 |
} |
202 | 204 |
} else if (resource.equals(RESOURCE_RESOLVE)) { |
... | ... | |
545 | 547 |
* Implements REST version of DataONE CRUD API --> getSystemMetadata |
546 | 548 |
* @param guid ID of data object to be read |
547 | 549 |
*/ |
548 |
@Override |
|
549 | 550 |
protected void getSystemMetadataObject(String guid) { |
550 | 551 |
OutputStream out = null; |
551 | 552 |
try { |
... | ... | |
927 | 928 |
} |
928 | 929 |
} |
929 | 930 |
|
930 |
private boolean asserRelation(String id) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented { |
|
931 |
private boolean assertRelation(String id) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented {
|
|
931 | 932 |
Identifier pidOfSubject = new Identifier(); |
932 | 933 |
pidOfSubject.setValue(id); |
933 | 934 |
Identifier pidOfObject = new Identifier(); |
... | ... | |
1112 | 1113 |
serializeException(e, out); |
1113 | 1114 |
} |
1114 | 1115 |
} |
1116 |
|
|
1117 |
/** |
|
1118 |
* set the access perms on a document |
|
1119 |
* @throws Exception |
|
1120 |
*/ |
|
1121 |
protected void setaccess() throws Exception |
|
1122 |
{ |
|
1123 |
try |
|
1124 |
{ |
|
1125 |
String guid = params.get("guid")[0]; |
|
1126 |
Identifier id = new Identifier(); |
|
1127 |
id.setValue(guid); |
|
1128 |
String accesspolicy = params.get("accesspolicy")[0]; |
|
1129 |
AccessPolicy accessPolicy = (AccessPolicy) deserializeServiceType(AccessPolicy.class, new ByteArrayInputStream(accesspolicy.getBytes("UTF-8"))); |
|
1130 |
CNodeService.getInstance().setAccessPolicy(session, id, accessPolicy); |
|
1131 |
} |
|
1132 |
catch(Exception e) |
|
1133 |
{ |
|
1134 |
response.setStatus(500); |
|
1135 |
printError("Error setting access in D1ResourceHandler: " + e.getClass() + ": " + e.getMessage(), response); |
|
1136 |
throw e; |
|
1137 |
} |
|
1138 |
} |
|
1139 |
|
|
1140 |
/** |
|
1141 |
* Earthgrid API > Query Service > Query Function : translates ecogrid query document to metacat query |
|
1142 |
* then calls DBQuery > createResultDocument function and then again translate resultset to ecogrid resultset |
|
1143 |
* |
|
1144 |
* NOTE: |
|
1145 |
* This is the only method that uses EcoGrid classes for its implementation. |
|
1146 |
* It does so because it takes an EcoGrid Query as input, and outputs an |
|
1147 |
* EcoGrid ResultSet document. These documents are parsed by the auto-generated |
|
1148 |
* EcoGrid classes from axis, and so we link to them here rather than re-inventing them. |
|
1149 |
* This creates a circular dependency, because the Metacat classes are needed |
|
1150 |
* to build the EcoGrid implementation, and the EcoGrid jars are needed to build this query() |
|
1151 |
* method. This circularity could be resolved by moving the EcoGrid classes |
|
1152 |
* to Metacat directly. As we transition away from EcoGrid SOAP methods in |
|
1153 |
* favor of these REST interfaces, this circular dependency can be eliminated. |
|
1154 |
* |
|
1155 |
* @throws Exception |
|
1156 |
*/ |
|
1157 |
private void query() throws Exception { |
|
1158 |
/* This block commented out because of the EcoGrid circular dependency. |
|
1159 |
* For now, query will not be supported until the circularity can be |
|
1160 |
* resolved, probably by moving the ecogrid query syntax transformers |
|
1161 |
* directly into the Metacat codebase. MBJ 2010-02-03 |
|
1162 |
|
|
1163 |
try { |
|
1164 |
EcogridQueryParser parser = new EcogridQueryParser(request |
|
1165 |
.getReader()); |
|
1166 |
parser.parseXML(); |
|
1167 |
QueryType queryType = parser.getEcogridQuery(); |
|
1168 |
EcogridJavaToMetacatJavaQueryTransformer queryTransformer = |
|
1169 |
new EcogridJavaToMetacatJavaQueryTransformer(); |
|
1170 |
QuerySpecification metacatQuery = queryTransformer |
|
1171 |
.transform(queryType); |
|
1115 | 1172 |
|
1173 |
DBQuery metacat = new DBQuery(); |
|
1174 |
|
|
1175 |
boolean useXMLIndex = (new Boolean(PropertyService |
|
1176 |
.getProperty("database.usexmlindex"))).booleanValue(); |
|
1177 |
String xmlquery = "query"; // we don't care the query in resultset, |
|
1178 |
// the query can be anything |
|
1179 |
PrintWriter out = null; // we don't want metacat result, so set out null |
|
1180 |
|
|
1181 |
// parameter: queryspecification, user, group, usingIndexOrNot |
|
1182 |
StringBuffer result = metacat.createResultDocument(xmlquery, |
|
1183 |
metacatQuery, out, username, groupNames, useXMLIndex); |
|
1184 |
|
|
1185 |
// create result set transfer |
|
1186 |
String saxparser = PropertyService.getProperty("xml.saxparser"); |
|
1187 |
MetacatResultsetParser metacatResultsetParser = new MetacatResultsetParser( |
|
1188 |
new StringReader(result.toString()), saxparser, queryType |
|
1189 |
.getNamespace().get_value()); |
|
1190 |
ResultsetType records = metacatResultsetParser.getEcogridResult(); |
|
1191 |
|
|
1192 |
System.out |
|
1193 |
.println(EcogridResultsetTransformer.toXMLString(records)); |
|
1194 |
response.setContentType("text/xml"); |
|
1195 |
out = response.getWriter(); |
|
1196 |
out.print(EcogridResultsetTransformer.toXMLString(records)); |
|
1197 |
|
|
1198 |
} catch (Exception e) { |
|
1199 |
e.printStackTrace(); |
|
1200 |
}*/ |
|
1201 |
response.setContentType("text/xml"); |
|
1202 |
response.setStatus(501); |
|
1203 |
PrintWriter out = response.getWriter(); |
|
1204 |
out.print("<error>Query operation not yet supported by Metacat.</error>"); |
|
1205 |
out.close(); |
|
1206 |
} |
|
1207 |
|
|
1116 | 1208 |
} |
Also available in: Unified diff
cleaning up the handlers -- removing superclass methods.