Mercurial > hg > eSciDocImport
comparison src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/RepairPublishingInfoDeleteWrong.java @ 8:a844f6948dd8
?nderungen im Walker
tools f?r pubman
author | dwinter |
---|---|
date | Mon, 14 May 2012 09:58:45 +0200 |
parents | |
children | 94ea06e32003 |
comparison
equal
deleted
inserted
replaced
7:df8c62d84f8f | 8:a844f6948dd8 |
---|---|
1 package de.mpiwg.itgroup.eSciDoc.Tools.Pubman; | |
2 | |
3 import java.io.IOException; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 | |
7 import org.apache.http.HttpEntity; | |
8 import org.apache.http.HttpResponse; | |
9 import org.apache.log4j.Level; | |
10 import org.apache.log4j.Logger; | |
11 import org.jdom.Document; | |
12 import org.jdom.Element; | |
13 import org.jdom.JDOMException; | |
14 import org.jdom.xpath.XPath; | |
15 | |
16 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler; | |
17 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools; | |
18 import de.mpiwg.itgroup.eSciDoc.exceptions.ESciDocXmlObjectException; | |
19 import de.mpiwg.itgroup.eSciDoc.utils.eSciDocXmlObject; | |
20 | |
21 public class RepairPublishingInfoDeleteWrong { | |
22 | |
23 /** | |
24 * @param args | |
25 * @throws ESciDocXmlObjectException | |
26 * @throws JDOMException | |
27 * @throws IOException | |
28 * @throws IllegalStateException | |
29 */ | |
30 public static void main(String[] args) throws IllegalStateException, | |
31 IOException, JDOMException, ESciDocXmlObjectException { | |
32 | |
33 Logger logger = Logger.getRootLogger(); | |
34 logger.setLevel(Level.DEBUG); | |
35 EScidocBasicHandler connector = new EScidocBasicHandler( | |
36 "escidoc.mpiwg-berlin.mpg.de", 8080, "dwinter", "fl0rian"); | |
37 | |
38 if(args.length<2){ | |
39 System.out.println("Usage: startrecord maximumrecords"); | |
40 System.exit(-1); | |
41 } | |
42 String MAX_REC = args[1]; | |
43 String start = args[0]; | |
44 String objectXPath = "//escidocItem:item"; | |
45 | |
46 String query = "?maximumRecords=" + String.valueOf(MAX_REC) | |
47 + "&startRecord=" + String.valueOf(start); | |
48 String command = "/ir/context/escidoc:38279/resources/members"; | |
49 for (eSciDocXmlObject obj : connector.getObjectsFromFilterResult( | |
50 command + query, objectXPath)) { | |
51 | |
52 Document doc = obj.getDocument(); | |
53 Boolean changed=false; | |
54 XPath publishingInfoContentXPath = EScidocTools.getESciDocXpath("//publication:publication[@type='http://purl.org/eprint/type/Book']/eterms:publishing-info/*"); | |
55 XPath publishingInfoXPath = EScidocTools.getESciDocXpath("//eterms:publishing-info"); | |
56 @SuppressWarnings("unchecked") | |
57 HashMap<String,Element> piContentHash = new HashMap<String, Element>(); | |
58 | |
59 | |
60 List<Element> piContents =publishingInfoContentXPath.selectNodes(doc); | |
61 for (Element piContent : piContents) { | |
62 | |
63 String piContentName=piContent.getName(); | |
64 if (piContentName.equals("publisher")){ | |
65 piContent.detach(); | |
66 System.out.println("delete:"+piContent.getQualifiedName()); | |
67 changed=true; | |
68 } | |
69 | |
70 | |
71 //piContentHash.put(piContentTag,piContent); | |
72 } | |
73 | |
74 // for (Element publishingInfo: (List<Element>)publishingInfoXPath.selectNodes(doc)){ | |
75 // for(String piContentTag: piContentHash.keySet()){ | |
76 // Element piContent = piContentHash.get(piContentTag); | |
77 // | |
78 // XPath xp= EScidocTools.getESciDocXpath("./"+piContent.getQualifiedName()); | |
79 // Element el=(Element)xp.selectSingleNode(publishingInfo); | |
80 // if(el==null){ | |
81 // System.out.println("Adding:"+piContent.getQualifiedName()); | |
82 // publishingInfo.addContent((Element)piContent.clone()); | |
83 // changed=true; | |
84 // } | |
85 // | |
86 // | |
87 // | |
88 // } | |
89 // | |
90 // } | |
91 // System.out.println(obj.printXML()); | |
92 if (changed){ | |
93 | |
94 Boolean retVal = connector.updateItem(obj); | |
95 System.out.println("Replaced:"+obj.getESciDocId()); | |
96 HttpResponse retValu = connector.submitAnObject(obj, "repairing publishing info (pulisher in bookitem)"); | |
97 | |
98 System.out.println(EScidocBasicHandler.convertStreamToString(retValu.getEntity().getContent())); | |
99 HttpResponse resObj = connector.eScidocGet(obj.getESciDocId()); | |
100 HttpEntity ent = resObj.getEntity(); | |
101 if (ent!=null){ | |
102 obj= new eSciDocXmlObject(ent.getContent()); | |
103 } else { | |
104 System.out.println("Can not retrieve:" + obj.getESciDocId()); | |
105 continue; | |
106 } | |
107 | |
108 HttpResponse reValue2 = connector.releaseAnObject(obj, "repairing publishing info (publisher in bookitem"); | |
109 System.out.println(EScidocBasicHandler.convertStreamToString(reValue2.getEntity().getContent())); | |
110 | |
111 } | |
112 } | |
113 | |
114 } | |
115 } |