MondrianCatalogPublisher.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.pentaho.ui.servlet |
![]() |
![]() |
Pentaho |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Copyright 2008 Pentaho Corporation. All rights reserved.
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
* BI Platform. The Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*/
package org.pentaho.ui.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mondrian.xmla.DataSourcesConfig.DataSource;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.core.repository.ISolutionRepository;
import org.pentaho.core.session.IPentahoSession;
import org.pentaho.core.system.PentahoSystem;
import org.pentaho.core.util.DatasourceHelper;
import org.pentaho.core.util.UIUtil;
import org.pentaho.messages.Messages;
import org.pentaho.messages.util.LocaleHelper;
import org.pentaho.ui.servlet.IMondrianCatalogService.MondrianCatalog;
import org.pentaho.ui.servlet.IMondrianCatalogService.MondrianCatalogServiceException;
import org.pentaho.ui.servlet.IMondrianCatalogService.MondrianCube;
import org.pentaho.ui.servlet.IMondrianCatalogService.MondrianDataSource;
import org.pentaho.ui.servlet.IMondrianCatalogService.MondrianSchema;
public class MondrianCatalogPublisher extends RepositoryFilePublisher {
// ~ Static fields/initializers ======================================================================================
private static final Log logger = LogFactory.getLog(MondrianCatalogPublisher.class);
private static final long serialVersionUID = -6052692173173633694L;
// ~ Instance fields =================================================================================================
private IMondrianCatalogService mondrianCatalogService = MondrianCatalogHelper.getInstance();
private String baseUrl;
// ~ Constructors ====================================================================================================
public MondrianCatalogPublisher() {
super();
baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
}
// ~ Methods =========================================================================================================
@Override
public Log getLogger() {
return logger;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding(LocaleHelper.getSystemEncoding());
IPentahoSession pentahoSession = UIUtil.getPentahoSession(req);
String publishPath = req.getParameter("publishPath"); //$NON-NLS-1$
String publishKey = req.getParameter("publishKey");//$NON-NLS-1$
String jndiName = req.getParameter("jndiName");//$NON-NLS-1$
String jdbcDriver = req.getParameter("jdbcDriver");//$NON-NLS-1$
String jdbcUrl = req.getParameter("jdbcUrl");//$NON-NLS-1$
String jdbcUserId = req.getParameter("jdbcUserId");//$NON-NLS-1$
String jdbcPassword = req.getParameter("jdbcPassword");//$NON-NLS-1$
boolean overwrite = Boolean.valueOf(req.getParameter("overwrite")).booleanValue(); //$NON-NLS-1$
boolean enableXmla = Boolean.valueOf(req.getParameter("enableXmla")).booleanValue(); //$NON-NLS-1$
List<FileItem> fileItems = Collections.emptyList();
try {
fileItems = getFileItems(req);
} catch (FileUploadException e) {
if (logger.isErrorEnabled()) {
logger.error(Messages.getErrorString("MondrianCatalogPublisher.ERROR_0002_EXCEPTION_OCCURRED"), e); //$NON-NLS-1$
}
resp.getWriter().println(ISolutionRepository.FILE_ADD_FAILED);
return;
}
int status = ISolutionRepository.FILE_ADD_FAILED;
try {
status = doPublish(fileItems, publishPath, publishKey, jndiName, jdbcDriver, jdbcUrl, jdbcUserId, jdbcPassword,
overwrite, pentahoSession);
} catch (Exception e) {
logger.error(Messages.getErrorString("MondrianCatalogPublisher.ERROR_0005_PUBLISH_EXCEPTION"), e); //$NON-NLS-1$
}
if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
resp.getWriter().println(status);
return;
}
if (logger.isDebugEnabled()) {
logger.debug("publishPath=" + publishPath); //$NON-NLS-1$
}
if ((publishPath != null) && (publishPath.endsWith("/") || publishPath.endsWith("\\"))) { //$NON-NLS-1$ //$NON-NLS-2$
publishPath = publishPath.substring(0, publishPath.length() - 1);
}
if (logger.isDebugEnabled()) {
logger.debug("jndiName=" + jndiName); //$NON-NLS-1$
}
if (StringUtils.isBlank(jndiName)) {
throw new ServletException(Messages.getErrorString("MondrianCatalogPublisher.ERROR_0003_JNDINAME_REQUIRED")); //$NON-NLS-1$
}
// expecting exactly one file
if (fileItems.size() != 1) {
// when this is appended, FILE_ADD_SUCCESSFUL has already been appended from super
if (logger.isErrorEnabled()) {
logger.error(Messages.getErrorString("MondrianCatalogPublisher.ERROR_0004_FILE_COUNT", "" + fileItems.size())); //$NON-NLS-1$ //$NON-NLS-2$
}
resp.getWriter().println(ISolutionRepository.FILE_ADD_FAILED);
return;
}
FileItem fi = fileItems.iterator().next();
String dsUrl = baseUrl;
if (!dsUrl.endsWith("/")) { //$NON-NLS-1$
dsUrl += "/"; //$NON-NLS-1$
}
dsUrl += "Xmla"; //$NON-NLS-1$
String dsAuthMode = DataSource.AUTH_MODE_UNAUTHENTICATED;
String dsProviderName = "Pentaho"; //$NON-NLS-1$
// DataSources where ProviderType=None are filtered by PentahoXmlaServlet
String dsProviderType = enableXmla ? DataSource.PROVIDER_TYPE_MDP : "None"; //$NON-NLS-1$
String catDef = "solution:" + publishPath + "/" + fi.getName(); //$NON-NLS-1$//$NON-NLS-2$
MondrianSchema mondrianSchema = mondrianCatalogService.loadMondrianSchema(catDef, pentahoSession);
String catName = mondrianSchema.getName();
String dsName = "Provider=Mondrian;DataSource=" + mondrianSchema.getName(); //$NON-NLS-1$
String dsDesc = "Published Mondrian Schema " + mondrianSchema.getName() + " using jndi datasource " + jndiName; //$NON-NLS-1$ //$NON-NLS-2$
// verify JNDI
try {
DatasourceHelper.getDSBoundName(jndiName);
} catch (NamingException e) {
logger.error(Messages.getErrorString("MondrianCatalogPublisher.ERROR_0001_JNDI_NAMING_ERROR", jndiName), e); //$NON-NLS-1$
resp.getWriter().println(ISolutionRepository.FILE_ADD_FAILED);
return;
}
// used in both the catalog and the catalog datasource
// Note: we use the unbound JNDI name here, the PentahoXmlaServlet and PivotViewComponent resolve the JNDI name
String catConnectStr = "Provider=mondrian;DataSource=" + jndiName; //$NON-NLS-1$
MondrianDataSource ds = new MondrianDataSource(dsName, dsDesc, dsUrl, catConnectStr, dsProviderName,
dsProviderType, dsAuthMode, null);
MondrianCatalog cat = new MondrianCatalog(catName, catConnectStr, catDef, ds, new MondrianSchema(catName,
new ArrayList<MondrianCube>()));
try {
mondrianCatalogService.addCatalog(cat, overwrite, pentahoSession);
} catch (MondrianCatalogServiceException e) {
if (logger.isErrorEnabled()) {
logger.error(Messages.getErrorString("MondrianCatalogPublisher.ERROR_0002_EXCEPTION_OCCURRED"), e); //$NON-NLS-1$
}
resp.getWriter().println(ISolutionRepository.FILE_ADD_FAILED);
return;
}
resp.getWriter().println(ISolutionRepository.FILE_ADD_SUCCESSFUL);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
public IMondrianCatalogService getMondrianCatalogService() {
return mondrianCatalogService;
}
public void setMondrianCatalogService(final IMondrianCatalogService mondrianCatalogService) {
this.mondrianCatalogService = mondrianCatalogService;
}
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(final String baseUrl) {
this.baseUrl = baseUrl;
}
}
The table below shows all metrics for MondrianCatalogPublisher.java.




