use of org.pentaho.platform.api.engine.IApplicationContext 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;
}
use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class SolutionContextListener method contextInitialized.
public void contextInitialized(final ServletContextEvent event) {
context = event.getServletContext();
// $NON-NLS-1$
String encoding = getServerParameter("encoding");
if (encoding != null) {
LocaleHelper.setSystemEncoding(encoding);
}
// $NON-NLS-1$
String textDirection = getServerParameter("text-direction");
if (textDirection != null) {
LocaleHelper.setTextDirection(textDirection);
}
// $NON-NLS-1$
String localeLanguage = getServerParameter("locale-language");
// $NON-NLS-1$
String localeCountry = getServerParameter("locale-country");
boolean localeSet = false;
if (!StringUtils.isEmpty(localeLanguage) && !StringUtils.isEmpty(localeCountry)) {
Locale[] locales = Locale.getAvailableLocales();
if (locales != null) {
for (Locale element : locales) {
if (element.getLanguage().equals(localeLanguage) && element.getCountry().equals(localeCountry)) {
LocaleHelper.setLocale(element);
localeSet = true;
break;
}
}
}
}
if (!localeSet) {
// do this thread in the default locale
LocaleHelper.setLocale(Locale.getDefault());
}
LocaleHelper.setDefaultLocale(LocaleHelper.getLocale());
// log everything that goes on here
// $NON-NLS-1$
logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_INITIALIZING"));
// $NON-NLS-1$
logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_SERVLET_CONTEXT", context));
// $NON-NLS-1$
SolutionContextListener.contextPath = context.getRealPath("");
logger.info(// $NON-NLS-1$
Messages.getInstance().getString("SolutionContextListener.INFO_CONTEXT_PATH", SolutionContextListener.contextPath));
SolutionContextListener.solutionPath = PentahoHttpSessionHelper.getSolutionPath(context);
if (StringUtils.isEmpty(SolutionContextListener.solutionPath)) {
// $NON-NLS-1$
String errorMsg = Messages.getInstance().getErrorString("SolutionContextListener.ERROR_0001_NO_ROOT_PATH");
logger.error(errorMsg);
/*
* Since we couldn't find solution repository path there is no point in going forward and the user should know
* that a major config setting was not found. So we are throwing in a RunTimeException with the requisite message.
*/
throw new RuntimeException(errorMsg);
}
logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_ROOT_PATH", // $NON-NLS-1$
SolutionContextListener.solutionPath));
// $NON-NLS-1$
String fullyQualifiedServerUrl = getServerParameter("fully-qualified-server-url");
if (fullyQualifiedServerUrl == null) {
// assume this is a demo installation
// TODO: Create a servlet that's loaded on startup to set this value
// $NON-NLS-1$
fullyQualifiedServerUrl = "http://localhost:8080/pentaho/";
}
IApplicationContext applicationContext = new WebApplicationContext(SolutionContextListener.solutionPath, fullyQualifiedServerUrl, context.getRealPath(""), // $NON-NLS-1$
context);
/*
* Copy out all the Server.properties from to the application context
*/
Properties props = new Properties();
ISystemConfig systemConfig = PentahoSystem.get(ISystemConfig.class);
if (systemConfig != null) {
IConfiguration config = systemConfig.getConfiguration("server");
if (config != null) {
try {
props.putAll(config.getProperties());
} catch (IOException e) {
logger.error("Could not find/read the server.properties file.");
}
}
}
/*
* Copy out all the initParameter values from the servlet context and put them in the application context.
*/
Enumeration<?> initParmNames = context.getInitParameterNames();
String initParmName;
while (initParmNames.hasMoreElements()) {
initParmName = (String) initParmNames.nextElement();
props.setProperty(initParmName, getServerParameter(initParmName, true));
}
((WebApplicationContext) applicationContext).setProperties(props);
setSystemCfgFile(context);
setObjectFactory(context);
serverStatusProvider.setStatus(IServerStatusProvider.ServerStatus.STARTING);
serverStatusProvider.setStatusMessages(new String[] { "Caution, the system is initializing. Do not shut down or restart the system at this time." });
PeriodicStatusLogger.start();
boolean initOk = false;
try {
initOk = PentahoSystem.init(applicationContext);
} finally {
updateStatusMessages(initOk);
PeriodicStatusLogger.stop();
}
this.showInitializationMessage(initOk, fullyQualifiedServerUrl);
}
use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class DIServerConfigTest method setup.
@Before
public void setup() throws Exception {
IApplicationContext mockAppContext = mock(IApplicationContext.class);
when(mockAppContext.getFullyQualifiedServerURL()).thenReturn(SERVER_URL);
PentahoSystem.setApplicationContext(mockAppContext);
IPentahoSession pentahoSession = mock(IPentahoSession.class);
when(pentahoSession.getName()).thenReturn(MOCK_USER);
PentahoSessionHolder.setSession(pentahoSession);
baseConfig = new SlaveServerConfig();
pluginRegistry = mock(PluginRegistry.class);
purRepositoryMeta = mock(RepositoryMeta.class);
purRepository = mock(Repository.class);
purMetaStore = mock(IMetaStore.class);
when(pluginRegistry.loadClass(RepositoryPluginType.class, DIServerConfig.PUR_REPOSITORY_PLUGIN_ID, Repository.class)).thenReturn(purRepository);
when(pluginRegistry.loadClass(RepositoryPluginType.class, DIServerConfig.PUR_REPOSITORY_PLUGIN_ID, RepositoryMeta.class)).thenReturn(purRepositoryMeta);
when(purRepository.getMetaStore()).thenReturn(purMetaStore);
when(purMetaStore.getName()).thenReturn("Mock MetaStore");
logChannel = mock(LogChannel.class);
}
use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class SolutionPropertiesFileConfigurationTest method testGetSolutionPath_fromAppContext.
@Test
public void testGetSolutionPath_fromAppContext() throws Exception {
IApplicationContext appContext = mock(IApplicationContext.class);
when(appContext.getSolutionPath("system")).thenReturn(f.getParent());
PentahoSystem.setApplicationContext(appContext);
String solutionPath = SolutionPropertiesFileConfiguration.getSolutionPath();
assertEquals(f.getParent(), solutionPath);
}
use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class MessageFormatterTest method before.
@Before
public void before() {
mockedRuntimeRepository = mock(IRuntimeRepository.class);
mockedSolutionEngine = mock(ISolutionEngine.class);
mockedPentahoSystem = new MockUp<PentahoSystem>() {
@Mock
public IApplicationContext getApplicationContext() {
final String solutionPath = ".";
final String applicationPath = "";
return new StandaloneApplicationContext(solutionPath, applicationPath);
}
};
runtimeCtx = spy(new RuntimeContext("id", mockedSolutionEngine, "solutionName", makeRuntimeData(session), session, null, "processId", urlFactory, makeParameterProviders(session), new ArrayList<String>(), null));
}
Aggregations