RepositoryImportResource { @POST @Consumes ( MediaType.MULTIPART_FORM_DATA ) @Produces ( MediaType.TEXT_HTML ) @Facet( name = "Unsupported" ) public Response doPostImport( @FormDataParam ( "importDir" ) String importDir, @FormDataParam ( "fileUpload" ) InputStream fileUpload, @FormDataParam ( "overwriteFile" ) String overwriteFile, @FormDataParam ( "overwriteAclPermissions" ) String overwriteAclPermissions, @FormDataParam ( "applyAclPermissions" ) String applyAclPermission, @FormDataParam ( "retainOwnership" ) String retainOwnership, @FormDataParam ( "charSet" ) String charSet, @FormDataParam ( "logLevel" ) String logLevel, @FormDataParam ( "fileUpload" ) FormDataContentDisposition fileInfo, @FormDataParam ( "fileNameOverride" ) String fileNameOverride ) { IRepositoryImportLogger importLogger = null; ByteArrayOutputStream importLoggerStream = new ByteArrayOutputStream(); boolean logJobStarted = false; if ( StringUtils.isBlank( charSet ) ) { charSet = DEFAULT_CHAR_SET; } try { validateImportAccess( importDir ); 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 ); if ( logLevel == null || logLevel.length() <= 0 ) { logLevel = "ERROR"; } FileService fileService = new FileService(); if ( !fileService.doCanAdminister() ) { applyAclSettingsFlag = false; retainOwnershipFlag = true; } Level level = Level.toLevel( logLevel ); ImportSession.getSession().setAclProperties( applyAclSettingsFlag, retainOwnershipFlag, overwriteAclSettingsFlag ); String fileName = fileNameOverride != null ? fileNameOverride : fileInfo.getFileName(); RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder(); bundleBuilder.input( fileUpload ); bundleBuilder.charSet( charSet ); bundleBuilder.path( importDir ); bundleBuilder.overwriteFile( overwriteFileFlag ); bundleBuilder.applyAclSettings( applyAclSettingsFlag ); bundleBuilder.overwriteAclSettings( overwriteAclSettingsFlag ); bundleBuilder.retainOwnership( retainOwnershipFlag ); bundleBuilder.name( fileName ); IPlatformImportBundle bundle = bundleBuilder.build(); IPlatformMimeResolver mimeResolver = PentahoSystem.get( IPlatformMimeResolver.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, importDir, level ); importer.importFile( bundle ); IMondrianCatalogService mondrianCatalogService = PentahoSystem.get( IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder .getSession() ); mondrianCatalogService.reInit( PentahoSessionHolder.getSession() ); } catch ( Exception e ) { return Response.serverError().entity( e.toString() ).build(); } finally { ImportSession.clearSession(); if ( logJobStarted == true ) { importLogger.endJob(); } } String responseBody; try { responseBody = importLoggerStream.toString( charSet ); } catch ( UnsupportedEncodingException e ) { LOGGER.error( "Encoding of response body is failed. (charSet=" + charSet + ")", e ); responseBody = importLoggerStream.toString(); } return Response.ok( responseBody, MediaType.TEXT_HTML ).build(); }  @POST @Consumes ( MediaType.MULTIPART_FORM_DATA ) @Produces ( MediaType.TEXT_HTML ) @Facet( name = "Unsupported" ) Response doPostImport( @FormDataParam ( "importDir" ) String importDir,
                                @FormDataParam ( "fileUpload" ) InputStream fileUpload,
                                @FormDataParam ( "overwriteFile" ) String overwriteFile,
                                @FormDataParam ( "overwriteAclPermissions" ) String overwriteAclPermissions,
                                @FormDataParam ( "applyAclPermissions" ) String applyAclPermission,
                                @FormDataParam ( "retainOwnership" ) String retainOwnership,
                                @FormDataParam ( "charSet" ) String charSet,
                                @FormDataParam ( "logLevel" ) String logLevel,
                                @FormDataParam ( "fileUpload" ) FormDataContentDisposition fileInfo,
                                @FormDataParam ( "fileNameOverride" ) String fileNameOverride );  }
@Test public void doPostImport() throws ParseException, PlatformImportException { RepositoryImportResource importResource = new RepositoryImportResource(); InputStream mockInputStream = mock( InputStream.class ); FormDataContentDisposition formDataContentDisposition = mock( FormDataContentDisposition.class ); when( policy.isAllowed( anyString() ) ).thenAnswer( new Answer<Boolean>() { @Override public Boolean answer( InvocationOnMock invocation ) throws Throwable { return true; } } ); importResource.doPostImport( IMPORT_DIR, mockInputStream, "true", "true", "true", "true", "UTF-8", "WARN", formDataContentDisposition, "" ); Assert.assertNull( ImportSession.getSession().getManifest() ); }