use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
SqlDataSource dataSource = new SqlDataSource();
dataSource.setDatabaseName(CONNECTION_NAME);
SqlPhysicalTable sqlTable = new SqlPhysicalTable();
sqlTable.setTargetTable(VALID_QUERY);
SqlPhysicalModel sqlModel = new SqlPhysicalModel();
sqlModel.addPhysicalTable(sqlTable);
sqlModel.setDatasource(dataSource);
analysisModel = new LogicalModel();
analysisModel.setId(LOGICAL_MODEL_ID_ANALYSIS);
analysisModel.setProperty(DSWDatasourceServiceImpl.LM_PROP_VISIBLE, LOGICAL_MODEL_CONTEXTNAME);
reportingModel = new LogicalModel();
reportingModel.setId(LOGICAL_MODEL_ID_REPORTING);
domain2Models = new Domain();
domain2Models.setId(DOMAIN_ID_2MODELS);
domain2Models.addLogicalModel(analysisModel);
domain2Models.addLogicalModel(reportingModel);
domain2Models.setLocales(Arrays.asList(new LocaleType("en_US", "Test locale")));
domain2Models.addPhysicalModel(sqlModel);
Set<String> domains = new TreeSet<String>();
domains.add(DOMAIN_ID_2MODELS);
doReturn(domain2Models).when(domainRepository).getDomain(DOMAIN_ID_2MODELS);
doReturn(domains).when(domainRepository).getDomainIds();
doAnswer(new Answer<Object>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
final String modelId = (String) invocation.getArguments()[1];
final LogicalModel modelToRemove = domain2Models.findLogicalModel(modelId);
domain2Models.getLogicalModels().remove(modelToRemove);
return null;
}
}).when(domainRepository).removeModel(anyString(), anyString());
workspace2Models = mock(ModelerWorkspace.class);
when(workspace2Models.getLogicalModel(ModelerPerspective.ANALYSIS)).thenReturn(analysisModel);
when(workspace2Models.getLogicalModel(ModelerPerspective.REPORTING)).thenReturn(reportingModel);
dswService = spy(new DSWDatasourceServiceImpl(mock(ConnectionServiceImpl.class)));
doNothing().when(dswService).checkSqlQueriesSupported(anyString());
dswService.setMetadataDomainRepository(domainRepository);
Object[][] coumnHeaders = new Object[][] { columns };
SQLMetaData metadata = mock(SQLMetaData.class);
when(metadata.getColumnHeaders()).thenReturn(coumnHeaders);
when(metadata.getJDBCColumnTypes()).thenReturn(columnTypes);
IPentahoResultSet resultSet = mock(IPentahoResultSet.class);
when(resultSet.getMetaData()).thenReturn(metadata);
doReturn(resultSet).when(sqlConnection).executeQuery(matches("(.*" + VALID_QUERY + ".*)"));
when(sqlConnection.executeQuery(matches("(.*" + QUERY_COLUMN_ALREADY_EXIST + ".*)"))).thenThrow(new SQLException("Reason", "S0021", 21));
doReturn(nativeConnection).when(sqlConnection).getNativeConnection();
MondrianCatalog catalog = mock(MondrianCatalog.class);
doReturn(catalog).when(mondrianService).getCatalog(anyString(), any(IPentahoSession.class));
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IMondrianCatalogService.class)) {
return mondrianService;
}
if (invocation.getArguments()[0].equals(IPentahoConnection.class)) {
return sqlConnection;
}
if (invocation.getArguments()[0].equals(IMetadataDomainRepository.class)) {
return domainRepository;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
IPentahoSession pentahoSessionMock = mock(IPentahoSession.class);
when(pentahoSessionMock.getName()).thenReturn("sessionName");
PentahoSessionHolder.setSession(pentahoSessionMock);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.
the class DatasourceResource method getAnalysisDatasourceInfo.
/**
* Get the data source wizard info (parameters) for a specific data source wizard id
*
* @param dswId
* String id for a data source wizard
*
* @return Response containing the parameter list
*/
@GET
@Path("/{catalogId : .+}/getAnalysisDatasourceInfo")
@Produces(WILDCARD)
@Facet(name = "Unsupported")
public Response getAnalysisDatasourceInfo(@PathParam("catalogId") String catalogId) {
IMondrianCatalogService mondrianCatalogService = PentahoSystem.get(IMondrianCatalogService.class, PentahoSessionHolder.getSession());
MondrianCatalog catalog = mondrianCatalogService.getCatalog(catalogId, PentahoSessionHolder.getSession());
if (catalog == null) {
logger.warn("Catalog " + catalogId + " doesn't exist");
return Response.status(Response.Status.BAD_REQUEST).build();
}
// dataSourceInfo can contain XML-escaped characters
String parameters = prepareDataSourceInfo(catalog.getDataSourceInfo());
// after preparation, parameters have escaped only quotes
return Response.ok().entity(parameters).build();
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.
the class ModelerService method serializeModels.
public String serializeModels(final Domain domain, final String name, final boolean doOlap) throws Exception {
String domainId = null;
initKettle();
if (dataAccessPermHandler.hasDataAccessPermission(PentahoSessionHolder.getSession())) {
SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
if (datasourceService == null) {
datasourceService = new DSWDatasourceServiceImpl();
}
ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), datasourceService.getGeoContext());
model.setModelName(name);
model.setDomain(domain);
if (name.endsWith(".xmi")) {
domain.setId(name);
} else {
domain.setId(name + ".xmi");
}
LogicalModel lModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (lModel == null) {
lModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
lModel.setProperty("AGILE_BI_GENERATED_SCHEMA", "TRUE");
lModel.setProperty("WIZARD_GENERATED_SCHEMA", "TRUE");
String catName = lModel.getName(Locale.getDefault().toString());
// strip off the _olap suffix for the catalog ref
catName = catName.replace(BaseModelerWorkspaceHelper.OLAP_SUFFIX, "");
if (doOlap) {
// $NON-NLS-1$
lModel.setProperty("MondrianCatalogRef", catName);
}
// Stores metadata into JCR.
IMetadataDomainRepository metadataDomainRep = PentahoSystem.get(IMetadataDomainRepository.class);
if (metadataDomainRep != null) {
metadataDomainRep.storeDomain(model.getDomain(), true);
}
// Serialize domain to olap schema.
if (doOlap) {
MondrianModelExporter exporter = new MondrianModelExporter(lModel, Locale.getDefault().toString());
String mondrianSchema = exporter.createMondrianModelXML();
IPentahoSession session = PentahoSessionHolder.getSession();
if (session != null) {
// first remove the existing schema, including any
// model annotations which may have been previously applied
IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", session);
// try to get the current catalog
MondrianCatalog currentCatalog = mondrianCatalogService.getCatalog(catName, session);
// if current catalog exists, remove it
if (currentCatalog != null) {
mondrianCatalogService.removeCatalog(catName, session);
}
session.setAttribute("MONDRIAN_SCHEMA_XML_CONTENT", mondrianSchema);
// $NON-NLS-1$
String catConnectStr = "Provider=mondrian;DataSource=\"" + getMondrianDatasource(domain) + "\"";
addCatalog(catName, catConnectStr, session);
}
}
} catch (Exception e) {
logger.error(e);
throw e;
}
return null;
}
});
}
return domainId;
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.
the class AnalysisServiceTest method testGetAnalysisDatasourceIds.
@Test
public void testGetAnalysisDatasourceIds() throws Exception {
final MondrianCatalog foodmartCatalog = new MondrianCatalog("foodmart", "info", "file:///place", new MondrianSchema("foodmart", Collections.emptyList()));
final MondrianCatalog foodmartCatalog2 = new MondrianCatalog("foodmart2", "info", "file:///place", new MondrianSchema("foodmart2", Collections.emptyList()));
final List<MondrianCatalog> catalogs = Arrays.asList(foodmartCatalog, foodmartCatalog2);
doReturn(catalogs).when(catalogService).listCatalogs(any(IPentahoSession.class), eq(false));
final HashSet<String> domainIds = Sets.newHashSet("foodmart.xmi", "sample.xmi");
doReturn(domainIds).when(metadataRepository).getDomainIds();
final List<String> response = analysisService.getAnalysisDatasourceIds();
assertEquals(Collections.singletonList("foodmart2"), response);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.
the class AnalysisServiceTest method testImportingSchemaRemovesExistingAnnotationsByDefault.
@Test
public void testImportingSchemaRemovesExistingAnnotationsByDefault() throws Exception {
MondrianCatalog otherCatalog = new MondrianCatalog("other", "", "", null);
MondrianCatalog salesCatalog = new MondrianCatalog("sales", "", "", null);
when(catalogService.listCatalogs(any(IPentahoSession.class), eq(false))).thenReturn(Arrays.asList(otherCatalog, salesCatalog));
putMondrianSchemaWithSchemaFileName("stubFileName", "overwrite=true");
verify(importer).importFile(argThat(matchBundle(true, acl)));
verify(catalogService).removeCatalog(eq("sales"), any(IPentahoSession.class));
}
Aggregations