use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testDeleteLogicalModel_removeReportingModelIfAnalysisModelDoesNotExist.
@Test
public void testDeleteLogicalModel_removeReportingModelIfAnalysisModelDoesNotExist() throws Exception {
doReturn(true).when(dswService).hasDataAccessPermission();
ModelerWorkspace workspace = mock(ModelerWorkspace.class);
when(workspace.getLogicalModel(ModelerPerspective.REPORTING)).thenReturn(reportingModel);
doReturn(workspace).when(dswService).createModelerWorkspace();
doCallRealMethod().when(dswService).deleteLogicalModel(DOMAIN_ID_2MODELS, MODEL_NAME);
assertTrue(dswService.deleteLogicalModel(DOMAIN_ID_2MODELS, MODEL_NAME));
verify(domainRepository).removeModel(DOMAIN_ID_2MODELS, LOGICAL_MODEL_ID_REPORTING);
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class SerializeServiceIT method testSerialize.
@Test
public void testSerialize() throws Exception {
if (ModelerMessagesHolder.getMessages() == null) {
ModelerMessagesHolder.setMessages(new SpoonModelerMessages());
}
try {
KettleEnvironment.init();
Props.init(Props.TYPE_PROPERTIES_EMPTY);
} catch (Exception e) {
// may already be initialized by another test
}
login("suzy", "", false);
String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
String path = solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + // $NON-NLS-1$ //$NON-NLS-2$
RepositoryFile.SEPARATOR;
String olapPath = null;
IApplicationContext appContext = PentahoSystem.getApplicationContext();
if (appContext != null) {
path = PentahoSystem.getApplicationContext().getSolutionPath(path);
olapPath = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$ //$NON-NLS-2$
"system" + RepositoryFile.SEPARATOR + "olap" + RepositoryFile.SEPARATOR);
}
// $NON-NLS-1$
File olap1 = new File(olapPath + "datasources.xml");
// $NON-NLS-1$
File olap2 = new File(olapPath + "tmp_datasources.xml");
FileUtils.copyFile(olap1, olap2);
Domain domain = generateModel();
ModelerService service = new ModelerService();
ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper());
model.setModelName("ORDERS");
model.setDomain(domain);
model.getWorkspaceHelper().populateDomain(model);
// $NON-NLS-1$
service.serializeModels(domain, "test_file");
Assert.assertEquals(domain.getLogicalModels().get(1).getProperty("MondrianCatalogRef"), model.getModelName());
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DatasourceResourceIT method testMondrianImportExport.
@Test
public void testMondrianImportExport() throws Exception {
final String domainName = "SalesData";
List<IMimeType> mimeTypeList = new ArrayList<IMimeType>();
mimeTypeList.add(new MimeType("Mondrian", "mondrian.xml"));
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("org.osjava.sj.root", "target/test-classes/solution1/system/simple-jndi");
File mondrian = new File("target/test-classes/dsw/testData/SalesData.mondrian.xml");
RepositoryFile repoMondrianFile = new RepositoryFile.Builder(mondrian.getName()).folder(false).hidden(false).build();
RepositoryFileImportBundle bundle1 = new RepositoryFileImportBundle.Builder().file(repoMondrianFile).charSet("UTF-8").input(new FileInputStream(mondrian)).mime("mondrian.xml").withParam("parameters", "Datasource=Pentaho;overwrite=true").withParam("domain-id", "SalesData").build();
MondrianImportHandler mondrianImportHandler = new MondrianImportHandler(mimeTypeList, PentahoSystem.get(IMondrianCatalogService.class));
mondrianImportHandler.importFile(bundle1);
try {
KettleEnvironment.init();
Props.init(Props.TYPE_PROPERTIES_EMPTY);
} catch (Exception e) {
// may already be initialized by another test
}
Domain domain = generateModel();
ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper());
model.setModelName("ORDERS");
model.setDomain(domain);
model.getWorkspaceHelper().populateDomain(model);
new ModelerService().serializeModels(domain, domainName);
final Response salesData = new DataSourceWizardResource().doGetDSWFilesAsDownload(domainName + ".xmi");
Assert.assertEquals(salesData.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertNotNull(salesData.getMetadata());
Assert.assertNotNull(salesData.getMetadata().getFirst("Content-Disposition"));
Assert.assertEquals(salesData.getMetadata().getFirst("Content-Disposition").getClass(), String.class);
Assert.assertTrue(((String) salesData.getMetadata().getFirst("Content-Disposition")).endsWith(domainName + ".zip\""));
File file = File.createTempFile(domainName, ".zip");
final FileOutputStream fileOutputStream = new FileOutputStream(file);
((StreamingOutput) salesData.getEntity()).write(fileOutputStream);
fileOutputStream.close();
final ZipFile zipFile = new ZipFile(file);
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
final ZipEntry zipEntry = entries.nextElement();
Assert.assertTrue(zipEntry.getName().equals(domainName + ".xmi") || zipEntry.getName().equals(domainName + ".mondrian.xml"));
}
zipFile.close();
file.delete();
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testCreateModelerWorkspace.
// should create new workspace without exception
@Test
public void testCreateModelerWorkspace() {
ModelerWorkspace workspace = dswService.createModelerWorkspace();
assertNotNull(workspace);
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DSWDatasourceServiceImpl method generateQueryDomain.
@Override
public QueryDatasourceSummary generateQueryDomain(String name, String query, DatabaseConnection connection, DatasourceDTO datasourceDTO) throws DatasourceServiceException {
ModelerWorkspace modelerWorkspace = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), getGeoContext());
ModelerService modelerService = createModelerService();
modelerWorkspace.setModelName(name);
try {
UtilHtmlSanitizer.getInstance().sanitizeConnectionParameters(connection);
executeQuery(UtilHtmlSanitizer.getInstance().safeEscapeHtml(datasourceDTO.getConnectionName()), query, "1");
Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(connection.getName(), query, 10, PentahoSessionHolder.getSession());
SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getEffectivePermittedUserList(securityEnabled), getPermittedRoleList(), getDefaultAcls(), (PentahoSessionHolder.getSession() != null) ? PentahoSessionHolder.getSession().getName() : null);
Domain domain = sqlModelGenerator.generate();
domain.getPhysicalModels().get(0).setId(connection.getName());
modelerWorkspace.setDomain(domain);
modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
modelerWorkspace.getWorkspaceHelper().autoModelRelationalFlat(modelerWorkspace);
modelerWorkspace.setModelName(datasourceDTO.getDatasourceName());
modelerWorkspace.getWorkspaceHelper().populateDomain(modelerWorkspace);
domain.getLogicalModels().get(0).setProperty("datasourceModel", serializeModelState(datasourceDTO));
domain.getLogicalModels().get(0).setProperty("DatasourceType", "SQL-DS");
QueryDatasourceSummary summary = new QueryDatasourceSummary();
prepareForSerializaton(domain);
modelerService.serializeModels(domain, modelerWorkspace.getModelName());
summary.setDomain(domain);
return summary;
} catch (SQLModelGeneratorException smge) {
logger.error(// $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
smge);
} catch (QueryValidationException e) {
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (ModelerException e) {
logger.error(// $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (SqlQueriesNotSupportedException e) {
// $NON-NLS-1$
throw new DatasourceServiceException(e.getLocalizedMessage(), e);
} catch (Exception e) {
logger.error(// $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
e);
}
}
Aggregations