use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class FilterDefinitionIT method testFilterCreation.
public void testFilterCreation() {
try {
// $NON-NLS-1$
Class.forName("net.sf.cglib.transform.ClassFilter");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ILogger l = new SimpleLogger(this);
IPentahoSession session = getSession();
setGlobalParams();
this.sessionStartup(session);
Document doc = null;
try {
// $NON-NLS-1$
doc = XmlDom4JHelper.getDocFromFile(new File(SOLUTION_PATH + "/test/filterPanel/test.filterpanel.xml"), null);
} catch (Exception ee) {
ee.printStackTrace();
// $NON-NLS-1$
assertTrue("Failed to get the document from a file.", false);
}
FilterPanel fp = null;
try {
fp = new FilterPanel(session, doc, l);
} catch (FilterPanelException e) {
e.printStackTrace();
// $NON-NLS-1$
assertTrue("Failed to create stream from document.", false);
}
Map parameterProviders = getParameterProviders();
boolean success = false;
List filters = fp.getFilters();
FilterDefinition fd = null;
fd = (FilterDefinition) filters.get(0);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter session-attribute failed", success);
fd = (FilterDefinition) filters.get(1);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter global-attribute failed", success);
fd = (FilterDefinition) filters.get(2);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter static-lov failed", success);
fd = (FilterDefinition) filters.get(3);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter action sequence failed", success);
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class TenantAwareLoginParsingDatasourceService method getTenantId.
@Override
public String getTenantId() {
// Retrieve the session and get the user id.
IPentahoSession session = PentahoSessionHolder.getSession();
String id = session.getName();
String rtn = null;
if (id != null) {
// No ID - bail out here
if (id.indexOf(getTenantSeparator()) >= 0) {
// Only gets here if the userid is non-null and has the tenantSeparator
// split the field
String[] bits = id.split(getTenantSeparator());
if (isTenantOnLeft()) {
// get the 0th or the 1st element depending
rtn = bits[0];
} else {
rtn = bits[1];
}
}
}
return rtn;
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class PojoComponent method callMethods.
protected void callMethods(List<Method> methods, Object value) throws Throwable {
if (value instanceof String) {
callMethodWithString(methods, value.toString());
return;
}
boolean done = false;
for (Method method : methods) {
Class<?>[] paramClasses = method.getParameterTypes();
if (paramClasses.length != 1) {
// we don't know how to handle this
throw new GenericSignatureFormatError();
}
Class<?> paramclass = paramClasses[0];
// do some type safety. this would be the point to do automatic type conversions
if (value instanceof IPentahoResultSet && paramclass.equals(IPentahoResultSet.class)) {
done = true;
method.invoke(pojo, new Object[] { (IPentahoResultSet) value });
break;
} else if (value instanceof java.lang.Boolean && (paramclass.equals(Boolean.class) || paramclass.equals(boolean.class))) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof java.lang.Integer && (paramclass.equals(Integer.class) || paramclass.equals(int.class))) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof java.lang.Long && (paramclass.equals(Long.class) || paramclass.equals(long.class))) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof java.lang.Double && (paramclass.equals(Double.class) || paramclass.equals(double.class))) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof java.lang.Float && (paramclass.equals(Float.class) || paramclass.equals(float.class))) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof IPentahoStreamSource && paramclass.equals(IPentahoStreamSource.class)) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof Date && paramclass.equals(Date.class)) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof BigDecimal && paramclass.equals(BigDecimal.class)) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof IContentItem && paramclass.equals(IContentItem.class)) {
done = true;
method.invoke(pojo, new Object[] { value });
break;
} else if (value instanceof IContentItem && paramclass.equals(String.class)) {
done = true;
method.invoke(pojo, new Object[] { value.toString() });
break;
} else if (paramclass.equals(IPentahoSession.class)) {
done = true;
method.invoke(pojo, new Object[] { (IPentahoSession) value });
break;
} else if (paramclass.equals(Log.class)) {
done = true;
method.invoke(pojo, new Object[] { (Log) value });
break;
}
}
if (!done) {
// Try invoking the first instance with what we have
try {
methods.get(0).invoke(pojo, new Object[] { value });
} catch (Exception ex) {
throw new IllegalArgumentException(// $NON-NLS-1$ //$NON-NLS-2$
"No implementation of method \"" + Method.class.getName() + "\" takes a " + value.getClass());
}
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UIServlet method doGet.
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
PentahoSystem.systemEntryPoint();
try {
OutputStream outputStream = response.getOutputStream();
String path = request.getContextPath();
IPentahoSession userSession = getPentahoSession(request);
HttpSession session = request.getSession();
// $NON-NLS-1$
String type = MediaType.valueOf(request.getParameter("type")).toString();
if (type == null) {
// $NON-NLS-1$
type = "text/html";
}
// find out which component is going to fulfill this request
// $NON-NLS-1$
String componentName = StringEscapeUtils.escapeHtml(request.getParameter("component"));
if (componentName == null) {
// $NON-NLS-1$
response.setContentType("text/html");
StringBuffer buffer = new StringBuffer();
formatErrorMessage(userSession, buffer, "UIServlet.ERROR_0001_COMPONENT_NOT_SPECIFIED");
outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
return;
}
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// TODO switch this to the interface once stable
IUIComponent component = (IUIComponent) session.getAttribute(componentName);
if (component == null) {
component = getComponent(componentName);
if (component == null) {
// $NON-NLS-1$
response.setContentType("text/html");
StringBuffer buffer = new StringBuffer();
formatErrorMessage(userSession, buffer, "UIServlet.ERROR_0002_COMPONENT_INVALID");
outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
return;
}
session.setAttribute(componentName, component);
}
if (!component.validate()) {
// TODO need an error here
return;
}
String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/content?type=" + type + "&component=" + componentName + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"&";
response.setContentType(type);
HttpOutputHandler outputHandler = new HttpOutputHandler(response, outputStream, true);
SimpleUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
HttpServletRequestHandler requestHandler = new HttpServletRequestHandler(userSession, null, request, outputHandler, urlFactory);
requestHandler.handleUIRequest(component, type);
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UploadFileServlet method doPost.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
IPentahoSession session = PentahoSessionHolder.getSession();
if (!hasManageDataAccessPermission(session)) {
response.sendError(403, Messages.getInstance().getErrorString("UploadFileServlet.ERROR_0009_UNAUTHORIZED"));
return;
}
UploadFileUtils utils = new UploadFileUtils(session);
// $NON-NLS-1$
response.setContentType("text/plain");
// Note - request.getParameter doesn't work on multi-part file data. But just in case,
// we get the standardRequestParamaters as well as the parameter map we create from the
// multi-part form data.
Map<String, String[]> standardRequestParameters = request.getParameterMap();
Map<String, FileItem> parsedMultiPartRequestParameters = this.getParsedRequestParameters(request, session);
// $NON-NLS-1$
FileItem uploadItem = parsedMultiPartRequestParameters.get("uploadFormElement");
if (uploadItem == null) {
// $NON-NLS-1$
String error = Messages.getInstance().getErrorString("UploadFileServlet.ERROR_0001_NO_FILE_TO_UPLOAD");
response.getWriter().write(error);
return;
}
// $NON-NLS-1$
String unzip = getRequestParameter(standardRequestParameters, parsedMultiPartRequestParameters, "unzip");
String temporary = // $NON-NLS-1$
getRequestParameter(standardRequestParameters, parsedMultiPartRequestParameters, "mark_temporary");
// $NON-NLS-1$
String fileName = getRequestParameter(standardRequestParameters, parsedMultiPartRequestParameters, "file_name");
if (StringUtils.isEmpty(fileName)) {
throw new ServletException(Messages.getInstance().getErrorString("UploadFileServlet.ERROR_0010_FILE_NAME_INVALID"));
}
boolean isTemporary = false;
if (temporary != null) {
isTemporary = Boolean.valueOf(temporary);
}
boolean shouldUnzip = false;
if (unzip != null) {
shouldUnzip = Boolean.valueOf(unzip);
}
utils.setShouldUnzip(shouldUnzip);
utils.setTemporary(isTemporary);
utils.setFileName(fileName);
utils.setWriter(response.getWriter());
utils.setUploadedFileItem(uploadItem);
// Do nothing with success value - the output should already have been written to the servlet response.
utils.process();
} catch (Exception e) {
String error = Messages.getInstance().getErrorString("UploadFileServlet.ERROR_0005_UNKNOWN_ERROR", // $NON-NLS-1
e.getLocalizedMessage());
response.getWriter().write(error);
}
}
Aggregations