LoadMetadataWithSelectedTables.java 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /***************************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * IBM Cognos Products: Moser
  7. *
  8. * (C) Copyright IBM Corp. 2020
  9. *
  10. * The source code for this program is not published or otherwise
  11. * divested of its trade secrets, irrespective of what has been
  12. * deposited with the U.S. Copyright Office.
  13. *
  14. ***************************************************************************************/
  15. import java.io.IOException;
  16. import com.ibm.bi.platform.modeling.sdk.examples.ModelingRESTEndpoints;
  17. import com.ibm.bi.platform.modeling.sdk.examples.SchemaImportHelper;
  18. import com.ibm.bi.platform.modeling.sdk.examples.internal.ModelingHelper;
  19. import com.ibm.bi.platform.modeling.sdk.examples.internal.UnexpectedHTTPResponseException;
  20. import com.ibm.json.java.JSONObject;
  21. /**
  22. * Example loads schema metadata with a subset of tables derived programmatically
  23. *
  24. */
  25. public class LoadMetadataWithSelectedTables {
  26. /**
  27. * Execute example which will load a datasource schema
  28. *
  29. * @param args
  30. * args[0] ca server url origin, e.g. http://localhost:9300/
  31. *
  32. * args[1] file location with login credentials, e.g. {
  33. * "parameters": [ { "name": "CAMNamespace", "value": "LDAP" }, {
  34. * "name": "h_CAM_action", "value": "logonAs" }, { "name":
  35. * "CAMUsername", "value": "hmiller" }, { "name": "CAMPassword",
  36. * "value": "hillock" } ] }
  37. *
  38. * args[2] datasource store Id
  39. * args[3] connection store id
  40. * args[4] signon store id
  41. *
  42. * args[5] catalog name
  43. * args[6] schema name
  44. *
  45. */
  46. public static void main(String[] args) {
  47. if (args.length < 7) {
  48. System.err.print(
  49. "Correct arguments: origin fileWithCredentials datasourceId connectionId signonId schema_name catalog_name");
  50. return;
  51. }
  52. try {
  53. String origin = args[0];
  54. String credentials = ModelingHelper.stringFromFile(args[1]), datasourceId = args[2],
  55. connectionId = args[3], signonId = args[4],
  56. catalog_name = args[5].isEmpty() ? null : args[5],
  57. schema_name = args[6].isEmpty() ? null : args[6];
  58. SchemaImportHelper helper = new SchemaImportHelper(origin);
  59. helper.authenticate(credentials);
  60. String url = helper.getOrigin() + ModelingRESTEndpoints.datasourcesURL + datasourceId;
  61. String response = helper.executeGetRequest(url, Integer.valueOf(200), null);
  62. JSONObject json = JSONObject.parse(response);
  63. String datasource_name = (String) json.get("defaultName");
  64. if(datasource_name == null){
  65. System.out.println("Datasource definition errors - datasource is missing manadatory attribute: default name");
  66. return;
  67. }
  68. url = helper.getOrigin() + ModelingRESTEndpoints.datasourcesURL + datasourceId + "/connections/" + connectionId;
  69. response = helper.executeGetRequest(url, Integer.valueOf(200), null);
  70. json = JSONObject.parse(response);
  71. String connection_name = (String) json.get("defaultName");
  72. if(connection_name == null){
  73. System.out.println("Datasource definition errors - datasource is missing manadatory attribute: default name");
  74. return;
  75. }
  76. helper.runLoadMetadataWithSelectedTablesExample(datasourceId, connectionId, signonId, datasource_name, connection_name, catalog_name, schema_name);
  77. } catch (UnexpectedHTTPResponseException e) {
  78. try {
  79. System.out.println("Response :" + ModelingHelper.httpEntityToString(e.getResponse().getEntity()));
  80. } catch (IOException io) {
  81. }
  82. e.printStackTrace();
  83. } catch (IOException e) {
  84. e.printStackTrace();
  85. }
  86. }
  87. }