package edu.indiana.dde.catalog.catalogtester; import java.io.File; import edu.indiana.dde.metadata.catalog.types.*; import edu.indiana.dde.catalog.catalogclient.*; public class TestUpdateProperty extends TesterBase { /** * @param args */ public static void main(String[] args) throws Exception { int option = 0; String errorDelivery = "DIRECT"; String hostName = "localhost"; String portNum = "8080"; String myDn = null; //the creator of the new user String fileName = null; String objectId = null; int position = -1; //default of no position long lastUpdate = -1; for (int j = 0; j < args.length; j++) { String argVal = args[j]; if ( argVal.compareToIgnoreCase("--help") == 0 || argVal.compareToIgnoreCase("-help") == 0) { usage(); return; } else if (argVal.startsWith("-")) { if (argVal.compareToIgnoreCase("-ed") == 0) option = 2; //error delivery else if (argVal.compareToIgnoreCase("-g") == 0) option = 1; //object ID else if (argVal.compareToIgnoreCase("-pos") == 0) option = 6; //replacement position (for multiple property instance) else if (argVal.compareToIgnoreCase("-dn") == 0) option = 3; //distinguished name else if (argVal.compareToIgnoreCase("-u") == 0) option = 8;//last update (from query header) else if (argVal.compareToIgnoreCase("-f") == 0) option = 7;//file name else if (argVal.compareToIgnoreCase("-h") == 0) option = 4; //host name else if (argVal.compareToIgnoreCase("-p") == 0) option = 5; //port else //invalid option = 0; } else if (option > 0) { if (option == 2) { String priorMethod = errorDelivery; if (argVal.compareToIgnoreCase("STREAMING") == 0) errorDelivery = "STREAMING"; else if(argVal.compareToIgnoreCase("DIRECT") == 0) errorDelivery = "DIRECT"; else { errorDelivery = priorMethod; String msg = "The error delivery method specified (" + argVal + ") is not valid. Restored prior setting: " + priorMethod; System.out.println(msg); } } else if (option == 1) objectId = argVal; else if (option == 3) myDn = argVal; else if (option == 4) hostName = argVal; else if (option == 5) portNum = argVal; else if (option == 6) position = Integer.parseInt(argVal); else if (option == 7) fileName = argVal; else if (option == 8) lastUpdate = Long.parseLong(argVal); option = 0; //reset } //end of option setting } //loop through parameters if (fileName == null || myDn == null || objectId == null) { usage(); return; } CatalogServiceStub stub = getStub(hostName, portNum, myDn); UpdatePropertyRequestDocument doc = UpdatePropertyRequestDocument.Factory.newInstance(); UpdatePropertyRequestDocument.UpdatePropertyRequest request = doc.addNewUpdatePropertyRequest(); request.setErrorDeliveryMethod(CatalogDeliveryType.Enum.forString(errorDelivery) ); UpdatePropertyType myUpdate = request.addNewUpdateProperty(); myUpdate.setObjectId(objectId); if (position > 0) myUpdate.setPosition(position); if (lastUpdate >= 0) myUpdate.setLastUpdate(lastUpdate); File dataFile = new File(fileName); CatalogPropertyUpdateDocument propertyDoc = null; try { propertyDoc = CatalogPropertyUpdateDocument.Factory.parse(dataFile); } catch (Exception e) { System.out.println("An error occurred in parsing the bean: " + e); return; } myUpdate.setCatalogPropertyUpdate(propertyDoc.getCatalogPropertyUpdate() ); request.setUpdateProperty(myUpdate); System.out.println(doc.toString() ); //invoke service UpdatePropertyResponseDocument myResponse = stub.updateProperty(doc); System.out.println(myResponse.getUpdatePropertyResponse().getCatalogOperationStatus().getStatus().toString() ); System.out.println("\nResponse Document:\n******************\n" + myResponse.toString() ); return; } //end of main private static void usage() { System.out.println("Usage: TestUpdateProperty -f -g -pos -u -dn -ed -h -p \n" + "position = 1\n" + "errors = DIRECT\n" + "host = localhost\n" + "port = 8080\n" + "Error Delivery Options: STREAMING, DIRECT"); return; } //end of usage } //end of TestUpdateProperty