Revision 8948
Added by Jing Tao about 10 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
931 | 931 |
PrintWriter out = response.getWriter(); |
932 | 932 |
if ((userName != null) && !userName.equals("public")) { |
933 | 933 |
handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, params, userName, |
934 |
groupNames, true, true); |
|
934 |
groupNames, true, true, null);
|
|
935 | 935 |
} else { |
936 | 936 |
response.setContentType("text/xml"); |
937 | 937 |
out.println("<?xml version=\"1.0\"?>"); |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
1498 | 1498 |
* @param accNumber |
1499 | 1499 |
* the document id which is used to name the output file |
1500 | 1500 |
*/ |
1501 |
private static void writeToFileSystem(String xml, String accNumber, String encoding) throws McdbException {
|
|
1501 |
private static void writeToFileSystem(byte[] xml, String accNumber) throws McdbException {
|
|
1502 | 1502 |
|
1503 | 1503 |
// write the document to disk |
1504 | 1504 |
String documentDir = null; |
... | ... | |
1528 | 1528 |
FileOutputStream fos = null; |
1529 | 1529 |
try { |
1530 | 1530 |
fos = new FileOutputStream(documentPath); |
1531 |
IOUtils.write(xml.getBytes(encoding), fos);
|
|
1531 |
IOUtils.write(xml, fos); |
|
1532 | 1532 |
|
1533 | 1533 |
fos.flush(); |
1534 | 1534 |
fos.close(); |
... | ... | |
2657 | 2657 |
|
2658 | 2658 |
public static String write(DBConnection conn, String xmlString, String pub, |
2659 | 2659 |
Reader dtd, String action, String docid, String user, |
2660 |
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules) |
|
2660 |
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes)
|
|
2661 | 2661 |
throws Exception |
2662 | 2662 |
{ |
2663 | 2663 |
//this method will be called in handleUpdateOrInsert method |
... | ... | |
2665 | 2665 |
// get server location for this doc |
2666 | 2666 |
int serverLocation = getServerLocationNumber(docid); |
2667 | 2667 |
return write(conn, xmlString, pub, dtd, action, docid, user, groups, |
2668 |
serverLocation, false, ruleBase, needValidation, writeAccessRules); |
|
2668 |
serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes);
|
|
2669 | 2669 |
} |
2670 | 2670 |
|
2671 | 2671 |
/** |
... | ... | |
2702 | 2702 |
public static String write(DBConnection conn, String xmlString, String pub, |
2703 | 2703 |
Reader dtd, String action, String accnum, String user, |
2704 | 2704 |
String[] groups, int serverCode, boolean override, String ruleBase, |
2705 |
boolean needValidation, boolean writeAccessRules) throws Exception |
|
2705 |
boolean needValidation, boolean writeAccessRules, byte[] xmlBytes) throws Exception
|
|
2706 | 2706 |
{ |
2707 | 2707 |
// NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT |
2708 | 2708 |
|
2709 | 2709 |
// Get the xml as a string so we can write to file later |
2710 | 2710 |
StringReader xmlReader = new StringReader(xmlString); |
2711 |
// detect encoding |
|
2712 |
XmlStreamReader xsr = null; |
|
2713 |
if(xmlBytes == null || xmlBytes.length == 0 ) { |
|
2714 |
xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
2715 |
} else { |
|
2716 |
xsr = new XmlStreamReader(new ByteArrayInputStream(xmlBytes)); |
|
2717 |
} |
|
2718 |
String encoding = xsr.getEncoding(); |
|
2719 |
//get the byte array from xmlString if the xmlbyte is null (this comes from metacat api) |
|
2720 |
if(xmlBytes == null || xmlBytes.length == 0) { |
|
2721 |
xmlBytes = xmlString.getBytes(encoding); |
|
2722 |
} |
|
2711 | 2723 |
|
2712 | 2724 |
logMetacat.debug("DocumentImpl.write - conn usage count before writing: " |
2713 | 2725 |
+ conn.getUsageCount()); |
... | ... | |
2767 | 2779 |
logReplication.info("lock granted for " + accnum |
2768 | 2780 |
+ " from " + server); |
2769 | 2781 |
|
2770 |
// detect encoding |
|
2771 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
2772 |
String encoding = xsr.getEncoding(); |
|
2782 |
|
|
2773 | 2783 |
Vector<String>guidsToSync = new Vector<String>(); |
2774 | 2784 |
|
2775 | 2785 |
/* |
... | ... | |
2794 | 2804 |
|
2795 | 2805 |
//write the file to disk |
2796 | 2806 |
logMetacat.debug("DocumentImpl.write - Writing xml to file system"); |
2797 |
writeToFileSystem(xmlString, accnum, encoding);
|
|
2807 |
writeToFileSystem(xmlBytes, accnum);
|
|
2798 | 2808 |
|
2799 | 2809 |
// write to xml_node complete. start the indexing thread. |
2800 | 2810 |
addDocidToIndexingQueue(docid, rev); |
... | ... | |
2878 | 2888 |
} |
2879 | 2889 |
XMLReader parser = null; |
2880 | 2890 |
try { |
2881 |
// detect encoding |
|
2882 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
2883 |
String encoding = xsr.getEncoding(); |
|
2891 |
|
|
2892 |
|
|
2884 | 2893 |
Vector<String>guidsToSync = new Vector<String>(); |
2885 | 2894 |
|
2886 | 2895 |
parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups, |
... | ... | |
2900 | 2909 |
updateNodeValues(conn, docid); |
2901 | 2910 |
|
2902 | 2911 |
//write the file to disk |
2903 |
writeToFileSystem(xmlString, accnum, encoding);
|
|
2912 |
writeToFileSystem(xmlBytes, accnum);
|
|
2904 | 2913 |
|
2905 | 2914 |
addDocidToIndexingQueue(docid, rev); |
2906 | 2915 |
if (guidsToSync.size() > 0) { |
... | ... | |
3103 | 3112 |
conn.setAutoCommit(true); |
3104 | 3113 |
|
3105 | 3114 |
// Write the file to disk |
3106 |
writeToFileSystem(xmlString, accnum, encoding); |
|
3115 |
byte[] bytes = xmlString.getBytes(encoding); |
|
3116 |
writeToFileSystem(bytes, accnum); |
|
3107 | 3117 |
|
3108 | 3118 |
// write to xml_node complete. start the indexing thread. |
3109 | 3119 |
// this only for xml_documents |
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java | ||
---|---|---|
59 | 59 |
}//Constructor |
60 | 60 |
|
61 | 61 |
public String write(DBConnection conn, String xml, String pub, Reader dtd, |
62 |
String action, String docid, String user, String[] groups) throws Exception { |
|
62 |
String action, String docid, String user, String[] groups, byte[]xmlBytes) throws Exception {
|
|
63 | 63 |
return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, groups, |
64 |
ruleBase, needValidation, writeAccessRules); |
|
64 |
ruleBase, needValidation, writeAccessRules, xmlBytes);
|
|
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
public String writeReplication(DBConnection conn, String xml, String pub, Reader dtd, |
src/edu/ucsb/nceas/metacat/MetacatHandler.java | ||
---|---|---|
1628 | 1628 |
*/ |
1629 | 1629 |
public String handleInsertOrUpdateAction(String ipAddress, String userAgent, |
1630 | 1630 |
HttpServletResponse response, PrintWriter out, Hashtable<String, String[]> params, |
1631 |
String user, String[] groups, boolean generateSystemMetadata, boolean writeAccessRules) { |
|
1631 |
String user, String[] groups, boolean generateSystemMetadata, boolean writeAccessRules, byte[] xmlBytes) {
|
|
1632 | 1632 |
Logger logMetacat = Logger.getLogger(MetacatHandler.class); |
1633 | 1633 |
DBConnection dbConn = null; |
1634 | 1634 |
int serialNumber = -1; |
... | ... | |
1805 | 1805 |
|
1806 | 1806 |
} else {*/ |
1807 | 1807 |
newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd, |
1808 |
doAction, accNumber, user, groups); |
|
1808 |
doAction, accNumber, user, groups, xmlBytes);
|
|
1809 | 1809 |
|
1810 | 1810 |
EventLog.getInstance().log(ipAddress, userAgent, user, accNumber, action[0]); |
1811 | 1811 |
|
... | ... | |
3189 | 3189 |
boolean writeAccessRules = true; |
3190 | 3190 |
//call the insert routine |
3191 | 3191 |
handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, |
3192 |
params, username, groupnames, true, writeAccessRules); |
|
3192 |
params, username, groupnames, true, writeAccessRules, null);
|
|
3193 | 3193 |
} |
3194 | 3194 |
catch(Exception e) |
3195 | 3195 |
{ |
src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java | ||
---|---|---|
165 | 165 |
.getDBConnection("EMLVersionsTransformer.handleSingleEML200Document"); |
166 | 166 |
serialNumber = dbconn.getCheckOutSerialNumber(); |
167 | 167 |
documentWrapper.write(dbconn, eml210Content, pub, dtd, |
168 |
doAction, newId, owner, groups); |
|
168 |
doAction, newId, owner, groups, null);
|
|
169 | 169 |
logMetacat.warn("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId); |
170 | 170 |
transformLog("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId); |
171 | 171 |
} |
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
359 | 359 |
// update the science metadata XML document |
360 | 360 |
// TODO: handle non-XML metadata/data documents (like netCDF) |
361 | 361 |
// TODO: don't put objects into memory using stream to string |
362 |
String objectAsXML = ""; |
|
362 |
//String objectAsXML = "";
|
|
363 | 363 |
try { |
364 |
objectAsXML = IOUtils.toString(object, "UTF-8"); |
|
364 |
//objectAsXML = IOUtils.toString(object, "UTF-8");
|
|
365 | 365 |
// give the old pid so we can calculate the new local id |
366 |
localId = insertOrUpdateDocument(objectAsXML, pid, session, "update");
|
|
366 |
localId = insertOrUpdateDocument(object, "UTF-8", pid, session, "update");
|
|
367 | 367 |
// register the newPid and the generated localId |
368 | 368 |
if (newPid != null) { |
369 | 369 |
IdentifierManager.getInstance().createMapping(newPid.getValue(), localId); |
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
402 | 402 |
if ( isScienceMetadata(sysmeta) ) { |
403 | 403 |
|
404 | 404 |
// CASE METADATA: |
405 |
String objectAsXML = ""; |
|
405 |
//String objectAsXML = "";
|
|
406 | 406 |
try { |
407 |
objectAsXML = IOUtils.toString(object, "UTF-8"); |
|
408 |
localId = insertOrUpdateDocument(objectAsXML, pid, session, "insert");
|
|
407 |
//objectAsXML = IOUtils.toString(object, "UTF-8");
|
|
408 |
localId = insertOrUpdateDocument(object,"UTF-8", pid, session, "insert");
|
|
409 | 409 |
//localId = im.getLocalId(pid.getValue()); |
410 | 410 |
|
411 | 411 |
} catch (IOException e) { |
... | ... | |
1148 | 1148 |
* @return localId - the resulting docid of the document created or updated |
1149 | 1149 |
* |
1150 | 1150 |
*/ |
1151 |
public String insertOrUpdateDocument(String xml, Identifier pid,
|
|
1151 |
public String insertOrUpdateDocument(InputStream xml, String encoding, Identifier pid,
|
|
1152 | 1152 |
Session session, String insertOrUpdate) |
1153 |
throws ServiceFailure { |
|
1153 |
throws ServiceFailure, IOException {
|
|
1154 | 1154 |
|
1155 | 1155 |
logMetacat.debug("Starting to insert xml document..."); |
1156 | 1156 |
IdentifierManager im = IdentifierManager.getInstance(); |
1157 | 1157 |
|
1158 | 1158 |
// generate pid/localId pair for sysmeta |
1159 | 1159 |
String localId = null; |
1160 |
|
|
1160 |
byte[] xmlBytes = IOUtils.toByteArray(xml); |
|
1161 |
String xmlStr = new String(xmlBytes, encoding); |
|
1161 | 1162 |
if(insertOrUpdate.equals("insert")) { |
1162 | 1163 |
localId = im.generateLocalId(pid.getValue(), 1); |
1163 | 1164 |
|
... | ... | |
1197 | 1198 |
docid[0] = localId; |
1198 | 1199 |
params.put("docid", docid); |
1199 | 1200 |
String[] doctext = new String[1]; |
1200 |
doctext[0] = xml; |
|
1201 |
doctext[0] = xmlStr;
|
|
1201 | 1202 |
params.put("doctext", doctext); |
1202 | 1203 |
|
1203 | 1204 |
String username = Constants.SUBJECT_PUBLIC; |
... | ... | |
1218 | 1219 |
// do the insert or update action |
1219 | 1220 |
handler = new MetacatHandler(new Timer()); |
1220 | 1221 |
String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null, |
1221 |
null, params, username, groupnames, false, false); |
|
1222 |
null, params, username, groupnames, false, false, xmlBytes);
|
|
1222 | 1223 |
|
1223 | 1224 |
if(result.indexOf("<error>") != -1) { |
1224 | 1225 |
String detailCode = ""; |
Also available in: Unified diff
Write the input stream into the file system without alteration in dataone create and update methods.