use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class DataSourceWizardService method createMondrianDswBundle.
/**
* Generate a mondrian schema from the model and create the appropriate import bundle
* @param domain domain with olap model
* @return import bundle
* @throws DatasourceServiceException
* @throws Exception If schema generation fails
*/
protected IPlatformImportBundle createMondrianDswBundle(Domain domain, RepositoryFileAclDto acl) throws DatasourceServiceException, DswPublishValidationException, IOException {
final String analysisDomainId = toAnalysisDomainId(domain.getId());
final String dataSource = ModelerService.getMondrianDatasource(domain);
// get olap logical model
final String locale = Locale.getDefault().toString();
ModelerWorkspace workspace = new ModelerWorkspace(new ModelerWorkspaceHelper(locale), dswService.getGeoContext());
workspace.setModelName(analysisDomainId);
workspace.setDomain(domain);
LogicalModel olapModel = workspace.getLogicalModel(ModelerPerspective.ANALYSIS);
if (olapModel == null) {
throw new IllegalArgumentException("No analysis model in xmi.");
}
// reference schema in xmi
olapModel.setProperty(MONDRIAN_CATALOG_REF, analysisDomainId);
// generate schema
MondrianModelExporter exporter = new MondrianModelExporter(olapModel, locale);
exporter.updateModelToNewDomainName(analysisDomainId);
String mondrianSchema = null;
try {
mondrianSchema = exporter.createMondrianModelXML();
} catch (Exception e) {
throw new DswPublishValidationException(Type.INVALID_XMI, e.getMessage());
}
// create bundle
final RepositoryFileImportBundle.Builder builder = new RepositoryFileImportBundle.Builder().input(IOUtils.toInputStream(mondrianSchema, ENCODING)).name(MONDRIAN_SCHEMA_NAME).charSet(ENCODING).overwriteFile(true).mime(MONDRIAN_MIME).withParam(IMPORT_DOMAIN_ID, analysisDomainId).withParam(MONDRIAN_CONNECTION_PARAM, "DataSource=" + dataSource);
if (acl != null) {
builder.acl(repositoryFileAclAdapter.unmarshal(acl)).applyAclSettings(true);
}
return builder.build();
}
use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class DatasourceService method isMetadataDatasource.
public static boolean isMetadataDatasource(Domain domain) {
if (domain == null) {
return false;
}
List<LogicalModel> logicalModelList = domain.getLogicalModels();
if (logicalModelList != null && logicalModelList.size() >= 1) {
for (LogicalModel logicalModel : logicalModelList) {
// keep this check for backwards compatibility for now
// $NON-NLS-1$
Object property = logicalModel.getProperty("AGILE_BI_GENERATED_SCHEMA");
if (property != null) {
return false;
}
// moving forward any non metadata generated datasource should have this property
// $NON-NLS-1$
property = logicalModel.getProperty("WIZARD_GENERATED_SCHEMA");
if (property != null) {
return false;
}
}
return true;
} else {
return true;
}
}
use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class CsvDatasourceServiceImpl method prepareForSerialization.
protected void prepareForSerialization(Domain domain) throws IOException {
/*
* This method is responsible for cleaning up legacy information when
* changing datasource types and also manages CSV files for CSV based
* datasources.
*/
String relativePath = PentahoSystem.getSystemSetting("file-upload-defaults/relative-path", // $NON-NLS-1$
String.valueOf(FileUtils.DEFAULT_RELATIVE_UPLOAD_FILE_PATH));
String path = PentahoSystem.getApplicationContext().getSolutionPath(relativePath);
String TMP_FILE_PATH = File.separatorChar + "system" + File.separatorChar + File.separatorChar + "tmp" + File.separatorChar;
String sysTmpDir = PentahoSystem.getApplicationContext().getSolutionPath(TMP_FILE_PATH);
LogicalModel logicalModel = domain.getLogicalModels().get(0);
// $NON-NLS-1$
String modelState = (String) logicalModel.getProperty("datasourceModel");
if (modelState != null) {
XStream xs = new XStream();
DatasourceDTO datasource = (DatasourceDTO) xs.fromXML(modelState);
CsvFileInfo csvFileInfo = datasource.getCsvModelInfo().getFileInfo();
String tmpFileName = csvFileInfo.getTmpFilename();
String csvFileName = csvFileInfo.getFilename();
File tmpFile = new File(sysTmpDir + File.separatorChar + tmpFileName);
// Move CSV temporary file to final destination.
if (tmpFile.exists()) {
File csvFile = new File(path + File.separatorChar + csvFileName);
org.apache.commons.io.FileUtils.copyFile(tmpFile, csvFile);
}
// Cleanup logic when updating from SQL datasource to CSV
// datasource.
datasource.setQuery(null);
// Update datasourceModel with the new modelState
modelState = xs.toXML(datasource);
logicalModel.setProperty("datasourceModel", modelState);
}
}
use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class DSWDatasourceServiceImpl method getLogicalModels.
public List<LogicalModelSummary> getLogicalModels(String context) throws DatasourceServiceException {
if (!hasDataAccessViewPermission()) {
// $NON-NLS-1$
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
}
List<LogicalModelSummary> logicalModelSummaries = new ArrayList<LogicalModelSummary>();
for (String domainId : getMetadataDomainRepository().getDomainIds()) {
Domain domain;
try {
domain = getMetadataDomainRepository().getDomain(domainId);
} catch (Exception e) {
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0022_UNABLE_TO_PROCESS_LOGICAL_MODEL", domainId), e);
continue;
}
String locale = LocaleHelper.getLocale().toString();
String[] locales = new String[domain.getLocales().size()];
for (int i = 0; i < domain.getLocales().size(); i++) {
locales[i] = domain.getLocales().get(i).getCode();
}
locale = LocaleHelper.getClosestLocale(locale, locales);
for (LogicalModel model : domain.getLogicalModels()) {
String vis = (String) model.getProperty(LM_PROP_VISIBLE);
if (vis != null) {
String[] visibleContexts = vis.split(",");
boolean visibleToContext = false;
for (String c : visibleContexts) {
if (StringUtils.isNotEmpty(c.trim()) && c.trim().equals(context)) {
visibleToContext = true;
break;
}
}
if (!visibleToContext) {
continue;
}
}
logicalModelSummaries.add(new LogicalModelSummary(domainId, model.getId(), model.getName(locale)));
}
}
return logicalModelSummaries;
}
use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class DebugModelerService method serializeModels.
public String serializeModels(Domain domain, String name) throws Exception {
String domainId;
PentahoSystemHelper.init();
initKettle();
try {
DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), datasourceService.getGeoContext());
model.setModelName(name);
model.setDomain(domain);
String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
// $NON-NLS-1$ //$NON-NLS-2$
String metadataLocation = "resources" + RepositoryFile.SEPARATOR + "metadata";
String path = solutionStorage + RepositoryFile.SEPARATOR + metadataLocation + RepositoryFile.SEPARATOR;
// $NON-NLS-1$
domainId = path + name + ".xmi";
IApplicationContext appContext = PentahoSystem.getApplicationContext();
if (appContext != null) {
path = PentahoSystem.getApplicationContext().getSolutionPath(path);
}
File pathDir = new File(path);
if (!pathDir.exists()) {
pathDir.mkdirs();
}
IPentahoSession session = getSession();
// Keep a reference to the mondrian catalog
model.getWorkspaceHelper().populateDomain(model);
LogicalModel lModel = domain.getLogicalModels().get(0);
String catName = lModel.getName(LocalizedString.DEFAULT_LOCALE);
// $NON-NLS-1$
lModel.setProperty("MondrianCatalogRef", catName);
// Serialize domain to xmi.
/*
DISABLED DUE TO USE OF OLD API
String base = PentahoSystem.getApplicationContext().getSolutionRootPath();
String parentPath = ActionInfo.buildSolutionPath(solutionStorage, metadataLocation, ""); //$NON-NLS-1$
int status = repository.publish(base, '/' + parentPath, name + ".xmi", reportXML.getBytes("UTF-8"),
true); //$NON-NLS-1$ //$NON-NLS-2$
if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
throw new RuntimeException("Unable to save to repository. Status: " + status); //$NON-NLS-1$
}
// Serialize domain to olap schema.
lModel = domain.getLogicalModels().get(1);
MondrianModelExporter exporter = new MondrianModelExporter(lModel, LocalizedString.DEFAULT_LOCALE);
String mondrianSchema = exporter.createMondrianModelXML();
Document schemaDoc = DocumentHelper.parseText(mondrianSchema);
byte[] schemaBytes = schemaDoc.asXML().getBytes("UTF-8"); //$NON-NLS-1$
status = repository.publish(base, '/' + parentPath, name + ".mondrian.xml", schemaBytes, true); //$NON-NLS-1$
if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
throw new RuntimeException("Unable to save to repository. Status: " + status); //$NON-NLS-1$
}
// Refresh Metadata
PentahoSystem.publish(session, MetadataPublisher.class.getName());
*/
// Write this catalog to the default Pentaho DataSource and refresh the cache.
// $NON-NLS-1$
File file = new File(path + name + ".mondrian.xml");
// Need to find a better way to get the connection name instead of using the Id.
String catConnectStr = "Provider=mondrian;DataSource=\"" + ((SqlPhysicalModel) domain.getPhysicalModels().get(0)).getId() + // $NON-NLS-1$
"\"";
String catDef = // $NON-NLS-1$
"solution:" + solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + RepositoryFile.SEPARATOR + file.getName();
addCatalog(catName, catConnectStr, catDef, session);
} catch (Exception e) {
getLogger().error(e);
throw e;
}
return domainId;
}
Aggregations