LoadMetadataExample.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.SchemaImportHelper;
  17. import com.ibm.bi.platform.modeling.sdk.examples.internal.ModelingHelper;
  18. import com.ibm.bi.platform.modeling.sdk.examples.internal.UnexpectedHTTPResponseException;
  19. /**
  20. * example which will load a datasource schema with all or subset of tables
  21. * defined by a spec loaded from a file
  22. */
  23. public class LoadMetadataExample {
  24. /**
  25. * Execute example which will load a datasource schema
  26. *
  27. * @param args
  28. * args[0] ca server url origin, e.g. http://localhost:9300/
  29. *
  30. * args[1] file location with login credentials, e.g. { "parameters": [ { "name":
  31. * "CAMNamespace", "value": "LDAP" }, { "name": "h_CAM_action",
  32. * "value": "logonAs" }, { "name": "CAMUsername", "value":
  33. * "hmiller" }, { "name": "CAMPassword", "value": "hillock" } ] }
  34. *
  35. *
  36. * args[2] datasource store Id
  37. * args[3] connection store id
  38. * args[4] signon store id
  39. *
  40. * args[5] file location with schema import options
  41. * , e.g.
  42. * {"schema":"FOODMART","catalog":"null","type":"dataSourceSchema",
  43. * "schemaType":"user","defaultName":"FOODMART"}
  44. *
  45. * or
  46. *
  47. * { "schema": "Person", "catalog": "AdventureWorks2014",
  48. * "schemaType": "user", "specification": { "dataStatistics":
  49. * "none", "excludedTables": [], "dataSamplingSize": 1000,
  50. * "version": "1.0", "importPrimaryForeignKeys": true },
  51. * "defaultName": "AdventureWorks2014/Person", "type":"dataSourceSchema" }
  52. */
  53. public static void main(String[] args) {
  54. if (args.length < 6) {
  55. System.err.println("Wrong number of arguments:" + args.length);
  56. System.err.println(
  57. "Correct arguments: origin fileWithCredentials datasourceId connectionId signonId fileWithschemaImportDefintion");
  58. System.err.println("origin - ca server url origin, e.g. http://localhost:9300/");
  59. System.err.println("fileWithCredentials - login credentials relative file path");
  60. System.err.println("datasourceId - datasource store id");
  61. System.err.println("connectionId - datasource connection store id");
  62. System.err.println("signonId - signon object store id");
  63. System.err.println("fileWithschemaImportDefintion - relative to the current directory file path to import options");
  64. return;
  65. }
  66. try {
  67. String origin = args[0], credentials = ModelingHelper.stringFromFile(args[1]), datasourceId = args[2],
  68. connectionId = args[3], signonId = args[4], importOptions = ModelingHelper.stringFromFile(args[5]);
  69. SchemaImportHelper helper = new SchemaImportHelper(origin);
  70. helper.authenticate(credentials);
  71. helper.runLoadMetadataExample(datasourceId, connectionId, signonId, importOptions);
  72. } catch (UnexpectedHTTPResponseException e) {
  73. try {
  74. System.out.println("Response :" + ModelingHelper.httpEntityToString(e.getResponse().getEntity()));
  75. } catch (IOException io) {
  76. }
  77. e.printStackTrace();
  78. } catch (IOException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. }