Package org.pentaho.platform.plugin.services.importexport

Examples of org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger


                                @FormDataParam ( "applyAclPermissions" ) String applyAclPermission,
                                @FormDataParam ( "retainOwnership" ) String retainOwnership, @FormDataParam ( "charSet" ) String pCharSet,
                                @FormDataParam ( "logLevel" ) String logLevel, @FormDataParam ( "fileUpload" ) FormDataContentDisposition fileInfo,
                                @FormDataParam ( "fileNameOverride" ) String fileNameOverride ) {
   
    IRepositoryImportLogger importLogger = null;
    ByteArrayOutputStream importLoggerStream = new ByteArrayOutputStream();
    boolean logJobStarted = false;

    String charSet = pCharSet == null ? DEFAULT_CHAR_SET : pCharSet;

    try {
      validateAccess();

      boolean overwriteFileFlag = ( "false".equals( overwriteFile ) ? false : true );
      boolean overwriteAclSettingsFlag = ( "true".equals( overwriteAclPermissions ) ? true : false );
      boolean applyAclSettingsFlag = ( "true".equals( applyAclPermission ) ? true : false );
      boolean retainOwnershipFlag = ( "true".equals( retainOwnership ) ? true : false );

      Level level = Level.toLevel( logLevel );
      ImportSession.getSession().setAclProperties( applyAclSettingsFlag, retainOwnershipFlag, overwriteAclSettingsFlag );

      //The fileNameOverride was added because the formDataContentDispositionfile object cannot reliable
      //contain non US-ASCII characters.  See RFC283 section 2.3 for details
      String fileName = fileNameOverride != null ? fileNameOverride : fileInfo.getFileName();

      RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
      bundleBuilder.input( fileIS );
      bundleBuilder.charSet( charSet );
      bundleBuilder.hidden( false );
      bundleBuilder.path( uploadDir );
      bundleBuilder.overwriteFile( overwriteFileFlag );
      bundleBuilder.applyAclSettings( applyAclSettingsFlag );
      bundleBuilder.overwriteAclSettings( overwriteAclSettingsFlag );
      bundleBuilder.retainOwnership( retainOwnershipFlag );
      bundleBuilder.name( fileName );
      IPlatformImportBundle bundle = bundleBuilder.build();

      IPlatformImportMimeResolver mimeResolver = PentahoSystem.get( IPlatformImportMimeResolver.class );
      String mimeTypeFromFile = mimeResolver.resolveMimeForFileName( fileName );
      if ( mimeTypeFromFile == null ) {
        return Response.ok( "INVALID_MIME_TYPE", MediaType.TEXT_HTML ).build();
      }
      bundleBuilder.mime( mimeTypeFromFile );

      IPlatformImporter importer = PentahoSystem.get( IPlatformImporter.class );
      importLogger = importer.getRepositoryImportLogger();

      final String mimeType =
          bundle.getMimeType() != null ? bundle.getMimeType() : mimeResolver.resolveMimeForBundle( bundle );
      if ( mimeType == null ) {
        return Response.ok( "INVALID_MIME_TYPE", MediaType.TEXT_HTML ).build();
      }

      logJobStarted = true;
      importLogger.startJob( importLoggerStream, uploadDir, level );
      importer.importFile( bundle );

      // Flush the Mondrian cache to show imported data-sources.
      IMondrianCatalogService mondrianCatalogService =
          PentahoSystem.get( IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder
              .getSession() );
      mondrianCatalogService.reInit( PentahoSessionHolder.getSession() );

      // Flush the IOlapService
      IOlapService olapService =
          PentahoSystem.get( IOlapService.class, "IOlapService", PentahoSessionHolder.getSession() ); //$NON-NLS-1$
      olapService.flushAll( PentahoSessionHolder.getSession() );

    } catch ( PentahoAccessControlException e ) {
      return Response.serverError().entity( e.toString() ).build();
    } catch ( Exception e ) {
      return Response.serverError().entity( e.toString() ).build();
    } finally {
      if ( logJobStarted == true ) {
        importLogger.endJob();
      }
    }
    String responseBody = null;
    try {
      responseBody = importLoggerStream.toString( charSet );
View Full Code Here


    final File reports = mock( File.class );
    String reportsName = "reports.zip";
    when( reports.getName() ).thenReturn( reportsName );
    when( reports.getPath() ).thenReturn( "/root/path/" + reportsName );
    when( directory.listFiles( ZIPS_FILTER ) ).thenReturn( new File[] { jobs, reports } );
    IRepositoryImportLogger logger = mock( IRepositoryImportLogger.class );
    when( importer.getRepositoryImportLogger() ).thenReturn( logger );
    loader.loadAll( directory, ZIPS_FILTER );
    verify( importer ).importFile( argThat( bundleMatcher( jobsName, inputStream ) ) );
    verify( jobs ).renameTo( argThat( fileMatcher( jobs ) ) );
    verify( importer ).importFile( argThat( bundleMatcher( reportsName, inputStream ) ) );
View Full Code Here

    when( reports.getName() ).thenReturn( reportsName );
    when( reports.getPath() ).thenReturn( "/root/path/" + reportsName );
    when( directory.listFiles( ZIPS_FILTER ) ).thenReturn( new File[] { jobs, reports } );
    Exception exception = new RuntimeException( "exception thrown on purpose from testWillContinueToLoadOnException" );
    doThrow( exception ).when( importer ).importFile( argThat( bundleMatcher( jobsName, inputStream ) ) );
    IRepositoryImportLogger logger = mock( IRepositoryImportLogger.class );
    when( importer.getRepositoryImportLogger() ).thenReturn( logger );
    loader.loadAll( directory, ZIPS_FILTER );
    verify( importer ).importFile( argThat( bundleMatcher( jobsName, inputStream ) ) );
    verify( importer ).importFile( argThat( bundleMatcher( reportsName, inputStream ) ) );
    verify( jobs ).renameTo( argThat( fileMatcher( jobs ) ) );
View Full Code Here

    MicroPlatform microPlatform = new MicroPlatform();
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    microPlatform.defineInstance( IPlatformImportMimeResolver.class, nameResolver );

    // mock logger to prevent npe
    IRepositoryImportLogger importLogger = new Log4JRepositoryImportLogger();

    PentahoPlatformImporter importer =
        new PentahoPlatformImporter( handlers, new DefaultRepositoryContentConverterHandler(
            new HashMap<String, Converter>() ) );
View Full Code Here

    MicroPlatform microPlatform = new MicroPlatform();
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    microPlatform.defineInstance( IPlatformImportMimeResolver.class, nameResolver );

    // mock logger to prevent npe
    IRepositoryImportLogger importLogger = new Log4JRepositoryImportLogger();

    PentahoPlatformImporter importer =
        new PentahoPlatformImporter( handlers, new DefaultRepositoryContentConverterHandler(
            new HashMap<String, Converter>() ) );
View Full Code Here

TOP

Related Classes of org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.