0
|
1 package de.mpiwg.itgroup.eSciDoc.Tools;
|
|
2 import java.io.IOException;
|
|
3 import java.io.StringReader;
|
|
4 import java.net.MalformedURLException;
|
|
5 import java.net.URL;
|
|
6 import java.rmi.RemoteException;
|
|
7 import java.text.SimpleDateFormat;
|
|
8 import java.util.Date;
|
|
9 import java.util.regex.Matcher;
|
|
10 import java.util.regex.Pattern;
|
|
11
|
|
12 import javax.xml.parsers.DocumentBuilder;
|
|
13 import javax.xml.parsers.DocumentBuilderFactory;
|
|
14 import javax.xml.rpc.ServiceException;
|
|
15
|
|
16 import org.apache.axis.types.NonNegativeInteger;
|
|
17 import org.apache.xmlrpc.XmlRpcException;
|
|
18 import org.apache.xmlrpc.client.XmlRpcClient;
|
|
19 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
|
20 import org.w3c.dom.Document;
|
|
21 import org.xml.sax.InputSource;
|
|
22
|
|
23
|
|
24 public class ingestLib extends IngestECHO{
|
|
25
|
|
26 /**
|
|
27 * @param args
|
|
28 * @throws Exception
|
|
29 * @throws Exception
|
|
30 */
|
|
31
|
|
32 private static String ZOPEPROVIDER = "http://127.0.0.1:18080";
|
|
33 private static String createFoxml(String litid) throws Exception{
|
|
34
|
|
35 String pid =
|
|
36 eSciDocXmlObject obj = new eSciDocXmlObject("mpiwg:"+pid,"vlpRessourceTemplate.xml");
|
|
37 //obj.setTitle("lit11111 - title");
|
|
38
|
|
39
|
|
40 //get DC Metadata from the Ressource
|
|
41 XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
|
42 XmlRpcClient client = new XmlRpcClient();
|
|
43 Object[] params = new Object[]{};
|
|
44 config.setServerURL(new URL(ZOPEPROVIDER+"/metadataMain"));
|
|
45 client.setConfig(config);
|
|
46 params = new Object[]{"http://vlp.mpiwg-berlin.mpg.de/library/data/"+litid+"/index_meta"};
|
|
47 String result = (String) client.execute("getDCFormatted", params);
|
|
48 System.out.println("dC:"+result);
|
|
49
|
|
50
|
|
51 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
52 factory.setNamespaceAware(true);
|
|
53 DocumentBuilder db =factory.newDocumentBuilder();
|
|
54 InputSource resultStream = new InputSource(new StringReader(result));
|
|
55 Document dc = db.parse(resultStream);
|
|
56 obj.insertDC(dc);
|
|
57
|
|
58 obj.setReferenceFolder("/mpiwg/online/permanent/vlp/"+litid);
|
|
59 //obj.generateXMLIndex(new File("/mpiwg/online/permanent/vlp/"+litid));
|
|
60 //long date = new Date().getTime();
|
|
61 SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.S'Z'");
|
|
62 String dateStr = dateformat.format(new Date());
|
|
63 obj.addWebUrl("http://vlp.mpiwg-berlin.mpg.de/references?id="+litid, litid, dateStr);
|
|
64 obj.addIndexMetaUrl("http://vlp.mpiwg-berlin.mpg.de/library/data/"+litid+"/index_meta", litid, dateStr);
|
|
65 obj.setRelationship("info:fedora/vlp:col1");
|
|
66 obj.setVLPId(litid);
|
|
67 return obj.printXML();
|
|
68
|
|
69 }
|
|
70
|
|
71
|
|
72
|
|
73
|
|
74
|
|
75
|
|
76 private static void ingestAllVLPObjects() throws MalformedURLException,
|
|
77 XmlRpcException {
|
|
78 XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
|
79 XmlRpcClient client = new XmlRpcClient();
|
|
80 config.setServerURL(new URL("http://127.0.0.1:18080/vlp/vlp_coll/library/data"));
|
|
81 client.setConfig(config);
|
|
82 Object[] params = new Object[]{};
|
|
83 Object[] res = (Object[]) client.execute("getAllRessources", params);
|
|
84
|
|
85 String string = "";
|
|
86 for (Object re: res){
|
|
87 Object[] rA = (Object [])re;
|
|
88 String[] splitted = ((String) rA[0]).split("/");
|
|
89 String id = splitted[splitted.length-1];
|
|
90
|
|
91 try {
|
|
92 String xml = createFoxml(id);
|
|
93
|
|
94 String ret = ingest(xml);
|
|
95
|
|
96 config.setServerURL(new URL((String)rA[1]));
|
|
97 client.setConfig(config);
|
|
98 params = new Object[]{ret};
|
|
99 client.execute("setPID", params);
|
|
100
|
|
101 System.out.println(ret);
|
|
102
|
|
103
|
|
104 } catch (Exception e) {
|
|
105 System.err.println("cannot get:"+(String) rA[0]);
|
|
106
|
|
107 }
|
|
108 }
|
|
109 }
|
|
110
|
|
111 private static void modifyDCSet(String litid, String PID) throws XmlRpcException, ServiceException, IOException
|
|
112 {
|
|
113 XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
|
114 XmlRpcClient client = new XmlRpcClient();
|
|
115 config.setServerURL(new URL(ZOPEPROVIDER+"/metadataMain"));
|
|
116
|
|
117
|
|
118 client.setConfig(config);
|
|
119 Object[] params = new Object[]{"http://vlp.mpiwg-berlin.mpg.de/library/data/"+litid+"/index_meta"};
|
|
120 String result = (String) client.execute("getDCFormatted", params);
|
|
121 //System.out.println("dC:"+result);
|
|
122
|
|
123 FedoraAPIM APIM;
|
|
124 FedoraAPIA APIA;
|
|
125
|
|
126 System.setProperty("javax.net.ssl.trustStore", "/usr/local/fedora/tomcat/conf/keystore");
|
|
127
|
|
128
|
|
129 String baseURL = "https://127.0.0.1:8443/fedora";
|
|
130 FedoraClient fc = new FedoraClient(baseURL, "fedoraAdmin", "XXXX");
|
|
131 APIA=fc.getAPIA();
|
|
132 APIM=fc.getAPIM();
|
|
133 String content = "<oai_dc:dc xmlns:oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/' xmlns:dc='http://purl.org/dc/elements/1.1/'><dc:description>VLP Literature Object</dc:description><dc:publisher>MPIWG</dc:publisher>";
|
|
134 content += result;
|
|
135 content += "</oai_dc:dc>";
|
|
136 //content="";
|
|
137
|
|
138 //System.out.println(content);
|
|
139
|
|
140
|
|
141 String chksum = MD5.asHex(new MD5(content).Final());
|
|
142
|
|
143 //System.out.println(chksum);
|
|
144 String[] em= new String[]{};
|
|
145 String pid = APIM.modifyDatastreamByValue(PID, "DC",em , "Dublin Core Record for this object", "text/xml", "",content.getBytes("utf-8"), null, null,"metadata changed",false);
|
|
146 System.out.println(pid);
|
|
147
|
|
148 }
|
|
149
|
|
150
|
|
151 public static void main(String[] args) throws Exception {
|
|
152
|
|
153 //ingestAllVLPObjects();
|
|
154 changeDCMetadata();
|
|
155 //modifyDCSet("lit14191","mpiwg:PR9MPM4E");
|
|
156
|
|
157 }
|
|
158
|
|
159 private static void changeDCMetadata() throws MalformedURLException,
|
|
160 ServiceException, IOException, RemoteException, XmlRpcException {
|
|
161 System.setProperty("javax.net.ssl.trustStore", "/usr/local/fedora/tomcat/conf/keystore");
|
|
162
|
|
163 String baseURL = "https://127.0.0.1:8443/fedora";
|
|
164 FedoraClient fc = new FedoraClient(baseURL, "fedoraAdmin", "XXX");
|
|
165 FedoraAPIA APIA;
|
|
166 APIA=fc.getAPIA();
|
|
167 Condition[] condition =
|
|
168 {new Condition("pid", ComparisonOperator.has, "mpiwg:*")};
|
|
169 FieldSearchQuery query = new FieldSearchQuery(condition, null);
|
|
170
|
|
171 NonNegativeInteger maxResults = new NonNegativeInteger("" + 200);
|
|
172
|
|
173 FieldSearchResult res = APIA.findObjects(new String[]{"pid"}, maxResults, query);
|
|
174 processResults(APIA, res);
|
|
175 while (true)
|
|
176 {
|
|
177 ListSession ses = res.getListSession();
|
|
178 if (ses == null)
|
|
179 break;
|
|
180 String tok = ses.getToken();
|
|
181 if (tok == null)
|
|
182 break;
|
|
183
|
|
184 res = APIA.resumeFindObjects(res.getListSession().getToken());
|
|
185 if (res.getResultList().length>0)
|
|
186 processResults(APIA, res);
|
|
187 else
|
|
188 break;
|
|
189 }
|
|
190 }
|
|
191
|
|
192 private static void processResults(FedoraAPIA APIA, FieldSearchResult res)
|
|
193 throws XmlRpcException, ServiceException, IOException {
|
|
194 ObjectFields[] fields = res.getResultList();
|
|
195
|
|
196 System.out.println("found:"+fields.length);
|
|
197 for (ObjectFields field: fields){
|
|
198 String pid = field.getPid();
|
|
199 MIMETypedStream ds = APIA.getDatastreamDissemination(pid, "vlp-admin", null);
|
|
200 byte[] x = ds.getStream();
|
|
201 String s = new String(x);
|
|
202 //System.err.println(s);
|
|
203
|
|
204 Pattern p = Pattern.compile("<vlp:identifier>(lit.*)</vlp:identifier>");
|
|
205 Matcher m = p.matcher(s);
|
|
206 m.find();
|
|
207 String lit = m.group(1);
|
|
208 System.out.println(lit);
|
|
209 modifyDCSet(lit, pid);
|
|
210 }
|
|
211 }
|
|
212 }
|