Created
April 10, 2012 19:31
-
-
Save mark-cooper/2353882 to your computer and use it in GitHub Desktop.
Batch deleting ContentDM records using Catcher and file of record identifiers
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.List; | |
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 deleting ContentDM records using Catcher and file of record identifiers | |
* 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))); | |
List<String> dmRecordIdentifiers = new ArrayList<String>(); | |
List<String> dmErrors = new ArrayList<String>(); | |
String id; | |
while((id = reader.readLine()) != null) { | |
dmRecordIdentifiers.add(id); | |
} | |
reader.close(); | |
int count = 1; | |
for(String dmRecord : dmRecordIdentifiers) { | |
try { | |
System.out.println(count); | |
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); | |
MetadataWrapper wrapper = new MetadataWrapper(); | |
wrapper.setMetadataList(mList); | |
System.out.println ("\n\nDelete an item to collection\n----------------------------"); | |
retMsg = cs.getCatcherPort().processCONTENTdm("delete", 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