Search in sources :

Example 11 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class MetadataImportHandlerIT method testNotPreserveDsw.

@Test
public void testNotPreserveDsw() throws Exception {
    final String domainId = "AModel";
    final InputStream fileIn = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/AModel.xmi"));
    try {
        final IPlatformImportBundle bundle = getMetadataImport(domainId, fileIn).build();
        context.checking(new Expectations() {

            {
                oneOf(metadataImporter).storeDomain(with(xmiInputStreamHasOlap(false)), with(equal(domainId)), with(equal(true)));
            }
        });
        importer.importFile(bundle);
        context.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(fileIn);
    }
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) Expectations(org.jmock.Expectations) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 12 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class MetadataImportHandlerIT method testDomainWithLocaleFiles.

@Test
public void testDomainWithLocaleFiles() throws Exception {
    final FileInputStream propIn = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/steel-wheels_en.properties"));
    final IPlatformImportBundle localizationBundle = new RepositoryFileImportBundle.Builder().input(propIn).charSet("UTF-8").hidden(false).name("steel-wheels_en.properties").build();
    final IPlatformImportBundle localizationBundle2 = new RepositoryFileImportBundle.Builder().input(propIn).charSet("UTF-8").hidden(false).name("steel-wheels_en_US.properties").build();
    final FileInputStream in = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/steel-wheels.xmi"));
    final IPlatformImportBundle bundle = new RepositoryFileImportBundle.Builder().input(in).charSet("UTF-8").hidden(false).overwriteFile(true).mime("text/xmi+xml").name("steel-wheels.xmi").comment("Test Metadata Import").withParam("domain-id", "steel-wheels").addChildBundle(localizationBundle).addChildBundle(localizationBundle2).build();
    context.checking(new Expectations() {

        {
            oneOf(metadataImporter).storeDomain(with(any(InputStream.class)), with(equal("steel-wheels")), with(equal(true)));
            atLeast(1).of(metadataImporter).addLocalizationFile("steel-wheels", "en", propIn, true);
            atLeast(1).of(metadataImporter).addLocalizationFile("steel-wheels", "en_US", propIn, true);
        }
    });
    importer.importFile(bundle);
    context.assertIsSatisfied();
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) Expectations(org.jmock.Expectations) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 13 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDswFromTemp.

@Test
public void testPublishDswFromTemp() throws Exception {
    InputStream metadataFile = getClass().getClassLoader().getResourceAsStream(TEST_XMI_FILE_PATH);
    boolean overwrite = true;
    boolean checkConnection = false;
    XmiParser mockXmiParser = mock(XmiParser.class);
    Domain mockDomain = mock(Domain.class);
    InputStream mockInputStream = mock(InputStream.class);
    IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
    IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwner("owner");
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(mockInputStream).when(dataSourceWizardService).toInputStreamWrapper(mockDomain, mockXmiParser);
    doReturn(mockMetadataBundle).when(dataSourceWizardService).createMetadataDswBundle(mockDomain, mockInputStream, overwrite, aclDto);
    doReturn(mockMondrianBundle).when(dataSourceWizardService).createMondrianDswBundle(mockDomain, aclDto);
    doReturn(mockIPlatformImporter).when(dataSourceWizardService).getIPlatformImporter();
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doReturn(metadataFile).when(dataSourceWizardService).createInputStreamFromFile(anyString());
    MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
    fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
    String list = "{\"xmiFileName\":\"" + XMI_TEMP_FILE_NAME + "\"}";
    String response = dataSourceWizardService.publishDswFromTemp(DOMAIN_ID, fileList, overwrite, checkConnection, aclDto);
    assertEquals(DOMAIN_ID + DataSourceWizardService.METADATA_EXT, response);
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) XmiParser(org.pentaho.metadata.util.XmiParser) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 14 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project data-access by pentaho.

the class MetadataServiceTest method fillServiceMock.

private void fillServiceMock(String domainId, InputStream metadataFile) throws Exception {
    FileResource mockFileResource = mock(FileResource.class);
    Response mockResponse = mock(Response.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPlatformImportBundle mockIPlatformImportBundle = mock(IPlatformImportBundle.class);
    RepositoryFileImportBundle.Builder mockRepositoryFileImportBundleBuilder = mock(RepositoryFileImportBundle.Builder.class);
    RepositoryFileImportBundle mockRepositoryFileImportBundle = mock(RepositoryFileImportBundle.class);
    ByteArrayInputStream mockByteArrayInputStream = mock(ByteArrayInputStream.class);
    doNothing().when(metadataService).accessValidation();
    doReturn(mockFileResource).when(metadataService).createNewFileResource();
    doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
    doReturn(null).when(mockResponse).getEntity();
    doReturn("\t\n/").when(metadataService).objectToString(null);
    doReturn(mockRepositoryFileImportBundleBuilder).when(metadataService).createNewRepositoryFileImportBundleBuilder(metadataFile, false, domainId, null);
    doReturn(UPLOAD_DIR).when(metadataService).internalGetUploadDir();
    doReturn(mockByteArrayInputStream).when(metadataService).createNewByteArrayInputStream(any(byte[].class));
    // doReturn( mockRepositoryFileImportBundle ).when( metadataService ).createNewRepositoryFileImportBundle(
    // mockByteArrayInputStream, "fileName", domainId );
    doReturn(mockRepositoryFileImportBundle).when(mockRepositoryFileImportBundleBuilder).build();
    doReturn(mockIPlatformImporter).when(metadataService).getImporter();
    doNothing().when(mockIPlatformImporter).importFile(mockIPlatformImportBundle);
    doReturn(mockIPentahoSession).when(metadataService).getSession();
    doNothing().when(metadataService).publish(mockIPentahoSession);
}
Also used : Response(javax.ws.rs.core.Response) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter)

Example 15 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project data-access by pentaho.

the class AnalysisService method createPlatformBundle.

/**
 * helper method to create the platform bundle used by the Jcr repository
 *
 * @param parameters
 * @param dataInputStream
 * @param catalogName
 * @param overWriteInRepository
 * @param fileName
 * @param xmlaEnabled
 * @param acl acl information for the data source. This parameter is optional.
 * @return IPlatformImportBundle
 */
private IPlatformImportBundle createPlatformBundle(String parameters, InputStream dataInputStream, String catalogName, boolean overWriteInRepository, String fileName, boolean xmlaEnabled, RepositoryFileAclDto acl) {
    byte[] bytes = null;
    try {
        bytes = IOUtils.toByteArray(dataInputStream);
        if (bytes.length == 0 && catalogName != null) {
            MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(PentahoSystem.get(IUnifiedRepository.class));
            Map<String, InputStream> fileData = helper.getModrianSchemaFiles(catalogName);
            dataInputStream = fileData.get("schema.xml");
            bytes = IOUtils.toByteArray(dataInputStream);
        }
    } catch (IOException e) {
        logger.error(e);
    }
    String datasource = getValue(parameters, "Datasource");
    String domainId = this.determineDomainCatalogName(parameters, catalogName, fileName, new ByteArrayInputStream(bytes));
    String sep = ";";
    if (StringUtils.isEmpty(parameters)) {
        parameters = "Provider=mondrian";
        parameters += sep + DATASOURCE_NAME + "=" + datasource;
        parameters += sep + ENABLE_XMLA + "=" + xmlaEnabled;
    }
    RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().input(new ByteArrayInputStream(bytes)).charSet(UTF_8).hidden(false).name(domainId).overwriteFile(overWriteInRepository).mime(MONDRIAN_MIME_TYPE).withParam(PARAMETERS, parameters).withParam(DOMAIN_ID, domainId);
    if (acl != null) {
        bundleBuilder.acl(repositoryFileAclAdapter.unmarshal(acl)).applyAclSettings(true);
    }
    bundleBuilder.withParam(ENABLE_XMLA, Boolean.toString(xmlaEnabled));
    IPlatformImportBundle bundle = bundleBuilder.build();
    return bundle;
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) IOException(java.io.IOException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)34 Test (org.junit.Test)21 InputStream (java.io.InputStream)15 FileInputStream (java.io.FileInputStream)14 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)13 File (java.io.File)12 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)8 ArrayList (java.util.ArrayList)7 Expectations (org.jmock.Expectations)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)5 Response (javax.ws.rs.core.Response)5 Matchers.anyString (org.mockito.Matchers.anyString)5 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)5 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)4 Domain (org.pentaho.metadata.model.Domain)4 XmiParser (org.pentaho.metadata.util.XmiParser)4