/*************************************************************************************** * IBM Confidential * * OCO Source Materials * * IBM Cognos Products: Moser * * (C) Copyright IBM Corp. 2020 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. * ***************************************************************************************/ import java.io.IOException; import com.ibm.bi.platform.modeling.sdk.examples.ModelingRESTEndpoints; import com.ibm.bi.platform.modeling.sdk.examples.SchemaImportHelper; import com.ibm.bi.platform.modeling.sdk.examples.internal.ModelingHelper; import com.ibm.bi.platform.modeling.sdk.examples.internal.UnexpectedHTTPResponseException; import com.ibm.json.java.JSONObject; /** * Example loads schema metadata with a subset of tables derived programmatically * */ public class LoadMetadataWithSelectedTables { /** * Execute example which will load a datasource schema * * @param args * args[0] ca server url origin, e.g. http://localhost:9300/ * * args[1] file location with login credentials, e.g. { * "parameters": [ { "name": "CAMNamespace", "value": "LDAP" }, { * "name": "h_CAM_action", "value": "logonAs" }, { "name": * "CAMUsername", "value": "hmiller" }, { "name": "CAMPassword", * "value": "hillock" } ] } * * args[2] datasource store Id * args[3] connection store id * args[4] signon store id * * args[5] catalog name * args[6] schema name * */ public static void main(String[] args) { if (args.length < 7) { System.err.print( "Correct arguments: origin fileWithCredentials datasourceId connectionId signonId schema_name catalog_name"); return; } try { String origin = args[0]; String credentials = ModelingHelper.stringFromFile(args[1]), datasourceId = args[2], connectionId = args[3], signonId = args[4], catalog_name = args[5].isEmpty() ? null : args[5], schema_name = args[6].isEmpty() ? null : args[6]; SchemaImportHelper helper = new SchemaImportHelper(origin); helper.authenticate(credentials); String url = helper.getOrigin() + ModelingRESTEndpoints.datasourcesURL + datasourceId; String response = helper.executeGetRequest(url, Integer.valueOf(200), null); JSONObject json = JSONObject.parse(response); String datasource_name = (String) json.get("defaultName"); if(datasource_name == null){ System.out.println("Datasource definition errors - datasource is missing manadatory attribute: default name"); return; } url = helper.getOrigin() + ModelingRESTEndpoints.datasourcesURL + datasourceId + "/connections/" + connectionId; response = helper.executeGetRequest(url, Integer.valueOf(200), null); json = JSONObject.parse(response); String connection_name = (String) json.get("defaultName"); if(connection_name == null){ System.out.println("Datasource definition errors - datasource is missing manadatory attribute: default name"); return; } helper.runLoadMetadataWithSelectedTablesExample(datasourceId, connectionId, signonId, datasource_name, connection_name, catalog_name, schema_name); } catch (UnexpectedHTTPResponseException e) { try { System.out.println("Response :" + ModelingHelper.httpEntityToString(e.getResponse().getEntity())); } catch (IOException io) { } e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }