120 |
120 |
message = handleDocIdSelect();
|
121 |
121 |
clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message);
|
122 |
122 |
|
123 |
|
} else if (action.equals("Replace")) {
|
124 |
|
message = "Not implemented, come back another day";
|
125 |
|
clientViewBean.setMessage(ClientView.REPLACE_MESSAGE, message);
|
126 |
|
|
127 |
123 |
} else if (action.equals("Upload")) {
|
128 |
124 |
message = "";
|
129 |
125 |
//*** Only process request if a file upload.
|
... | ... | |
135 |
131 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, message);
|
136 |
132 |
|
137 |
133 |
} else if (action.equals("Update")) {
|
138 |
|
System.out.println("ClientViewHelper.clientRequest: Update");
|
|
134 |
System.out.println("This is not implemented here. Call ClientViewHelper.jspx");
|
139 |
135 |
} else if (action.equals("Scope")) {
|
140 |
136 |
message = handleDocIdSelect();
|
141 |
137 |
clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message);
|
... | ... | |
265 |
261 |
//*** Get the data file's DOC ID.
|
266 |
262 |
nextDocId = nextDocId(lastDocId, clientViewBean.getUsername());
|
267 |
263 |
|
268 |
|
//*** Set the file format (just using file extension for now).
|
269 |
|
idx = fileName.lastIndexOf(".");
|
270 |
|
if (idx > 1)
|
271 |
|
formatType = fileName.substring(idx+1).toUpperCase();
|
272 |
|
else
|
273 |
|
formatType = "";
|
274 |
|
|
275 |
|
fileInfo = new String[2];
|
276 |
|
fileInfo[ClientView.FORMAT_TYPE] = formatType;
|
277 |
|
fileInfo[ClientView.FILE_NAME] = fileName.toString();
|
278 |
|
|
|
264 |
fileInfo = parseFileInfo(fileName.toString());
|
279 |
265 |
dataDocIDs.put(nextDocId, fileInfo);
|
280 |
266 |
//*** Upload the data file to metacat.
|
281 |
267 |
getMetacatClient().upload(nextDocId, fileName.toString(), inputStream, Integer.MAX_VALUE);
|
... | ... | |
315 |
301 |
}
|
316 |
302 |
|
317 |
303 |
public String handleFileUpdate(MultipartParser multipartParser) throws Exception {
|
318 |
|
Reader reader;
|
319 |
304 |
String result = "", fNm, action, lastDocId, newDocId, xPathQuery;
|
320 |
305 |
InputStream inputStream;
|
321 |
306 |
HashMap paramsMap;
|
322 |
307 |
StringBuilder fileName;
|
323 |
308 |
Iterator iterIt;
|
324 |
309 |
boolean sendIt;
|
|
310 |
String metadataDocId, fileInfo[];
|
325 |
311 |
|
326 |
312 |
paramsMap = new HashMap();
|
327 |
313 |
fileName = new StringBuilder();
|
328 |
314 |
if ((inputStream = getNextInputStream(multipartParser, fileName, paramsMap)) != null) {
|
329 |
315 |
action = (String) paramsMap.get("action");
|
|
316 |
//*** Get the Doc Id.
|
330 |
317 |
lastDocId = (String) paramsMap.get("docid");
|
|
318 |
//*** Get the metadata Doc Id.
|
|
319 |
metadataDocId = (String) paramsMap.get("metadataDocId");
|
331 |
320 |
fNm = fileName.toString();
|
|
321 |
|
332 |
322 |
try {
|
333 |
|
if (fNm.toLowerCase().endsWith(".xml") && action.toLowerCase().contains("metadata")) {
|
|
323 |
if (lastDocId.equals(metadataDocId)) { //*** This is the metadata file.
|
334 |
324 |
//*** Keep it here for updating.
|
335 |
325 |
setMetadataDoc(inputStream);
|
336 |
326 |
if (ClientFgdcHelper.isFGDC(getMetadataDoc())) {
|
|
327 |
clientViewBean.setContentStandard(ClientView.FEDERAL_GEOGRAPHIC_DATA_COMMITTEE);
|
337 |
328 |
if (!ClientFgdcHelper.hasMetacatInfo(lastDocId, getMetadataDoc())) {
|
338 |
329 |
result = "Update not performed: the Metadata file has no prior Metacat info in it.";
|
339 |
330 |
} else {
|
340 |
|
//xPathQuery = String.format(ClientFgdcHelper.XPATH_QUERY_TEMPLATE, lastDocId);
|
341 |
331 |
xPathQuery = ClientFgdcHelper.XPATH_QUERY_TEMPLATE.replaceFirst("%1s", lastDocId);
|
342 |
|
//*** Update the metadata with the new Doc Id version.
|
343 |
|
newDocId = nextVersion(lastDocId, xPathQuery);
|
344 |
|
//*** Upload the metadata file to metacat.
|
345 |
|
reader = XMLUtilities.getDOMTreeAsReader(getMetadataDoc().getDocumentElement(), false);
|
346 |
|
getMetacatClient().update(newDocId, reader, null);
|
347 |
|
reader.close();
|
|
332 |
newDocId = updateMetadataDoc(lastDocId, xPathQuery, fNm);
|
348 |
333 |
result = "MetaCat Package Updated: the Document Identifier is " + newDocId;
|
349 |
334 |
}
|
350 |
335 |
} else {
|
351 |
336 |
//***TODO This is EML.
|
|
337 |
clientViewBean.setContentStandard(ClientView.ECOLOGICAL_METADATA_LANGUAGE);
|
352 |
338 |
result = "Currently this functionality only supports FGDC metadata.";
|
353 |
339 |
}
|
354 |
340 |
} else {
|
355 |
341 |
//*** This is a data file.
|
356 |
|
result = "This is a data file. action: " + action + " lastDocId: " + lastDocId + " fNm: " + fNm;
|
|
342 |
//*** Query for the metadata, we need to update it with the new data file doc id.
|
|
343 |
setMetadataDoc(metadataDocId);
|
|
344 |
if (ClientFgdcHelper.isFGDC(getMetadataDoc())) {
|
|
345 |
clientViewBean.setContentStandard(ClientView.FEDERAL_GEOGRAPHIC_DATA_COMMITTEE);
|
|
346 |
fileInfo = parseFileInfo(fNm);
|
|
347 |
|
|
348 |
xPathQuery = ClientFgdcHelper.FGDC_DATA_FILE_QUERY_XPATH.replaceFirst("%1s", lastDocId);
|
|
349 |
newDocId = nextVersion(lastDocId, xPathQuery);
|
|
350 |
ClientFgdcHelper.updateFileNameAndType(getMetadataDoc().getDocumentElement(), newDocId, fileInfo);
|
|
351 |
//*** Upload the data file to metacat.
|
|
352 |
//result = getMetacatClient().upload(newDocId, fNm, inputStream, Integer.MAX_VALUE);
|
|
353 |
result = "Updated " + lastDocId + " with " + fNm + " (" + newDocId + ") ";
|
|
354 |
|
|
355 |
//*** Upload the metadata file to metacat.
|
|
356 |
xPathQuery = ClientFgdcHelper.XPATH_QUERY_TEMPLATE.replaceFirst("%1s", lastDocId);
|
|
357 |
newDocId = updateMetadataDoc(metadataDocId, xPathQuery, null);
|
|
358 |
System.out.println("ClientViewHelper.handleFileUpdate:\n" + XMLUtilities.getDOMTreeAsString(getMetadataDoc().getDocumentElement()));
|
|
359 |
} else {
|
|
360 |
//***TODO This is EML.
|
|
361 |
clientViewBean.setContentStandard(ClientView.ECOLOGICAL_METADATA_LANGUAGE);
|
|
362 |
result = "Currently this functionality only supports FGDC metadata.";
|
|
363 |
}
|
357 |
364 |
|
358 |
|
//newDocId = "TODO";
|
359 |
|
//reader = null; //TODO
|
360 |
|
//getMetacatClient().insert(newDocId, reader, null);
|
361 |
|
//reader.close();
|
362 |
365 |
}
|
363 |
|
|
364 |
|
|
365 |
|
//*** Pass on the public read access. TODO
|
366 |
|
// if(hasPublicAccess)
|
367 |
|
// getMetacatClient().setAccess(newDocId, "public", "read", "allow", "allowFirst");
|
368 |
366 |
} catch (java.io.IOException ex) {
|
369 |
367 |
ex.printStackTrace();
|
370 |
368 |
}
|
371 |
|
|
372 |
|
//DEBUG STUFF
|
373 |
|
//String key, val;
|
374 |
|
//result = "-----------------iteration------------<br/>fNm = " + fNm + "<br/>";
|
375 |
|
//iterIt = paramsMap.keySet().iterator();
|
376 |
|
//while(iterIt.hasNext()) {
|
377 |
|
// key = (String) iterIt.next();
|
378 |
|
// val = (String) paramsMap.get(key);
|
379 |
|
// result += key + ": " + val + "<br/>";
|
380 |
|
//}
|
381 |
|
|
382 |
369 |
} else {
|
383 |
370 |
result = "Please enter the updated file path/name.";
|
384 |
371 |
}
|
385 |
372 |
return(result);
|
386 |
373 |
}
|
387 |
374 |
|
|
375 |
private String updateMetadataDoc(String lastDocId, String docIdPath, String origFileName) {
|
|
376 |
String newDocId = null;
|
|
377 |
Reader reader;
|
|
378 |
|
|
379 |
//*** Update the metadata with the new Doc Id version.
|
|
380 |
try {
|
|
381 |
newDocId = nextVersion(lastDocId, docIdPath);
|
|
382 |
if (origFileName != null) {
|
|
383 |
if (clientViewBean.getContentStandard().equals(ClientView.FEDERAL_GEOGRAPHIC_DATA_COMMITTEE))
|
|
384 |
ClientFgdcHelper.updateMetadataFileName(getMetadataDoc().getDocumentElement(), newDocId, origFileName);
|
|
385 |
else
|
|
386 |
; //TODO EML, etc.
|
|
387 |
}
|
|
388 |
//*** Upload the metadata file to metacat.
|
|
389 |
//reader = XMLUtilities.getDOMTreeAsReader(getMetadataDoc().getDocumentElement(), false);
|
|
390 |
//getMetacatClient().update(newDocId, reader, null);
|
|
391 |
//reader.close();
|
|
392 |
} catch (Exception ex) {
|
|
393 |
ex.printStackTrace();
|
|
394 |
}
|
|
395 |
return(newDocId);
|
|
396 |
}
|
|
397 |
|
388 |
398 |
private InputStream getNextInputStream(MultipartParser multipartParser, StringBuilder fileName, HashMap paramsMap)
|
389 |
399 |
throws IOException {
|
390 |
400 |
InputStream result = null;
|
... | ... | |
644 |
654 |
public MetacatClient getMetacatClient() {
|
645 |
655 |
return(metacatClient);
|
646 |
656 |
}
|
|
657 |
|
|
658 |
//*** BEGIN: Static utility methods ***
|
|
659 |
|
|
660 |
public static String[] parseFileInfo(String fileName) {
|
|
661 |
String[] result = new String[2];
|
|
662 |
int idx;
|
|
663 |
String formatType;
|
|
664 |
|
|
665 |
//*** Set the file format (just using file extension for now).
|
|
666 |
idx = fileName.lastIndexOf(".");
|
|
667 |
if (idx > 1)
|
|
668 |
formatType = fileName.substring(idx+1).toUpperCase();
|
|
669 |
else
|
|
670 |
formatType = "";
|
|
671 |
|
|
672 |
result[ClientView.FORMAT_TYPE] = formatType;
|
|
673 |
result[ClientView.FILE_NAME] = fileName.toString();
|
|
674 |
return(result);
|
|
675 |
}
|
|
676 |
|
|
677 |
public static void updateNodeText(Node root, XPath xPath, String expression, String text) {
|
|
678 |
Node targetNode;
|
|
679 |
|
|
680 |
if (text != null && !text.equals("")) {
|
|
681 |
try {
|
|
682 |
targetNode = (Node) xPath.evaluate(expression, root, XPathConstants.NODE);
|
|
683 |
targetNode.setTextContent(text);
|
|
684 |
} catch (XPathExpressionException ex) {
|
|
685 |
ex.printStackTrace();
|
|
686 |
}
|
|
687 |
}
|
|
688 |
}
|
|
689 |
|
|
690 |
|
|
691 |
public static Node getNode(XPath xPath, String expression, Node root) {
|
|
692 |
Node result = null;
|
|
693 |
|
|
694 |
try {
|
|
695 |
result = (Node) xPath.evaluate(expression, root, XPathConstants.NODE);
|
|
696 |
} catch (XPathExpressionException ex) {
|
|
697 |
ex.printStackTrace();
|
|
698 |
}
|
|
699 |
return(result);
|
|
700 |
|
|
701 |
}
|
|
702 |
//*** END: Static utility methods ***
|
|
703 |
|
647 |
704 |
}
|
Changes for java 1.4 compilation, and further development.