package edu.indiana.dde.catalog.catalogtester; import edu.indiana.dde.metadata.catalog.types.*; import edu.indiana.dde.catalog.catalogclient.*; /** * This small test program is for the Query By Id operation. See the * usage method or execute with --help as the only parameter. * * @author Scott Jensen scjensen@cs.indiana.edu * */ public class TestObjectIdQuery 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 hFilter = "TARGET"; String cFilter = "ID_ONLY"; String resultDelivery = "STREAMING"; String errorDelivery = "DIRECT"; boolean applyAttrFilter = false; boolean applyElementFilter = false; 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("-hf") == 0) option = 6; //Hierarchy Filter else if (argVal.compareToIgnoreCase("-cf") == 0) option = 7; //Content Filter else if (argVal.compareToIgnoreCase("-rd") == 0) option = 8; // Result Delivery else if (argVal.compareToIgnoreCase("-ed") == 0) option = 9; // Error Delivery else if (argVal.compareToIgnoreCase("-attr") == 0) applyAttrFilter = true; // apply the attr filter - no parameter to follow else if (argVal.compareToIgnoreCase("-element") == 0) applyElementFilter = true; // apply the element filter - no parameter to follow // only applies if applyAttrFilter is false 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 //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) hFilter = argVal; else if (option == 7) cFilter = argVal; else if (option == 8) resultDelivery = argVal; else if (option == 9) errorDelivery = argVal; option = 0; //reset } //end of option setting } //loop through parameters if (guid == null || myDn == null) { usage(); return; } CatalogServiceStub stub = getStub(hostName, portNum, myDn); ObjectIdQueryRequestDocument doc = ObjectIdQueryRequestDocument.Factory.newInstance(); ObjectIdQueryRequestDocument.ObjectIdQueryRequest request = doc.addNewObjectIdQueryRequest(); request.addObjectId(guid); QueryResultFormatType resultFormat = request.addNewQueryResultFormat(); resultFormat.setOffset(0); resultFormat.setCount(0); resultFormat.setHierarchyFilter(HierarchyFilterType.Enum.forString(hFilter) ); if (applyAttrFilter) { System.out.println("Applying attribute filter"); PropertyFilterType filterOne = resultFormat.addNewPropertyFilter(); filterOne.setPropertyName("status"); filterOne.setPropertySource("LEAD"); PropertyFilterType filterTwo = resultFormat.addNewPropertyFilter(); filterTwo.setPropertyName("keywordTheme"); filterTwo.setPropertySource("LEAD"); } else if (applyElementFilter) { System.out.println("Applying element filter"); ElementFilterType filterOne = resultFormat.addNewElementFilter(); filterOne.setPropertyName("status"); filterOne.setPropertySource("LEAD"); filterOne.setPropertyName("progress"); filterOne.setElementSource("LEAD"); filterOne.setElementFilter("HowAmIDoin"); ElementFilterType filterTwo = resultFormat.addNewElementFilter(); filterTwo.setPropertyName("keywordTheme"); filterTwo.setPropertySource("LEAD"); filterTwo.setElementName("themeKeyword"); filterTwo.setElementSource("LEAD"); filterTwo.setElementFilter("SomeTheme"); } else { System.out.println("Applying content filter: " + cFilter); resultFormat.setContentFilter(ContentFilterType.Enum.forString(cFilter) ); } resultFormat.setResultDeliveryMethod(CatalogDeliveryType.Enum.forString(resultDelivery) ); resultFormat.setErrorDeliveryMethod(CatalogDeliveryType.Enum.forString(errorDelivery) ); System.out.println(doc.toString() ); //invoke service QueryResponseDocument myResponse = stub.objectIdQuery(doc); System.out.println(myResponse.getQueryResponse().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: TestObjectIdQuery -g -hf -cf -rd -ed -attr -element -dn -h -p \n" + "Defaults:\n" + "hf = TARGET\n" + "cf = ID_ONLY\n" + "rd = STREAMING\n" + "ed = DIRECT\n" + "host = localhost\n" + "port = 8080\n" + "Hierarchy Filter Options: TARGET, SUBTREE\n" + "Content Filter Options: ID_ONLY, FULL_SCHEMA\n" + " -attr option will apply attribute filters\n" + " -element option will apply an element filter (unless -attr is used)\n" + "Result and Error Delivery Options: STREAMING, DIRECT"); return; } //end of usage } //end of TestObjectIdQuery class