Search in sources :

Example 1 with MetadataImportHandler

use of org.pentaho.platform.plugin.services.importer.MetadataImportHandler in project data-access by pentaho.

the class DatasourceResourceIT method testMetadataImportExport.

@Test
public void testMetadataImportExport() throws PlatformInitializationException, IOException, PlatformImportException {
    List<IMimeType> mimeTypeList = new ArrayList<IMimeType>();
    mimeTypeList.add(new MimeType("Metadata", ".xmi"));
    File metadata = new File("target/test-classes/dsw/testData/metadata.xmi");
    RepositoryFile repoMetadataFile = new RepositoryFile.Builder(metadata.getName()).folder(false).hidden(false).build();
    MetadataImportHandler metadataImportHandler = new MetadataImportHandler(mimeTypeList, (IPentahoMetadataDomainRepositoryImporter) PentahoSystem.get(IMetadataDomainRepository.class));
    RepositoryFileImportBundle bundle1 = new RepositoryFileImportBundle.Builder().file(repoMetadataFile).charSet("UTF-8").input(new FileInputStream(metadata)).mime(".xmi").withParam("domain-id", "SalesData").build();
    metadataImportHandler.importFile(bundle1);
    final Response salesData = new DataSourceWizardResource().doGetDSWFilesAsDownload("SalesData");
    Assert.assertEquals(salesData.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertNotNull(salesData.getMetadata());
    Assert.assertNotNull(salesData.getMetadata().getFirst("Content-Disposition"));
    Assert.assertEquals(salesData.getMetadata().getFirst("Content-Disposition").getClass(), String.class);
    Assert.assertTrue(((String) salesData.getMetadata().getFirst("Content-Disposition")).endsWith(".xmi\""));
}
Also used : MetadataImportHandler(org.pentaho.platform.plugin.services.importer.MetadataImportHandler) ArrayList(java.util.ArrayList) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) FileInputStream(java.io.FileInputStream) Response(javax.ws.rs.core.Response) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) DataSourceWizardResource(org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 MimeType (org.pentaho.platform.core.mimetype.MimeType)1 DataSourceWizardResource (org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource)1 MetadataImportHandler (org.pentaho.platform.plugin.services.importer.MetadataImportHandler)1 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)1