private InputStream StripDswFromStream( InputStream inputStream ) throws Exception {
// Check if this is valid xml
InputStream inputStream2 = null;
String xmi = null;
XmiParser xmiParser = new XmiParser();
try {
byte[] is = IOUtils.toByteArray( inputStream );
xmi = new String( is, "UTF-8" );
// now, try to see if the xmi can be parsed (ie, check if it's valid xmi)
Domain domain = xmiParser.parseXmi( new java.io.ByteArrayInputStream( is ) );
boolean changed = false;
if ( domain.getLogicalModels().size() > 1 ) {
Iterator<LogicalModel> iterator = domain.getLogicalModels().iterator();
while ( iterator.hasNext() ) {
LogicalModel logicalModel = iterator.next();
Object property = logicalModel.getProperty( DSW_SOURCE_PROPERTY ); //$NON-NLS-1$
if ( property != null ) {
// This metadata file came from a DataSourceWizard, it may have embedded mondrian schema
// that would incorrectly inform the system that there is mondrian schema attached. By
// definition we only want to import the metadata portion.
if ( logicalModel.getProperty( logicalModel.PROPERTY_OLAP_DIMS ) != null ) {
// This logical model is an Olap model that needs to be removed from metadata
iterator.remove();
} else {
// Remove properties that make this a DSW
logicalModel.removeChildProperty( DSW_SOURCE_PROPERTY );
logicalModel.removeChildProperty( "AGILE_BI_VERSION" );
}
changed = true;
}
}
if ( changed ) {
// The model was modified, regenerate the xml
xmi = xmiParser.generateXmi( domain );
}
}
// xmi is valid. Create a new inputstream for the actual import action.
inputStream2 = new java.io.ByteArrayInputStream( xmi.getBytes( "UTF-8" ) );