how to copy OdadataSourceHandle from one design report to another design report?

37 Views Asked by At

String targetRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report.getMergeRptTemplates().getTargetTemplate()+".rptdesign"; String attachRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report.getMergeRptTemplates() .getAttachTemplate()+".rptdesign";

    DesignConfig dConfig = new DesignConfig();
    IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
    IDesignEngine dEngine = factory.createDesignEngine(dConfig);
    SessionHandle session = dEngine.newSessionHandle(null);
    ReportDesignHandle targetRptDesignHandle = null;
    ReportDesignHandle attachRptDesignHandle = null;
    try {
        targetRptDesignHandle = session.openDesign(targetRptFile);
        attachRptDesignHandle = session.openDesign(attachRptFile);
    } catch (DesignFileException e) {
        e.printStackTrace();
    }


    OdaDataSourceHandle attachOdaDataSourceHandle = (OdaDataSourceHandle)attachRptDesignHandle.getAllDataSources()
            .get(0);
    targetRptDesignHandle.getAllDataSources().add(attachOdaDataSourceHandle);


    String newTargetRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report
            .getMergeRptTemplates().getTargetTemplate()+"-merge"+".rptdesign";

    try {
        targetRptDesignHandle.saveAs(newTargetRptFile);
        targetRptDesignHandle.close();
        attachRptDesignHandle.close();
        session.closeAll(true);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
1

There are 1 best solutions below

0
On

Never did this, but I remember a similar problem when I wanted to copy a JDBCDataSource. I worked around this by setting all the properties manually instead of trying to copy the whole DS.