Mercurial > hg > eSciDocImport
comparison src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/ReplaceAffiliation.java @ 8:a844f6948dd8
?nderungen im Walker
tools f?r pubman
author | dwinter |
---|---|
date | Mon, 14 May 2012 09:58:45 +0200 |
parents | |
children | c201d58997e5 |
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.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 ReplaceAffiliation { | |
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", "fl1rian"); | |
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 personXPath = EScidocTools.getESciDocXpath("//eterms:creator/person:person"); | |
54 XPath organizationXPath = EScidocTools.getESciDocXpath("./organization:organization"); | |
55 XPath titleXPath = EScidocTools.getESciDocXpath("./dc:title"); | |
56 XPath identifierXPath = EScidocTools.getESciDocXpath("./dc:identifier"); | |
57 | |
58 @SuppressWarnings("unchecked") | |
59 List<Element> persons = personXPath.selectNodes(doc); | |
60 for (Element person : persons) { | |
61 Element organization = (Element) organizationXPath.selectSingleNode(person); | |
62 if (organization!=null){ | |
63 Element title = (Element) titleXPath.selectSingleNode(organization); | |
64 | |
65 String titleString = title.getTextTrim(); | |
66 if (titleString | |
67 .startsWith("Max Planck Society")) { | |
68 title.setText("Max Planck Institute for the History of Science"); | |
69 Element identifier = (Element) identifierXPath.selectSingleNode(organization); | |
70 identifier.setText("escidoc:14002"); | |
71 changed=true; | |
72 | |
73 } | |
74 } | |
75 } | |
76 | |
77 //System.out.println(obj.printXML()); | |
78 if (changed){ | |
79 | |
80 Boolean retVal = connector.updateItem(obj); | |
81 System.out.println("Replaced:"+obj.getESciDocId()); | |
82 HttpResponse retValu = connector.submitAnObject(obj, "changed affiliation of persons"); | |
83 | |
84 System.out.println(EScidocBasicHandler.convertStreamToString(retValu.getEntity().getContent())); | |
85 HttpResponse resObj = connector.eScidocGet(obj.getESciDocId()); | |
86 HttpEntity ent = resObj.getEntity(); | |
87 if (ent!=null){ | |
88 obj= new eSciDocXmlObject(ent.getContent()); | |
89 } else { | |
90 System.out.println("Can not retrieve:" + obj.getESciDocId()); | |
91 continue; | |
92 } | |
93 | |
94 HttpResponse reValue2 = connector.releaseAnObject(obj, "changed affiliation of persons"); | |
95 System.out.println(EScidocBasicHandler.convertStreamToString(reValue2.getEntity().getContent())); | |
96 | |
97 } | |
98 } | |
99 | |
100 } | |
101 } |