package edu.indiana.dde.catalog.catalogtester; import java.util.ArrayList; import edu.indiana.dde.metadata.catalog.types.*; import edu.indiana.dde.catalog.catalogclient.*; /** * This class is for testing the deleteProperty operation. If a property has * a cardinality exceeding 1, then the position of the instance of that property * to be deleted must be specified. The position is based on the order that is * used in the query result when the FULL_SCHEMA option is used for the content * filter. The position of the first instance is 1, not 0. * The timestamp parameter (specified in this test as -ts) is the timestamp * from the header of the query. This is to ensure that the metadata has not changed * since the view the user is looking at in determining the deletetion(s). * For system-geerated deletions, a value of -1 for the timestamp forces the * deletion without considering the timestamp. * multiple positions can be specifie d in this test (and in the operation). For * the test each instance should be proeceeded by -pos, so to delete the instances in * positions 3 and 5, include the following on the parameters: -pos 3 -pos 5. * A range can also be specified using -fpos and -lpos, The deletion is inclusive * of the first and last positions. * * @author Scott Jensen scjensen@cs.indiana.edu * */ public class TestDeleteProperty extends TesterBase { /** * @param args */ public static void main(String[] args) throws Exception { int option = 0; String guid = null; String propertyName = null; String propertySource = "LEAD"; ArrayList positions = new ArrayList(); int startPos = -1; int endPos = -1; String hostName = "localhost"; String portNum = "8080"; String myDn = null; String errorDelivery = "DIRECT"; 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("-g") == 0) option = 1; //GUID else if (argVal.compareToIgnoreCase("-dn") == 0) option = 3; //distinguished name else if (argVal.compareToIgnoreCase("-h") == 0) option = 4; //host name else if (argVal.compareToIgnoreCase("-p") == 0) option = 5; //port else if (argVal.compareToIgnoreCase("-pn") == 0) option = 6;//property name else if (argVal.compareToIgnoreCase("-ps") == 0) option = 7; //property source else if (argVal.compareToIgnoreCase("-pos") == 0) option = 8; //position (single or multiple delete) else if (argVal.compareToIgnoreCase("-fpos") == 0) option = 9;//first position (range delete) else if (argVal.compareToIgnoreCase("-lpos") == 0) option = 10;//last position (range delete) else if (argVal.compareToIgnoreCase("-ed") == 0) option = 11;//error delivery else if (argVal.compareToIgnoreCase("-ts") == 0) option = 12;//last update else //invalid option = 0; } else if (option > 0) { if (option == 1) guid = argVal; else if (option == 3) myDn = argVal; else if (option == 4) hostName = argVal; else if (option == 5) portNum = argVal; else if (option == 6) propertyName = argVal; else if (option == 7) propertySource = argVal; else if (option == 8) positions.add(new Integer(argVal) ); else if (option == 9) startPos = Integer.parseInt(argVal); else if (option == 10) endPos = Integer.parseInt(argVal); if (option == 11) { 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 == 12) lastUpdate = Long.parseLong(argVal); option = 0; //reset } //end of option setting } //loop through parameters if (guid == null || propertyName == null || propertySource == null || myDn == null) { usage(); return; } CatalogServiceStub stub = getStub(hostName, portNum, myDn); DeletePropertyRequestDocument doc = DeletePropertyRequestDocument.Factory.newInstance(); DeletePropertyRequestDocument.DeletePropertyRequest request = doc.addNewDeletePropertyRequest(); request.setErrorDeliveryMethod(CatalogDeliveryType.Enum.forString(errorDelivery) ); DeletePropertyType property = request.addNewDeleteProperty(); property.setObjectId(guid); property.setPropertyName(propertyName); property.setPropertySource(propertySource); property.setLastUpdate(lastUpdate); // Use the positions if any are specified, otherwise use the range if both // the first and last position are set to valid values. if (positions.size() > 0) { for (Integer pos: positions) property.addPosition(pos.intValue() ); } else if (startPos > -1 && endPos > -1 && startPos <= endPos) { DeletePropertyRangeType range = property.addNewPropertyRange(); range.setFirst(startPos); range.setLast(endPos); } System.out.println(doc.toString() ); //invoke service DeletePropertyResponseDocument myResponse = stub.deleteProperty(doc); System.out.println(myResponse.getDeletePropertyResponse().getCatalogOperationStatus().getStatus().toString() ); System.out.println("\nResponse Document:\n******************\n" + myResponse.toString() ); stub.cleanup(); return; } //end of main private static void usage() { System.out.println("Usage: TestDeleteProperty -g -pn -ps -pos -fpos -lpos -ts -dn -h -p -ed \n" + "Defaults:\n" + "property source = LEAD\n" + "host = localhost\n" + "port = 8080\n" + "error delivery = DIRECT\n" + "Error delivery can be either DIRECT or STREAMING.\n" + "pos can be repeated for multiple positions. fpos and lpos are optional, but both are required if used.\n" + "The pos and fpos/lpos are mutually exclusive and pos takes priority."); return; } //end of usage } //end of class