Search in sources :

Example 41 with IPentahoSession

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);
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) FilterPanelException(org.pentaho.platform.uifoundation.component.xml.FilterPanelException) Document(org.dom4j.Document) SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger) FilterPanelException(org.pentaho.platform.uifoundation.component.xml.FilterPanelException) FilterPanel(org.pentaho.platform.uifoundation.component.xml.FilterPanel) FilterDefinition(org.pentaho.platform.uifoundation.component.FilterDefinition) ILogger(org.pentaho.platform.api.engine.ILogger) List(java.util.List) LinkedList(java.util.LinkedList) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 42 with IPentahoSession

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;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 43 with IPentahoSession

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());
        }
    }
}
Also used : IPentahoStreamSource(org.pentaho.commons.connection.IPentahoStreamSource) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Method(java.lang.reflect.Method) Date(java.util.Date) BigDecimal(java.math.BigDecimal) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 44 with IPentahoSession

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();
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) HttpSession(javax.servlet.http.HttpSession) OutputStream(java.io.OutputStream) HttpOutputHandler(org.pentaho.platform.web.http.HttpOutputHandler) IUIComponent(org.pentaho.platform.api.ui.IUIComponent) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory)

Example 45 with IPentahoSession

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) FileItem(org.apache.commons.fileupload.FileItem) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10