Revision 6794
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java | ||
---|---|---|
1155 | 1155 |
* @throws NotAuthorized |
1156 | 1156 |
* @throws InvalidRequest |
1157 | 1157 |
* @throws NotFound |
1158 |
* @throws JiBXException |
|
1159 |
* @throws IllegalAccessException |
|
1160 |
* @throws InstantiationException |
|
1161 |
* @throws IOException |
|
1158 | 1162 |
*/ |
1159 | 1163 |
public boolean setReplicationStatus(String pid) throws ServiceFailure, |
1160 | 1164 |
NotImplemented, InvalidToken, NotAuthorized, InvalidRequest, |
1161 | 1165 |
NotFound { |
1162 |
|
|
1163 |
File tmpDir = getTempDirectory(); |
|
1164 |
MultipartRequest mr = null; |
|
1166 |
|
|
1165 | 1167 |
boolean result = false; |
1166 | 1168 |
Identifier identifier = new Identifier(); |
1167 | 1169 |
identifier.setValue(pid); |
1168 |
long serialVersion = 0L; |
|
1169 |
String serialVersionStr = null; |
|
1170 |
BaseException failure = null; |
|
1170 | 1171 |
ReplicationStatus status = null; |
1171 | 1172 |
String replicationStatus = null; |
1172 | 1173 |
NodeReference targetNodeRef = null; |
... | ... | |
1174 | 1175 |
|
1175 | 1176 |
// Parse the params out of the multipart form data |
1176 | 1177 |
// Read the incoming data from its Mime Multipart encoding |
1177 |
logMetacat |
|
1178 |
.debug("Parsing ReplicaStatus from the mime multipart entity"); |
|
1178 |
logMetacat.debug("Parsing ReplicaStatus from the mime multipart entity"); |
|
1179 | 1179 |
|
1180 |
// handle MMP inputs |
|
1181 |
MultipartRequestResolver mrr = new MultipartRequestResolver( |
|
1182 |
tmpDir.getAbsolutePath(), 1000000000, 0); |
|
1183 |
|
|
1184 | 1180 |
try { |
1185 |
mr = mrr.resolveMultipart(request); |
|
1186 |
multipartparams = mr.getMultipartParameters(); |
|
1187 |
logMetacat.debug("Resolved the ReplicaStatus multipart request."); |
|
1188 |
|
|
1189 |
} catch (IOException e) { |
|
1190 |
throw new ServiceFailure("4852", |
|
1191 |
"Couldn't resolve the multipart request: " + e.getMessage()); |
|
1192 |
|
|
1193 |
} catch (FileUploadException e) { |
|
1194 |
throw new ServiceFailure("4852", |
|
1195 |
"Couldn't resolve the multipart request: " + e.getMessage()); |
|
1196 |
|
|
1197 |
} catch (Exception e) { |
|
1198 |
throw new ServiceFailure("4852", |
|
1199 |
"Couldn't resolve the multipart request: " + e.getMessage()); |
|
1200 |
|
|
1181 |
failure = collectReplicationStatus(); |
|
1182 |
|
|
1183 |
} catch (IOException e2) { |
|
1184 |
throw new ServiceFailure("4700", "Couldn't resolve the multipart request: " + |
|
1185 |
e2.getMessage()); |
|
1186 |
|
|
1187 |
} catch (InstantiationException e2) { |
|
1188 |
throw new ServiceFailure("4700", "Couldn't resolve the multipart request: " + |
|
1189 |
e2.getMessage()); |
|
1190 |
|
|
1191 |
} catch (IllegalAccessException e2) { |
|
1192 |
throw new ServiceFailure("4700", "Couldn't resolve the multipart request: " + |
|
1193 |
e2.getMessage()); |
|
1194 |
|
|
1195 |
} catch (JiBXException e2) { |
|
1196 |
throw new ServiceFailure("4700", "Couldn't resolve the multipart request: " + |
|
1197 |
e2.getMessage()); |
|
1198 |
|
|
1201 | 1199 |
} |
1202 |
|
|
1203 |
// get the serialVersion |
|
1204 |
try { |
|
1205 |
serialVersionStr = multipartparams.get("serialVersion").get(0); |
|
1206 |
serialVersion = new Long(serialVersionStr).longValue(); |
|
1207 |
|
|
1208 |
} catch (NumberFormatException nfe) { |
|
1209 |
String msg = "The 'serialVersion' must be a positive integer and was not."; |
|
1210 |
logMetacat.error(msg); |
|
1211 |
throw new InvalidRequest("4730", msg); |
|
1212 |
|
|
1213 |
} catch (NullPointerException e) { |
|
1214 |
logMetacat |
|
1215 |
.debug("The 'serialVersion' parameter was not found in the " |
|
1216 |
+ "multipartparams map. Trying the params map."); |
|
1217 |
try { |
|
1218 |
serialVersionStr = params.get("serialVersion")[0]; |
|
1219 |
serialVersion = new Long(serialVersionStr).longValue(); |
|
1220 |
|
|
1221 |
} catch (NumberFormatException e1) { |
|
1222 |
String msg = "The 'serialVersion' must be a positive integer and was not."; |
|
1223 |
logMetacat.error(msg); |
|
1224 |
throw new InvalidRequest("4730", msg); |
|
1225 |
|
|
1226 |
} catch (NullPointerException npe) { |
|
1227 |
String msg = "The 'serialVersion' must be provided as a parameter and was not."; |
|
1228 |
logMetacat.error(msg); |
|
1229 |
throw new InvalidRequest("4730", msg); |
|
1230 |
|
|
1231 |
} |
|
1232 |
|
|
1233 |
} |
|
1234 |
|
|
1200 |
|
|
1235 | 1201 |
// get the replication status param |
1236 | 1202 |
try { |
1237 | 1203 |
replicationStatus = multipartparams.get("status").get(0); |
... | ... | |
1281 | 1247 |
} |
1282 | 1248 |
|
1283 | 1249 |
result = CNodeService.getInstance(request).setReplicationStatus( |
1284 |
session, identifier, targetNodeRef, status, serialVersion);
|
|
1250 |
session, identifier, targetNodeRef, status, failure);
|
|
1285 | 1251 |
response.setStatus(200); |
1286 | 1252 |
response.setContentType("text/xml"); |
1287 | 1253 |
return result; |
Also available in: Unified diff
Modify CNresourceHandler.setReplicationStatus() to use the new API signature, including the failure BaseException that is parsed out of the MMP as a file section. Log the exception message. Since this is an asynchronous call, ReplicationManager won't see a failed status, but the MNAuditTask eventually will.