package edu.indiana.dde.catalog.catalogtester; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.ArrayList; import edu.indiana.dde.metadata.catalog.types.*; import edu.indiana.dde.catalog.catalogclient.*; //Classes from the XML Bean for the LEAD Metadata Schema import edu.indiana.extreme.lead.metadata.*; /** * This program is used to test the addProperty operation. Each property * to be added should be the XML of a LEAD property and contained in a * separate file. Each file is specified on the command line using the * -f flag. This test adds all of the properties to the single specified * object. The addProperty operation also allows for properties to be added * to multiple objects owned by the same user as a single call. * * @author Scott Jensen scjensen@cs.indiana.edu * */ public class TestAddProperty extends TesterBase { /** * @param args */ public static void main(String[] args) throws Exception { int option = 0; String guid = null; String hostName = "localhost"; String portNum = "8080"; String myDn = null; String delivery = "DIRECT"; ArrayList fileNames = new ArrayList(); 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 = 2; //guid else if (argVal.compareToIgnoreCase("-dn") == 0) option = 3; //distinguished name 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 if (argVal.compareToIgnoreCase("-d") == 0) option = 6; //error delivery method else //invalid option = 0; } else if (option > 0) { if (option == 2) guid = argVal; else if (option == 3) myDn = argVal; else if (option == 4) hostName = argVal; else if (option == 5) portNum = argVal; else if (option == 7) fileNames.add(argVal); else if (option == 6) { String priorMethod = delivery; if (argVal.compareToIgnoreCase("STREAMING") == 0) delivery = "STREAMING"; else if(argVal.compareToIgnoreCase("DIRECT") == 0) delivery = "DIRECT"; else { delivery = priorMethod; String msg = "The delivery method specified (" + argVal + ") is not valid. Restored prior setting: " + priorMethod; System.out.println(msg); } } option = 0; //reset } //end of option setting } //loop through parameters if (fileNames.size() == 0 || myDn == null || guid == null) { usage(); return; } CatalogServiceStub stub = getStub(hostName, portNum, myDn); AddPropertyRequestDocument doc = AddPropertyRequestDocument.Factory.newInstance(); AddPropertyRequestDocument.AddPropertyRequest request = doc.addNewAddPropertyRequest(); request.setErrorDeliveryMethod(CatalogDeliveryType.Enum.forString(delivery)); CatalogPropertyType property = request.addNewCatalogProperty(); property.setObjectId(guid); ArrayList catalogPropertyAddArray = new ArrayList(fileNames.size() ); // add the properties int pos = 0; for (String filename: fileNames) { FileReader frData = null; BufferedReader inData = null; try { StringBuffer dataBuffer = new StringBuffer(8192); dataBuffer.append(""); File dataFile = new File(filename); frData = new FileReader(dataFile); inData = new BufferedReader(frData); String dataLine; while ( (dataLine = inData.readLine() ) != null) { dataBuffer.append(dataLine); } dataBuffer.append(""); CatalogPropertyAddDocument addDoc = CatalogPropertyAddDocument.Factory.parse(dataBuffer.toString() ); catalogPropertyAddArray.add(addDoc.getCatalogPropertyAdd() ); } catch (Exception e) { System.out.println("There was an error loading the data file: " + filename + " and the properties were not added: " + e); return; } finally { try { inData.close(); } catch (Exception e) {} try { frData.close(); } catch (Exception e) {} } } //loop through the files // put the properties into the add document CatalogPropertyAddType[] addTypeArray = new CatalogPropertyAddType[catalogPropertyAddArray.size()]; for (int i=0; i < catalogPropertyAddArray.size(); i++) { addTypeArray[i] = catalogPropertyAddArray.get(i); } property.setCatalogPropertyAddArray(addTypeArray); catalogPropertyAddArray.clear(); // Call the catalog AddPropertyResponseDocument myResponse = stub.addProperty(doc); System.out.println(myResponse.getAddPropertyResponse().getCatalogOperationStatus().getStatus().toString() ); System.out.println("\nResponse Document:\n******************\n" + myResponse.toString() ); return; } //end of main private static void usage() { System.out.println("Usage: TestAddProperties -f -g -dn -d -h -p \n" + "Defaults:\n" + "delivery = DIRECT" + "host = localhost\n" + "port = 8080\n" + "delivery method options for errors:\n" + "DIRECT - included in response\n" + "STREAMING - response includes URL for retrieving errors"); return; } //end of usage } //end of TestAddProperty