package edu.indiana.dde.catalog.catalogtester; import edu.indiana.dde.metadata.catalog.types.*; import edu.indiana.dde.catalog.catalogclient.*; import java.util.*; import java.io.*; //Classes from the XML Bean for the LEAD Metadata Schema import edu.indiana.extreme.lead.metadata.*; /** * This program tests the creation of an object (e.g., an experiment, collection or * file). The XML for the object is provided in a file and the name of the file is * passed as a parameter. The -g parameter provides for passing a substitute global * ID for the object being added. The LEADresource contained in the file will be * edited to replace the global ID. This allows the same test file to be reused * without needing to edit the global ID. If the object being added is not a top-level * object (project) then the GUID of the new object's parent must also be provided. * * @author Scott Jensen scjensen@cs.indiana.edu * */ public class TestCreateObject extends TesterBase { /** * @param args */ public static void main(String[] args) throws Exception { int option = 0; String replacementGuid = null; String parentGuid = null; String hostName = "localhost"; String portNum = "8080"; String objType = "FILE"; String myDn = null; String fileName = null; 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("-pg") == 0) option = 2; //parent guid else if (argVal.compareToIgnoreCase("-g") == 0) option = 1; //alternate 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("-t") == 0) option = 6; //object type else //invalid option = 0; } else if (option > 0) { if (option == 2) parentGuid = argVal; else if (option == 1) replacementGuid = argVal; else if (option == 3) myDn = argVal; else if (option == 4) hostName = argVal; else if (option == 5) portNum = argVal; else if (option == 6) objType = argVal; else if (option == 7) fileName = argVal; option = 0; //reset } //end of option setting } //loop through parameters if (fileName == null || myDn == null) { usage(); return; } CatalogServiceStub stub = getStub(hostName, portNum, myDn); CreateObjectRequestDocument doc = CreateObjectRequestDocument.Factory.newInstance(); CreateObjectRequestDocument.CreateObjectRequest request = doc.addNewCreateObjectRequest(); request.setErrorDeliveryMethod(CatalogDeliveryType.Enum.forString("STREAMING") ); //Open the file and load the LEADresource document StringBuffer dataBuffer = new StringBuffer(8192); FileReader frData = null; BufferedReader inData = null; try { File dataFile = new File(fileName); frData = new FileReader(dataFile); inData = new BufferedReader(frData); String dataLine; while ( (dataLine = inData.readLine() ) != null) { dataBuffer.append(dataLine); } } catch (Exception e) { System.out.println("There was an error loading the data file: " + e); return; } finally { try { inData.close(); } catch (Exception e) {} try { frData.close(); } catch (Exception e) {} } LEADresourceDocument myLeadDoc = null; try { myLeadDoc = LEADresourceDocument.Factory.parse(dataBuffer.toString() ); } catch (Exception e) { System.out.println("An error occurred in parsing the bean: " + e); return; } //check if user supplied a replacement GUID if (replacementGuid != null) myLeadDoc.getLEADresource().setResourceID(replacementGuid); CatalogDataType myData = request.addNewCatalogData(); myData.setCatalogType(CatalogAggregationType.Enum.forString(objType) ); if (parentGuid != null) myData.setParentId(parentGuid); myData.setLEADresource(myLeadDoc.getLEADresource() ); System.out.println(doc.toString() ); //invoke service CreateObjectResponseDocument myResponse = stub.createObject(doc); System.out.println(myResponse.getCreateObjectResponse().getCatalogOperationStatus().getStatus().toString() ); System.out.println("\nResponse Document:\n******************\n" + myResponse.toString() ); return; } //end of main private static void usage() { System.out.println("Usage: TestCreateObject -f -g -pg -t -dn -h -p \n" + "Defaults:\n" + "object type = FILE\n" + "parent = not set\n" + "parent type = PROJECT\n" + "host = localhost\n" + "port = 8080\n" + "Possible Types: FILE, COLLECTION, EXPERIMENT, PROJECT\n" + "The optional GUID can be used to replace the resourceID used in the file document"); return; } //end of usage } //end of TestCreateObject