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);
}
}
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();
}
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);
}
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);
}
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;
}
Aggregations