Change Catalog programmatically

33 views
Skip to first unread message

Gianpaolo Trotta

unread,
Jun 14, 2016, 7:32:16 AM6/14/16
to pivot4j-list
Hi. I have a problem.
I wanto to change catalog programmatically in order to use different catalogs language based.
I have 3 catalogs:
IT
EN
FR

In ViewHandler.java I write this lines of code in getCubes function:

if (cubeItems == null) 
{
FacesContext context = FacesContext.getCurrentInstance();

ResourceBundle bundle = context.getApplication().getResourceBundle(
context, "msg");

String defaultLabel = bundle.getString("message.cubeList.default");

this.cubeItems = new ArrayList<UISelectItem>();

UISelectItem defaultItem = new UISelectItem();
defaultItem.setItemLabel(defaultLabel);
defaultItem.setItemValue("");

cubeItems.add(defaultItem);

if (model != null) 
{
OlapDataSource dataSource = ((PivotModelImpl) model)
.getDataSource();

ManageCookie mc = new ManageCookie();
Schema schema = null;
List<Cube> cubes = null;
if(mc.getCookie("lang") != null)
{
OlapConnection conn = dataSource.getConnection();
System.out.println("DATABASE: " + conn.getDatabase());
System.out.println("CATALOG: " + conn.getCatalog());
System.out.println("SCHEMA: " + conn.getSchema());
conn.setDatabase("BAM-" + mc.getCookie("lang").getValue().toUpperCase());
conn.setCatalog("BAM-" + mc.getCookie("lang").getValue().toUpperCase());
conn.setSchema("BAM-" + mc.getCookie("lang").getValue().toUpperCase());
System.out.println("DATABASE: " + conn.getDatabase());
System.out.println("CATALOG: " + conn.getCatalog());
System.out.println("SCHEMA: " + conn.getSchema());
cubes = conn.getOlapSchema().getCubes();
}
else
{
schema = dataSource.getConnection().getOlapSchema();
cubes = schema.getCubes();
}

for (Cube cube : cubes) 
{
if (cube.isVisible()) 
{
UISelectItem item = new UISelectItem();
item.setItemLabel(cube.getCaption());
item.setItemValue(cube.getName());

cubeItems.add(item);
}
}
}
}

return cubeItems;

but set functions silently ignore this request.

In olap4j specification I have read that, maybe, the driver does not support catalogs,

Any suggestions?

Thanks in advance.

Gianpaolo Trotta

unread,
Jun 14, 2016, 9:22:54 AM6/14/16
to pivot4j-list
Ok I have a trick.
I split schema in 3 parts.
English, italian and french part ad I have translated all values of tag name.
For each cube I have inserted a tag description with value en, it, fr respectively.
Function getCubes is:

public List<UISelectItem> getCubes() throws SQLException 
{
if (cubeItems == null) 
{
FacesContext context = FacesContext.getCurrentInstance();

ResourceBundle bundle = context.getApplication().getResourceBundle(
context, "msg");

String defaultLabel = bundle.getString("message.cubeList.default");

this.cubeItems = new ArrayList<UISelectItem>();

UISelectItem defaultItem = new UISelectItem();
defaultItem.setItemLabel(defaultLabel);
defaultItem.setItemValue("");

cubeItems.add(defaultItem);

if (model != null) 
{
OlapDataSource dataSource = ((PivotModelImpl) model)
.getDataSource();
Schema schema = null;
List<Cube> cubes = null;
schema = dataSource.getConnection().getOlapSchema();
cubes = schema.getCubes();
ManageCookie mc = new ManageCookie();
for (Cube cube : cubes) 
{
if (cube.isVisible()) 
{
if(mc.getCookie("lang") != null)
{
System.out.println("CUBE DESCRIPTION: " + cube.getDescription());
if(mc.getCookie("lang").getValue().equals(cube.getDescription()))
{
UISelectItem item = new UISelectItem();
item.setItemLabel(cube.getCaption());
item.setItemValue(cube.getName());

cubeItems.add(item);
}
}
else
{
UISelectItem item = new UISelectItem();
item.setItemLabel(cube.getCaption());
item.setItemValue(cube.getName());

cubeItems.add(item);
}
}
}
}
}

return cubeItems;
}

Bye.
Reply all
Reply to author
Forward
0 new messages