MondrianImportHandler implements IPlatformImportHandler { public void importFile( IPlatformImportBundle bundle ) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException { boolean overwriteInRepossitory = bundle.overwriteInRepository(); boolean xmla = "false".equalsIgnoreCase( findParameterPropertyValue( bundle, ENABLE_XMLA ) ) ? false : true; final String domainId = (String) bundle.getProperty( DOMAIN_ID ); if ( domainId == null ) { throw new PlatformImportException( "Bundle missing required domain-id property" ); } try { InputStream is = bundle.getInputStream(); MondrianCatalog catalog = this.createCatalogObject( domainId, xmla, bundle ); IPentahoSession session = PentahoSessionHolder.getSession(); if ( mondrianRepositoryImporter instanceof IAclAwareMondrianCatalogService ) { RepositoryFileAcl acl = bundle.isApplyAclSettings() ? bundle.getAcl() : null; IAclAwareMondrianCatalogService aware = (IAclAwareMondrianCatalogService) mondrianRepositoryImporter; aware.addCatalog( is, catalog, overwriteInRepossitory, acl, session ); } else { mondrianRepositoryImporter.addCatalog( is, catalog, overwriteInRepossitory, session ); } } catch ( MondrianCatalogServiceException mse ) { int statusCode = convertExceptionToStatus( mse ); throw new PlatformImportException( mse.getMessage(), statusCode ); } catch ( Exception e ) { throw new PlatformImportException( e.getMessage(), PlatformImportException.PUBLISH_GENERAL_ERROR ); } } MondrianImportHandler( List<IMimeType> mimeTypes, final IMondrianCatalogService mondrianImporter ); void importFile( IPlatformImportBundle bundle ); @Override List<IMimeType> getMimeTypes();  }
@Test public void testImportFile() throws Exception { when( bundle.getProperty( eq( MondrianImportHandler.DOMAIN_ID ) ) ).thenReturn( MondrianImportHandler.DOMAIN_ID ); testImportFileBase(); }
@Test public void testImportFile_DoNotApplyAclSettings() throws Exception { when( bundle.getProperty( eq( MondrianImportHandler.DOMAIN_ID ) ) ).thenReturn( MondrianImportHandler.DOMAIN_ID ); when( bundle.isApplyAclSettings() ).thenReturn( false ); IAclAwareMondrianCatalogService aclImporter = mock( IAclAwareMondrianCatalogService.class ); MondrianImportHandler handler = new MondrianImportHandler( mimeTypes, aclImporter ); handler.importFile( bundle ); ArgumentCaptor<RepositoryFileAcl> captor = ArgumentCaptor.forClass( RepositoryFileAcl.class ); verify( aclImporter ).addCatalog( any( InputStream.class ), any( MondrianCatalog.class ), anyBoolean(), captor.capture(), any( IPentahoSession.class ) ); assertNull( captor.getValue() ); }
@Test public void testImportFile_applyAclSettings() throws Exception { RepositoryFileAcl acl = mock( RepositoryFileAcl.class ); when( bundle.getProperty( eq( MondrianImportHandler.DOMAIN_ID ) ) ).thenReturn( MondrianImportHandler.DOMAIN_ID ); when( bundle.isApplyAclSettings() ).thenReturn( true ); when( bundle.getAcl() ).thenReturn( acl ); IAclAwareMondrianCatalogService aclImporter = mock( IAclAwareMondrianCatalogService.class ); MondrianImportHandler handler = new MondrianImportHandler( mimeTypes, aclImporter ); handler.importFile( bundle ); ArgumentCaptor<RepositoryFileAcl> captor = ArgumentCaptor.forClass( RepositoryFileAcl.class ); verify( aclImporter ).addCatalog( any( InputStream.class ), any( MondrianCatalog.class ), anyBoolean(), captor.capture(), any( IPentahoSession.class ) ); assertEquals( acl, captor.getValue() ); }