21
|
1 package de.mpiwg.itgroup.eSciDoc.Tools.Pubman;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.util.List;
|
|
5
|
|
6 import org.apache.http.HttpEntity;
|
|
7 import org.apache.http.HttpResponse;
|
|
8 import org.apache.log4j.Level;
|
|
9 import org.apache.log4j.Logger;
|
|
10 import org.jdom.Document;
|
|
11 import org.jdom.Element;
|
|
12 import org.jdom.JDOMException;
|
|
13 import org.jdom.xpath.XPath;
|
|
14
|
|
15 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler;
|
|
16 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools;
|
|
17 import de.mpiwg.itgroup.eSciDoc.exceptions.ESciDocXmlObjectException;
|
|
18 import de.mpiwg.itgroup.eSciDoc.utils.eSciDocXmlObject;
|
|
19
|
|
20 public class ReplaceConeIdsInSource {
|
|
21
|
|
22 /**
|
|
23 * @param args
|
|
24 * @throws ESciDocXmlObjectException
|
|
25 * @throws JDOMException
|
|
26 * @throws IOException
|
|
27 * @throws IllegalStateException
|
|
28 */
|
|
29 public static void main(String[] args) throws IllegalStateException,
|
|
30 IOException, JDOMException, ESciDocXmlObjectException {
|
|
31
|
|
32 Logger logger = Logger.getRootLogger();
|
|
33 logger.setLevel(Level.DEBUG);
|
|
34 EScidocBasicHandler connector = new EScidocBasicHandler(
|
|
35 "escidoc.mpiwg-berlin.mpg.de", 8080, "dwinter", "XXXX");
|
|
36
|
|
37 if(args.length<2){
|
|
38 System.out.println("Usage: startrecord maximumrecords");
|
|
39 System.exit(-1);
|
|
40 }
|
|
41 String MAX_REC = args[1];
|
|
42 String start = args[0];
|
|
43 String objectXPath = "//escidocItem:item";
|
|
44
|
|
45 String query = "?maximumRecords=" + String.valueOf(MAX_REC)
|
|
46 + "&startRecord=" + String.valueOf(start);
|
|
47 String command = "/ir/context/escidoc:38279/resources/members";
|
|
48 for (eSciDocXmlObject obj : connector.getObjectsFromFilterResult(
|
|
49 command + query, objectXPath)) {
|
|
50
|
|
51 Document doc = obj.getDocument();
|
|
52 Boolean changed=false;
|
|
53 XPath idXPath = EScidocTools.getESciDocXpath("//source:source//dc:identifier");
|
|
54 @SuppressWarnings("unchecked")
|
|
55 List<Element> identifiers = idXPath.selectNodes(doc);
|
|
56 for (Element identifier : identifiers) {
|
|
57 String idString = identifier.getTextTrim();
|
|
58 if (!idString.startsWith("http://pubman.mpiwg-berlin.mpg.de/cone/editors/resource")) {
|
|
59 idString=idString.replace("http://pubman.mpiwg-berlin.mpg.de/cone/persons/resource",
|
|
60 "http://pubman.mpiwg-berlin.mpg.de/cone/editors/resource");
|
|
61 identifier.setText(idString);
|
|
62 changed=true;
|
|
63
|
|
64 }
|
|
65
|
|
66 }
|
|
67 if (changed){
|
|
68
|
|
69 Boolean retVal = connector.updateItem(obj);
|
|
70 System.out.println("Replaced:"+obj.getESciDocId());
|
|
71 HttpResponse retValu = connector.submitAnObject(obj, "changed cone identifiers");
|
|
72
|
|
73 System.out.println(EScidocBasicHandler.convertStreamToString(retValu.getEntity().getContent()));
|
|
74 HttpResponse resObj = connector.eScidocGet(obj.getESciDocId());
|
|
75 HttpEntity ent = resObj.getEntity();
|
|
76 if (ent!=null){
|
|
77 obj= new eSciDocXmlObject(ent.getContent());
|
|
78 } else {
|
|
79 System.out.println("Can not retrieve:" + obj.getESciDocId());
|
|
80 continue;
|
|
81 }
|
|
82
|
|
83 HttpResponse reValue2 = connector.releaseAnObject(obj, "changed cone identifiers");
|
|
84 System.out.println(EScidocBasicHandler.convertStreamToString(reValue2.getEntity().getContent()));
|
|
85
|
|
86 }
|
|
87 }
|
|
88
|
|
89 }
|
|
90 }
|