use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class MetadataService method importMetadataDatasource.
public void importMetadataDatasource(String domainId, InputStream metadataFile, boolean overwrite, List<InputStream> localeFileStreams, List<String> localeFileNames, RepositoryFileAclDto acl) throws PentahoAccessControlException, PlatformImportException, Exception {
if (StringUtils.isEmpty(domainId)) {
throw new PlatformImportException(Messages.getString("MetadataDatasourceService.ERROR_005_DOMAIN_NAME_EMPTY"));
}
accessValidation();
FileResource fr = createNewFileResource();
Object reservedCharsObject = fr.doGetReservedChars().getEntity();
String reservedChars = objectToString(reservedCharsObject);
if (reservedChars != null && domainId.matches(".*[" + reservedChars.replaceAll("/", "") + "]+.*")) {
String msg = prohibitedSymbolMessage(domainId, fr);
throw new PlatformImportException(msg, PlatformImportException.PUBLISH_PROHIBITED_SYMBOLS_ERROR);
}
metadataFile = validateFileSize(metadataFile, domainId);
// domain ID comes with ".xmi" suffix when creating or editing domain
// (see ModelerService.serializeModels( Domain, String, boolean ) ),
// but when the user enters domain ID manually when importing metadata file,
// it will unlikely contain that suffix, so let's add it forcibly.
domainId = forceXmiSuffix(domainId);
RepositoryFileImportBundle.Builder bundleBuilder = createNewRepositoryFileImportBundleBuilder(metadataFile, overwrite, domainId, acl);
if (localeFileStreams != null) {
for (int i = 0; i < localeFileStreams.size(); i++) {
IPlatformImportBundle localizationBundle = createNewRepositoryFileImportBundle(localeFileStreams.get(i), localeFileNames.get(i), domainId);
bundleBuilder.addChildBundle(localizationBundle);
}
}
IPlatformImportBundle bundle = bundleBuilder.build();
IPlatformImporter importer = getImporter();
importer.importFile(bundle);
IPentahoSession pentahoSession = getSession();
publish(pentahoSession);
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class DatasourceResourceIT method testImportZipFile.
private void testImportZipFile(String filePath, final String expectedSchemaName, boolean annotated) throws Exception {
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
File f = new File(filePath);
when(schemaFileInfo.getFileName()).thenReturn(f.getName());
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
if (annotated) {
mockery.checking(new Expectations() {
{
exactly(2).of(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return true;
}
public void describeTo(Description description) {
description.appendText("bundle with zipped mondrian schema");
}
})));
}
});
} else {
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals(expectedSchemaName);
}
public void describeTo(Description description) {
description.appendText("bundle with zipped mondrian schema");
}
})));
}
});
}
AnalysisService service = new AnalysisService();
FileInputStream in = new FileInputStream(filePath);
try {
service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
mockery.assertIsSatisfied();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class DatasourceResourceIT method testImportFile.
private void testImportFile(String filePath, final String expectedSchemaName) throws Exception {
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
when(schemaFileInfo.getFileName()).thenReturn("stubFileName");
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals(expectedSchemaName) && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
}
public void describeTo(Description description) {
description.appendText("bundle with mondrian schema");
}
})));
}
});
AnalysisService service = new AnalysisService();
FileInputStream in = new FileInputStream(filePath);
try {
service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
mockery.assertIsSatisfied();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project pentaho-platform by pentaho.
the class FileService method systemRestore.
public void systemRestore(final InputStream fileUpload, String overwriteFile, String applyAclSettings, String overwriteAclSettings) throws PlatformImportException, SecurityException {
if (doCanAdminister()) {
boolean overwriteFileFlag = !"false".equals(overwriteFile);
boolean applyAclSettingsFlag = !"false".equals(applyAclSettings);
boolean overwriteAclSettingsFlag = "true".equals(overwriteAclSettings);
IRepositoryImportLogger importLogger = null;
Level level = Level.ERROR;
ByteArrayOutputStream importLoggerStream = new ByteArrayOutputStream();
String importDirectory = "/";
RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
bundleBuilder.input(fileUpload);
bundleBuilder.charSet("UTF-8");
bundleBuilder.hidden(RepositoryFile.HIDDEN_BY_DEFAULT);
bundleBuilder.schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT);
bundleBuilder.path(importDirectory);
bundleBuilder.overwriteFile(overwriteFileFlag);
bundleBuilder.name("SystemBackup.zip");
bundleBuilder.applyAclSettings(applyAclSettingsFlag);
bundleBuilder.overwriteAclSettings(overwriteAclSettingsFlag);
bundleBuilder.retainOwnership(true);
bundleBuilder.preserveDsw(true);
ImportSession.getSession().setAclProperties(applyAclSettingsFlag, true, overwriteAclSettingsFlag);
IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
importLogger = importer.getRepositoryImportLogger();
importLogger.startJob(importLoggerStream, importDirectory, level);
try {
importer.importFile(bundleBuilder.build());
} finally {
importLogger.endJob();
}
} else {
throw new SecurityException();
}
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class DatasourceResourceIT method testPublishDsw.
@Test
public void testPublishDsw() throws Exception {
DataSourceWizardResource service = new DataSourceWizardResource();
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.isPreserveDsw() && bundle.getProperty("domain-id").equals("AModel.xmi") && bundle.getMimeType().equals("text/xmi+xml");
}
public void describeTo(Description description) {
description.appendText("bundle with xmi");
}
})));
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals("AModel") && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
}
public void describeTo(Description description) {
description.appendText("bundle with mondrian schema");
}
})));
}
});
FileInputStream in = new FileInputStream(new File(new File("target/test-classes"), "SampleDataOlap.xmi"));
try {
Response resp = service.publishDsw("AModel.xmi", in, true, false, null);
Assert.assertEquals(Response.Status.Family.SUCCESSFUL, Response.Status.fromStatusCode(resp.getStatus()).getFamily());
mockery.assertIsSatisfied();
} finally {
IOUtils.closeQuietly(in);
}
}
Aggregations