Mercurial > hg > eSciDocImport
view src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/RepairPublishingInfoDate.java @ 19:671c6e3449f7
add coneids added
author | dwinter |
---|---|
date | Mon, 27 May 2013 15:06:53 +0200 |
parents | da598103dd22 |
children |
line wrap: on
line source
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 RepairPublishingInfoDate { /** * @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.INFO); if(args.length<5){ System.out.println("Usage: username password contextID (eg.escidoc:XXX) startrecord maximumrecords"); System.exit(-1); } String MAX_REC = args[4]; String start = args[3]; String contextId = args[2]; String username = args[0]; String password = args[1]; String objectXPath = "//escidocItem:item"; EScidocBasicHandler connector = new EScidocBasicHandler( "escidoc.mpiwg-berlin.mpg.de", 8080, username,password); String query = "?maximumRecords=" + String.valueOf(MAX_REC) + "&startRecord=" + String.valueOf(start); //String command = "/ir/context/escidoc:38279/resources/members"; String command = "/ir/context/"+contextId+"/resources/members"; //String command = "/ir/context/escidoc:79281/resources/members"; System.out.println("search for:"+command+query); Integer i=0; for (eSciDocXmlObject obj : connector.getObjectsFromFilterResult( command + query, objectXPath)) { i++; Document doc = obj.getDocument(); Boolean changed=false; XPath publishingInfoContentXPath = EScidocTools.getESciDocXpath("//publication:publication/dcterms:created"); XPath publishingInfoContentXPathIssued = EScidocTools.getESciDocXpath("//publication:publication/dcterms:issued"); XPath publishingInfoXPath = EScidocTools.getESciDocXpath("//publication:publication"); @SuppressWarnings("unchecked") HashMap<String,Element> piContentHash = new HashMap<String, Element>(); System.out.println(i); Element issued =(Element)publishingInfoContentXPathIssued.selectSingleNode(doc); if (issued==null){ List<Element> piContents =publishingInfoContentXPath.selectNodes(doc); for (Element piContent : piContents) { String creationDate=piContent.getText(); System.out.println("found creation and no issue date:"+creationDate); Element node = (Element)publishingInfoXPath.selectSingleNode(doc); //Element element = new Element("issued",EScidocTools.dcterms); //element.setText(creationDate); //node.addContent(element); piContent.setName("issued"); String piContentName=piContent.getName(); changed=true; }} 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())); } } } }