The example provided in this document is provided “as-is” to the user and assumes that the user:
PREREQUISITES:
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:
Note:
More elaborate programs will require additional library files and are out of the scope of this document.
The following code snippet will execute a Report Services Document, loop through the elements in the group-by for all layouts.
public static void loopRWDPDF() throws Exception {
//Create connection with the Intelligence Server
RWSource rwSource = factory.getRWSource();
WebObjectSource objsrc=factory.getObjectSource();
RWInstance rwi = rwSource.getNewInstance("595971B341E1D90B5FA16B85AED18FFF", EnumRWExecutionModes.RW_MODE_PDF);
//Make sure execution has finished in the Intelligence Server by checking the status
while (rwi.pollStatus() != 1) Thread.sleep(2000);
try{
RWDefinition def = rwi.getDefinition();
RWManipulation rwMan = rwi.getRWManipulator();
String key = null;
rwi.getData();
System.out.println("Layout Count: "+def.getLayoutCount());
RWLayoutSectionDef lsd;
WebFolder folder = (WebFolder)objSrc.getObject("9C78655B4C8B5DE816923C91FC7E53D1", EnumDSSXMLObjectTypes.DssXmlTypeFolder);
folder.populate();
RWInstance newInst = null;
//loop through layouts
for (int j=0;j<def.getLayoutCount();j++){
lsd = def.getLayout(j);
System.out.println("Layout: " + lsd.getName());
rwi = rwMan.setCurrentLayout(j, true);
newInst = rwMan.applyChanges();
newInst.pollStatus();
//get new instance
//save layout changes to document
System.out.println(newInst.getDefinition().getCurrentLayout().getName());
newInst.setSaveAsFlags(EnumDSSXMLDocSaveAsFlags.DssXmlDocSaveAsOverwrite);
newInst.saveAs(folder,def.getName());
System.out.println("New: "+newInst.getDefinition().getGroupBys().size());
newInst.pollStatus();
RWData newData = newInst.getData(); //call to execute to populate new instance
RWDefinition newDef = newInst.getDefinition();
System.out.println("newDef size: "+ newDef.getGroupBys().size()); //group by list
for (int i=0;i<newDef.getGroupBys().size();i++){
RWGroupBy gb = newDef.getGroupBys().get(i);
if(gb.getLevel() == EnumRWGroupByLevels.RWLEVEL_GROUP_START){ //get groupby
RWGroupByUnit gbu = gb.getUnit();
RWGroupByElements elem = gbu.getElements(); //grouby elements
key = gb.getKey();
System.out.println("Element Size: "+ elem.size());
for (int x=0;x<elem.size();x++){
System.out.println("GroupBy Elements:" + elem.get(x).getDisplayName());
}
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}