Mercurial > hg > eSciDocImport
changeset 4:cb5668b07bfc
neuer check ob datei schon existiert.
author | dwinter |
---|---|
date | Wed, 12 Jan 2011 16:34:42 +0100 |
parents | 58b52df9763c |
children | a42dabfcffdf |
files | src/de/mpiwg/itgroup/eSciDoc/Tools/EScidocBasicHandler.java src/de/mpiwg/itgroup/eSciDoc/harvesting/ESciDocDataHarvester.java |
diffstat | 2 files changed, 128 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/de/mpiwg/itgroup/eSciDoc/Tools/EScidocBasicHandler.java Wed Jan 12 11:00:14 2011 +0100 +++ b/src/de/mpiwg/itgroup/eSciDoc/Tools/EScidocBasicHandler.java Wed Jan 12 16:34:42 2011 +0100 @@ -559,7 +559,7 @@ } - public List<eSciDocXmlObject> getObjectListFromFilterResult(String command, String objectXpath) throws IOException, IllegalStateException, JDOMException,ESciDocXmlObjectException { + public List<eSciDocXmlObject> getObjectsFromFilterResult(String command, String objectXpath) throws IOException, IllegalStateException, JDOMException,ESciDocXmlObjectException { //String filter = "<param><filter></filter></param>"; // //String command = context @@ -819,6 +819,35 @@ + public List<eSciDocXmlObject> getObjectsFromSearch(String field, String value) throws ESciDocXmlObjectException { + String query = "/srw/search/escidoc_all?operation=searchRetrieve&version=1.1&query="; + query+=field+"%3d"; + try { + query+=URLEncoder.encode(value, "utf-8"); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new ESciDocXmlObjectException(); + } + + try { + return getObjectsFromFilterResult(query, "//escidocItem:item"); + } catch (IllegalStateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JDOMException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + throw new ESciDocXmlObjectException(); // fehler wenn kein return + } + + +
--- a/src/de/mpiwg/itgroup/eSciDoc/harvesting/ESciDocDataHarvester.java Wed Jan 12 11:00:14 2011 +0100 +++ b/src/de/mpiwg/itgroup/eSciDoc/harvesting/ESciDocDataHarvester.java Wed Jan 12 16:34:42 2011 +0100 @@ -5,6 +5,7 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.ArrayList; +import java.util.List; import java.util.Map; import org.apache.http.HttpEntity; @@ -68,7 +69,8 @@ * @throws TransformerException * @throws ESciDocXmlObjectException */ - public Boolean readObjectsFromInstance(String type) throws ConnectorException, TransformerException, ESciDocXmlObjectException { + @Deprecated + public Boolean readObjectsFromInstanceOLD(String type) throws ConnectorException, TransformerException, ESciDocXmlObjectException { ArrayList<String> addedObjects = new ArrayList<String>(); ArrayList<String> notAddedObjects = new ArrayList<String>(); for (ECHOObject obj : importer.getObjectList(type)) { @@ -144,6 +146,100 @@ } + /** Read objects into eScidoc or updates the objects if indexMeta has changed. + * @param type restrict the imported objects to a specific type, possible types should be defined in + * the given importer @see {@link #importer} + * @return + * @throws ConnectorException + * @throws TransformerException + * @throws ESciDocXmlObjectException + */ + public Boolean readObjectsFromInstance(String type) throws ConnectorException, TransformerException, ESciDocXmlObjectException { + ArrayList<String> addedObjects = new ArrayList<String>(); + ArrayList<String> notAddedObjects = new ArrayList<String>(); + for (ECHOObject obj : importer.getObjectList(type)) { + + if (ECHORessource.class.isInstance(obj)) { + try { + + // checke zuerst, ob die MD5 schon im publiziert Teil der Metadaten ist, dann tue nichts + String md5 = ((ECHORessource) obj).getIndexMetaMD5onServer(); + List<eSciDocXmlObject> results = connector.getObjectsFromSearch("escidoc.component.checksum",md5); + if (results.size()>0){ //index.meta schon abgespeichert + continue; + } + + + + ECHOObject old; + try { + + old = connector.alreadyExists( + "/md-records/md-record/admin/archivePath", + ((ECHORessource) obj).archivePath, echoContext); + } catch (ObjectNotUniqueError e) { + // TODO Auto-generated catch block + e.printStackTrace(); + continue; + } + if (old!=null) { + logger.debug("already exist:" + + ((ECHORessource) obj).archivePath); + handleExistingObject(obj,old); + continue; + } + } catch (ConnectorException e) { + logger.debug("already exist error:"); + e.printStackTrace(); + continue; + } + } + + obj.context = echoContext; + + String contid = connector.getIDfromPID(obj.pid, echoContext); + if (contid != null) { + System.out.println("------- belongsTo:" + contid); + } else { + + eSciDocXmlObject escidocItem = transformer.transform(obj); + + + try { + logger.info(escidocItem.printXML()); + // TODO write PID to back to echo-obj + Boolean result = connector.createItem(escidocItem); + if (result) { + addedObjects.add(escidocItem.getESciDocId()); + addedFile.debug(escidocItem.getESciDocId() + "\n"); + + } else { + notAddedObjects.add(obj.echoUrl); + notAddedFile.debug(obj.echoUrl); + + } + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new ESciDocXmlObjectException(); + } catch (JDOMException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new ESciDocXmlObjectException(); + } + + } + } + if (logger.getLevel() == Level.DEBUG) { + for (String addedObject : addedObjects) { + logger.debug(addedObject); + } + } + + return true; + } + @@ -223,7 +319,7 @@ String query = "?maximumRecords="+String.valueOf(MAX_REC)+"&startRecord=" + String.valueOf(start)+"&"+queryRestrict; for (eSciDocXmlObject obj : connector - .getObjectListFromFilterResult(command+query, objectXPath)) { + .getObjectsFromFilterResult(command+query, objectXPath)) { //TODO is the following really necessary, currently the obj in the list is sometimes not the current one. try{