use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method addCatalog_WithAcl.
@Test
public void addCatalog_WithAcl() throws Exception {
initMondrianCatalogsCache();
MondrianCatalogHelper helperSpy = spy(helper);
IPentahoSession session = mock(IPentahoSession.class);
doNothing().when(helperSpy).init(session);
doReturn(Collections.<MondrianCatalog>emptyList()).when(helperSpy).getCatalogs(session);
doReturn(null).when(helperSpy).makeSchema(anyString());
MondrianCatalog cat = createTestCatalog();
RepositoryFileAcl acl = mock(RepositoryFileAcl.class);
IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), eq(acl));
doReturn(aclHelper).when(helperSpy).getAclHelper();
doReturn(null).when(helperSpy).makeSchema(CATALOG_NAME);
doReturn(true).when(helperSpy).catalogExists(any(MondrianCatalog.class), eq(session));
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, acl, session);
verify(aclHelper, times(1)).setAclFor(any(RepositoryFile.class), eq(acl));
doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
verify(aclHelper, times(2)).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method removeCatalog_WithAcl.
@Test
public void removeCatalog_WithAcl() throws Exception {
IPentahoSession session = mock(IPentahoSession.class);
helper = spy(helper);
doReturn(createTestCatalog()).when(helper).getCatalog(eq(CATALOG_NAME), eq(session));
doNothing().when(helper).reInit(eq(session));
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helper).getMondrianCatalogRepositoryHelper();
IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
when(aclHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
doReturn(aclHelper).when(helper).getAclHelper();
RepositoryFile file = mock(RepositoryFile.class);
when(file.getId()).thenReturn("1");
when(repo.getFile("/etc/mondrian/" + CATALOG_NAME)).thenReturn(file);
helper.removeCatalog(CATALOG_NAME, session);
verify(aclHelper).removeAclFor(any(RepositoryFile.class));
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project data-access by pentaho.
the class DataSourceWizardServiceTest method testDoGetDSWFilesAsDownload.
@Test
public void testDoGetDSWFilesAsDownload() throws Exception {
Map<String, InputStream> mockFileData = mock(Map.class);
ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
MondrianCatalogRepositoryHelper mockMondrianCatalogRepositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
LogicalModel mockLogicalModel = mock(LogicalModel.class);
String mockObject = "not null";
String dswId = "dswId";
doReturn(true).when(dataSourceWizardService).canManageACL();
doReturn(mockFileData).when(dataSourceWizardService).getMetadataFiles(dswId);
doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
doReturn(mockMondrianCatalogRepositoryHelper).when(dataSourceWizardService).createMondrianCatalogRepositoryHelper();
doNothing().when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId, mockFileData);
Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload("dswId");
assertEquals(mockFileData, response);
verify(dataSourceWizardService, times(1)).doGetDSWFilesAsDownload("dswId");
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper 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;
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project data-access by pentaho.
the class DataSourceWizardService method doGetDSWFilesAsDownload.
public Map<String, InputStream> doGetDSWFilesAsDownload(String dswId) throws PentahoAccessControlException {
if (!canManageACL()) {
throw new PentahoAccessControlException();
}
// First get the metadata files;
Map<String, InputStream> fileData = getMetadataFiles(dswId);
// Then get the corresponding mondrian files
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
MondrianCatalogRepositoryHelper helper = createMondrianCatalogRepositoryHelper();
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
fileData.putAll(helper.getModrianSchemaFiles(catalogRef));
parseMondrianSchemaNameWrapper(dswId, fileData);
}
return fileData;
}
Aggregations