logger.info( "Saving File:" + cdeFilePath );
// 2. If not the CDE temp file, delete the temp file, if one exists
IRWAccess access = Utils.getSystemOrUserRWAccess( cdeFilePath );
// TODO:
boolean isPreview = cdeFilePath.indexOf( "_tmp.cdfde" ) >= 0;
if ( !isPreview ) {
String cdeTempFilePath = cdeFilePath.replace( ".cdfde", "_tmp.cdfde" );
access.deleteFile( cdeTempFilePath );
String cdaTempFilePath = cdeFilePath.replace( ".cdfde", "_tmp.cda" );
access.deleteFile( cdaTempFilePath );
String wcdfTempFilePath = cdeFilePath.replace( ".cdfde", "_tmp.wcdf" );
access.deleteFile( wcdfTempFilePath );
}
// 3. CDE
if ( !access.saveFile( cdeFilePath, new ByteArrayInputStream( safeGetEncodedBytes( cdfdeJsText ) ) ) ) {
throw new DashboardStructureException(
Messages.getString( "DashboardStructure.ERROR_006_SAVE_FILE_ADD_FAIL_EXCEPTION" ) );
}
// 3. CDA
CdaRenderer cdaRenderer = new CdaRenderer( cdfdeJsText );
String cdaFileName = cdeFilePath.replace( ".cdfde", ".cda" );
// Any data sources?
if ( cdaRenderer.isEmpty() ) {
access.deleteFile( cdaFileName );
} else {
// throws Exception ????
String cdaText = cdaRenderer.render();
if ( !access.saveFile( cdaFileName, new ByteArrayInputStream( safeGetEncodedBytes( cdaText ) ) ) ) {
throw new DashboardStructureException(
Messages.getString( "DashboardStructure.ERROR_006_SAVE_FILE_ADD_FAIL_EXCEPTION" ) );
}
}