package com.ntrs.nform.metadata;
import java.util.regex.Matcher;import java.util.regex.Pattern;
import com.cognos.developer.schemas.bibus._3.BaseClass;import com.cognos.developer.schemas.bibus._3.DataSourceConnection;import com.cognos.developer.schemas.bibus._3.PropEnum;import com.cognos.developer.schemas.bibus._3.QueryOptions;import com.cognos.developer.schemas.bibus._3.Sort;import com.ntrs.nform.Utils;import com.ntrs.nform.c8.C8SDK;import com.ntrs.nform.c8.ContentManagerService;
public class DatasourceList { public static void main(String[] args) {
String[] cognos; try { cognos = Utils.getCognosConfig(); Pattern p = Pattern.compile("http://((npc)(sdc))cog([a-z])"); Matcher m = p.matcher(cognos[0]);
String env = null; if (m.find()) { env = m.group(4); env = ("p".equals(env) ? "prod" : "u".equals(env) ? "uat" : "dev"); } else { throw new RuntimeException("Invalid URL " + cognos[0]); }
C8SDK c8 = new C8SDK(); c8.logon(cognos[0], cognos[1], cognos[2], cognos[3]); ContentManagerService cms = c8.getContentManagerService(); listDataSourcesAndConnections(cms); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
public static void listDataSourcesAndConnections( ContentManagerService cmService) throws Exception { PropEnum dataSourceProps[] = new PropEnum[] { PropEnum.defaultName, PropEnum.searchPath }; PropEnum dataConnectionProps[] = new PropEnum[] { PropEnum.defaultName, PropEnum.connectionString };
BaseClass[] dataSources = cmService.getContent( "CAMID(\":\")//dataSource", dataSourceProps, new Sort[] {}, new QueryOptions());
for (int i = 0; i < dataSources.length; i++) { System.out.println("\nData Source name: " + dataSources[i].getDefaultName().getValue()); BaseClass[] dataConnections = cmService.getContent(dataSources[i] .getSearchPath().getValue() + "//dataSourceConnection", dataConnectionProps, new Sort[] {}, new QueryOptions()); for (int j = 0; j < dataConnections.length; j++) { System.out.println("\tData Connection name: " + dataConnections[j].getDefaultName().getValue()); System.out.println("\tConnection string: " + ((DataSourceConnection) dataConnections[j]) .getConnectionString().getValue()); } } }}
Subscribe to:
Post Comments (Atom)

Thanks for your information, i am working on cognos , after taking cognos online training @ www.monstercourses.com
ReplyDelete