Created
April 11, 2012 23:46
-
-
Save mark-cooper/2363526 to your computer and use it in GitHub Desktop.
Batch edit ContentDM records using Catcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sonomalibrary.catcher; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
import org.oclc.cdm.catcherws.CatcherService; | |
import org.oclc.cdm.catcherws.Metadata; | |
import org.oclc.cdm.catcherws.MetadataWrapper; | |
import org.oclc.cdm.catcherws.MetadataWrapper.MetadataList; | |
/** | |
* Demonstrate - | |
* batch edit ContentDM records using Catcher and file of record identifiers:values | |
* Must 1st generate the classes and add to project | |
* C:\>wsimport -p org.oclc.cdm.catcherws -s . | |
* https://worldcat.org/webservices/contentdm/catcher/6.0/CatcherService.wsdl | |
*/ | |
public class OCLCCatcher | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println ("Starting ..."); | |
final String CDMURL = "https://yourserver.contentdm.oclc.org:443/"; | |
final String CDMUSERNAME = "username"; | |
final String CDMPASSWORD = "password"; | |
final String CDMLICENSE = "license"; | |
final String CDMALIAS = "/collection"; | |
final String DMRECORDS = "dmrecords"; // input file name | |
String retMsg; | |
CatcherService cs = new CatcherService(); | |
System.out.println ("Current web service version\n---------------------------"); | |
System.out.println (cs.getCatcherPort().getWSVersion()); | |
BufferedReader reader = new BufferedReader(new FileReader(new File(DMRECORDS))); | |
Map<String, String> dmRecordIdentifiers = new HashMap<String, String>(); | |
List<String> dmErrors = new ArrayList<String>(); | |
String id; | |
while((id = reader.readLine()) != null) { | |
String[] parts = id.split(":"); | |
dmRecordIdentifiers.put(parts[0], parts[1]); | |
} | |
reader.close(); | |
int count = 1; | |
Set<String> dmRecordIdentifiersKeys = dmRecordIdentifiers.keySet(); | |
for(String dmRecord : dmRecordIdentifiersKeys) { | |
try { | |
System.out.println(count); | |
System.out.println(dmRecord); | |
System.out.println(dmRecordIdentifiers.get(dmRecord)); | |
if(dmRecord.equals("")) continue; | |
MetadataWrapper.MetadataList mList = new MetadataList(); | |
List<Metadata> metadata = mList.getMetadata(); | |
Metadata m = new Metadata(); | |
m.setField("dmrecord"); | |
m.setValue(dmRecord); | |
metadata.add(m); | |
m = new Metadata(); | |
m.setField("dmoclcno"); | |
m.setValue(dmRecordIdentifiers.get(dmRecord)); | |
metadata.add(m); | |
MetadataWrapper wrapper = new MetadataWrapper(); | |
wrapper.setMetadataList(mList); | |
System.out.println ("\n\nEdit an item to collection\n----------------------------"); | |
retMsg = cs.getCatcherPort().processCONTENTdm("edit", CDMURL, | |
CDMUSERNAME, CDMPASSWORD, CDMLICENSE, CDMALIAS, wrapper); | |
System.out.println (retMsg); | |
count++; | |
} catch (Exception e) { | |
dmErrors.add("Error: " + dmRecord); | |
} | |
} | |
for(String error : dmErrors) { | |
System.out.println (error); | |
} | |
System.out.println ("\n\nCONTENTdm upload module version\n-------------------------------"); | |
System.out.println ( | |
cs.getCatcherPort().getCONTENTdmHTTPTransferVersion(CDMURL, | |
CDMUSERNAME, CDMPASSWORD)); | |
System.out.println ("\n\nDONE"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment