Revision 6708
Added by ben leinfelder over 12 years ago
ReplicationService.java | ||
---|---|---|
65 | 65 |
import org.dataone.service.types.v1.SystemMetadata; |
66 | 66 |
import org.dataone.service.util.DateTimeMarshaller; |
67 | 67 |
import org.dataone.service.util.TypeMarshaller; |
68 |
import org.jibx.runtime.JiBXException; |
|
68 | 69 |
import org.xml.sax.InputSource; |
69 | 70 |
import org.xml.sax.SAXException; |
70 | 71 |
import org.xml.sax.XMLReader; |
... | ... | |
899 | 900 |
protected static void handleGetDocumentInfoRequest( |
900 | 901 |
Hashtable<String, String[]> params, HttpServletResponse response) { |
901 | 902 |
String docid = ((String[]) (params.get("docid")))[0]; |
902 |
StringBuffer sb = new StringBuffer(); |
|
903 | 903 |
|
904 | 904 |
try { |
905 |
DocumentImpl doc = new DocumentImpl(docid); |
|
906 |
sb.append("<documentinfo><docid>").append(docid); |
|
907 |
sb.append("</docid>"); |
|
905 |
// get docinfo as XML string |
|
906 |
String docinfoXML = getDocumentInfo(docid); |
|
908 | 907 |
|
909 |
try { |
|
910 |
// serialize the System Metadata as XML for docinfo |
|
911 |
String guid = IdentifierManager.getInstance().getGUID(doc.getDocID(), doc.getRev()); |
|
912 |
SystemMetadata systemMetadata = IdentifierManager.getInstance().getSystemMetadata(guid); |
|
913 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
914 |
TypeMarshaller.marshalTypeToOutputStream(systemMetadata, baos); |
|
915 |
String systemMetadataXML = baos.toString("UTF-8"); |
|
916 |
sb.append("<systemMetadata>"); |
|
917 |
sb.append(systemMetadataXML); |
|
918 |
sb.append("</systemMetadata>"); |
|
919 |
} catch(McdbDocNotFoundException e) { |
|
920 |
logMetacat.warn("No SystemMetadata found for: " + docid); |
|
921 |
} |
|
922 |
|
|
923 |
Calendar created = Calendar.getInstance(); |
|
924 |
created.setTime(doc.getCreateDate()); |
|
925 |
Calendar updated = Calendar.getInstance(); |
|
926 |
updated.setTime(doc.getUpdateDate()); |
|
927 |
|
|
928 |
sb.append("<docname>").append(doc.getDocname()); |
|
929 |
sb.append("</docname><doctype>").append(doc.getDoctype()); |
|
930 |
sb.append("</doctype>"); |
|
931 |
sb.append("<user_owner>").append(doc.getUserowner()); |
|
932 |
sb.append("</user_owner><user_updated>").append(doc.getUserupdated()); |
|
933 |
sb.append("</user_updated>"); |
|
934 |
sb.append("<date_created>"); |
|
935 |
sb.append(DateTimeMarshaller.serializeDateToUTC(doc.getCreateDate())); |
|
936 |
sb.append("</date_created>"); |
|
937 |
sb.append("<date_updated>"); |
|
938 |
sb.append(DateTimeMarshaller.serializeDateToUTC(doc.getUpdateDate())); |
|
939 |
sb.append("</date_updated>"); |
|
940 |
sb.append("<home_server>"); |
|
941 |
sb.append(doc.getDocHomeServer()); |
|
942 |
sb.append("</home_server>"); |
|
943 |
sb.append("<public_access>").append(doc.getPublicaccess()); |
|
944 |
sb.append("</public_access><rev>").append(doc.getRev()); |
|
945 |
sb.append("</rev>"); |
|
946 |
|
|
947 |
sb.append("<accessControl>"); |
|
948 |
|
|
949 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
950 |
sb.append(acfsf.getAccessString()); |
|
951 |
|
|
952 |
sb.append("</accessControl>"); |
|
953 |
|
|
954 |
sb.append("</documentinfo>"); |
|
955 | 908 |
// get a writer for sending back to response |
956 | 909 |
response.setContentType("text/xml"); |
957 | 910 |
Writer out = response.getWriter(); |
958 |
out.write(sb.toString());
|
|
911 |
out.write(docinfoXML);
|
|
959 | 912 |
out.close(); |
960 | 913 |
|
961 | 914 |
} catch (Exception e) { |
... | ... | |
966 | 919 |
|
967 | 920 |
} |
968 | 921 |
|
922 |
public static Hashtable<String, String> getDocumentInfoMap(String docid) |
|
923 |
throws HandlerException, AccessControlException, JiBXException, |
|
924 |
IOException, McdbException, SAXException { |
|
925 |
|
|
926 |
// Try get docid info from remote server |
|
927 |
DocInfoHandler dih = new DocInfoHandler(); |
|
928 |
XMLReader docinfoParser = ReplicationHandler.initParser(dih); |
|
929 |
|
|
930 |
String docInfoStr = getDocumentInfo(docid); |
|
931 |
|
|
932 |
// strip out the system metadata portion |
|
933 |
String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr); |
|
934 |
docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr); |
|
935 |
|
|
936 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
|
937 |
Hashtable<String, String> docinfoHash = dih.getDocInfo(); |
|
938 |
|
|
939 |
return docinfoHash; |
|
940 |
} |
|
941 |
|
|
969 | 942 |
/** |
943 |
* Gets a docInfo XML snippet for the replication API |
|
944 |
* @param docid |
|
945 |
* @return |
|
946 |
* @throws AccessControlException |
|
947 |
* @throws JiBXException |
|
948 |
* @throws IOException |
|
949 |
* @throws McdbException |
|
950 |
*/ |
|
951 |
public static String getDocumentInfo(String docid) throws AccessControlException, JiBXException, IOException, McdbException { |
|
952 |
StringBuffer sb = new StringBuffer(); |
|
953 |
|
|
954 |
DocumentImpl doc = new DocumentImpl(docid); |
|
955 |
sb.append("<documentinfo><docid>").append(docid); |
|
956 |
sb.append("</docid>"); |
|
957 |
|
|
958 |
try { |
|
959 |
// serialize the System Metadata as XML for docinfo |
|
960 |
String guid = IdentifierManager.getInstance().getGUID(doc.getDocID(), doc.getRev()); |
|
961 |
SystemMetadata systemMetadata = IdentifierManager.getInstance().getSystemMetadata(guid); |
|
962 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
963 |
TypeMarshaller.marshalTypeToOutputStream(systemMetadata, baos); |
|
964 |
String systemMetadataXML = baos.toString("UTF-8"); |
|
965 |
sb.append("<systemMetadata>"); |
|
966 |
sb.append(systemMetadataXML); |
|
967 |
sb.append("</systemMetadata>"); |
|
968 |
} catch(McdbDocNotFoundException e) { |
|
969 |
logMetacat.warn("No SystemMetadata found for: " + docid); |
|
970 |
} |
|
971 |
|
|
972 |
Calendar created = Calendar.getInstance(); |
|
973 |
created.setTime(doc.getCreateDate()); |
|
974 |
Calendar updated = Calendar.getInstance(); |
|
975 |
updated.setTime(doc.getUpdateDate()); |
|
976 |
|
|
977 |
sb.append("<docname>").append(doc.getDocname()); |
|
978 |
sb.append("</docname><doctype>").append(doc.getDoctype()); |
|
979 |
sb.append("</doctype>"); |
|
980 |
sb.append("<user_owner>").append(doc.getUserowner()); |
|
981 |
sb.append("</user_owner><user_updated>").append(doc.getUserupdated()); |
|
982 |
sb.append("</user_updated>"); |
|
983 |
sb.append("<date_created>"); |
|
984 |
sb.append(DateTimeMarshaller.serializeDateToUTC(doc.getCreateDate())); |
|
985 |
sb.append("</date_created>"); |
|
986 |
sb.append("<date_updated>"); |
|
987 |
sb.append(DateTimeMarshaller.serializeDateToUTC(doc.getUpdateDate())); |
|
988 |
sb.append("</date_updated>"); |
|
989 |
sb.append("<home_server>"); |
|
990 |
sb.append(doc.getDocHomeServer()); |
|
991 |
sb.append("</home_server>"); |
|
992 |
sb.append("<public_access>").append(doc.getPublicaccess()); |
|
993 |
sb.append("</public_access><rev>").append(doc.getRev()); |
|
994 |
sb.append("</rev>"); |
|
995 |
|
|
996 |
sb.append("<accessControl>"); |
|
997 |
|
|
998 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
999 |
sb.append(acfsf.getAccessString()); |
|
1000 |
|
|
1001 |
sb.append("</accessControl>"); |
|
1002 |
|
|
1003 |
sb.append("</documentinfo>"); |
|
1004 |
|
|
1005 |
return sb.toString(); |
|
1006 |
} |
|
1007 |
|
|
1008 |
/** |
|
970 | 1009 |
* Sends System Metadata as XML |
971 | 1010 |
*/ |
972 | 1011 |
protected static void handleGetSystemMetadataRequest( |
Also available in: Unified diff
use shared method for looking up "docInfo" map -- both in Metacat replication and in D1 system metadata generation