diff src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/RepairPublishingInfoPlaceMain.java @ 8:a844f6948dd8

?nderungen im Walker tools f?r pubman
author dwinter
date Mon, 14 May 2012 09:58:45 +0200
parents
children e0efd3a9d2f0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/RepairPublishingInfoPlaceMain.java	Mon May 14 09:58:45 2012 +0200
@@ -0,0 +1,129 @@
+package de.mpiwg.itgroup.eSciDoc.Tools.Pubman;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.xpath.XPath;
+
+import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler;
+import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools;
+import de.mpiwg.itgroup.eSciDoc.exceptions.ESciDocXmlObjectException;
+import de.mpiwg.itgroup.eSciDoc.utils.eSciDocXmlObject;
+
+public class RepairPublishingInfoPlaceMain {
+
+	/**
+	 * @param args
+	 * @throws ESciDocXmlObjectException
+	 * @throws JDOMException
+	 * @throws IOException
+	 * @throws IllegalStateException
+	 */
+	public static void main(String[] args) throws IllegalStateException,
+			IOException, JDOMException, ESciDocXmlObjectException {
+
+		Logger logger = Logger.getRootLogger();
+		logger.setLevel(Level.DEBUG);
+		EScidocBasicHandler connector = new EScidocBasicHandler(
+				"escidoc.mpiwg-berlin.mpg.de", 8080, "dwinter", "fl0rian");
+
+		if(args.length<2){
+			System.out.println("Usage: startrecord maximumrecords");
+			System.exit(-1);
+		}
+		String MAX_REC = args[1];
+		String start = args[0];
+		String objectXPath = "//escidocItem:item";
+
+		String query = "?maximumRecords=" + String.valueOf(MAX_REC)
+				+ "&startRecord=" + String.valueOf(start);
+		String command = "/ir/context/escidoc:38279/resources/members";
+		for (eSciDocXmlObject obj : connector.getObjectsFromFilterResult(
+				command + query, objectXPath)) {
+
+			Document doc = obj.getDocument();
+			Boolean changed=false;
+			XPath publishingInfoContentXPath = EScidocTools.getESciDocXpath("//publication:publication[@type='http://purl.org/eprint/type/Book']/source:source/eterms:publishing-info/*");
+			XPath publishingInfoXPath = EScidocTools.getESciDocXpath("//publication:publication/eterms:publishing-info");
+			@SuppressWarnings("unchecked")
+			HashMap<String,Element> piContentHash = new HashMap<String, Element>();
+			
+			
+			List<Element> piContents =publishingInfoContentXPath.selectNodes(doc);
+			for (Element piContent : piContents) {
+				
+				String piContentName=piContent.getName();
+				//if (piContentName.equals("place")){
+					//piContent.detach();
+					System.out.println("add:"+piContent.getQualifiedName());
+					Element pi = (Element)publishingInfoXPath.selectSingleNode(doc);
+					
+					XPath xp= EScidocTools.getESciDocXpath("//publication:publication/eterms:publishing-info/"+piContent.getQualifiedName());
+					Element el=(Element)xp.selectSingleNode(doc);
+					if(el==null){
+						System.out.println("Adding:"+piContent.getQualifiedName());
+						if(pi==null){
+							System.out.println("      Cannot add");
+						} else {
+						pi.addContent((Element)piContent.clone());
+						changed=true;
+						}
+					}
+					
+					
+				//}
+				
+
+				//piContentHash.put(piContentTag,piContent);
+			}
+			
+//			for (Element publishingInfo: (List<Element>)publishingInfoXPath.selectNodes(doc)){
+//				for(String piContentTag: piContentHash.keySet()){
+//					Element piContent = piContentHash.get(piContentTag);
+//				
+//					XPath xp= EScidocTools.getESciDocXpath("./"+piContent.getQualifiedName());
+//					Element el=(Element)xp.selectSingleNode(publishingInfo);
+//					if(el==null){
+//						System.out.println("Adding:"+piContent.getQualifiedName());
+//						publishingInfo.addContent((Element)piContent.clone());
+//						changed=true;
+//					}
+//					
+//					
+//				
+//			}
+//				
+//			}
+//			System.out.println(obj.printXML());
+			if (changed){
+				
+				Boolean retVal = connector.updateItem(obj);
+				System.out.println("Replaced:"+obj.getESciDocId());
+				HttpResponse retValu = connector.submitAnObject(obj, "repairing publishing info (pulisher in bookitem)");
+				
+				System.out.println(EScidocBasicHandler.convertStreamToString(retValu.getEntity().getContent()));
+				HttpResponse resObj = connector.eScidocGet(obj.getESciDocId());
+				HttpEntity ent = resObj.getEntity();
+				if (ent!=null){
+				obj= new eSciDocXmlObject(ent.getContent());
+				} else {
+					System.out.println("Can not retrieve:" + obj.getESciDocId());
+					continue;
+				}
+				
+				HttpResponse reValue2 = connector.releaseAnObject(obj, "repairing publishing info (publisher in bookitem");
+				System.out.println(EScidocBasicHandler.convertStreamToString(reValue2.getEntity().getContent()));
+
+			}
+		}
+
+	}
+}