Search in sources :

Example 1 with FilterDefinition

use of org.pentaho.platform.uifoundation.component.FilterDefinition 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 2 with FilterDefinition

use of org.pentaho.platform.uifoundation.component.FilterDefinition in project pentaho-platform by pentaho.

the class FilterPanel method getXForm.

public Document getXForm(final String actionUrl) {
    StringBuffer content = new StringBuffer();
    Document document = null;
    // String strUuid = UUID.randomUUID().toString().replaceAll( "-", "_");
    // $NON-NLS-1$ //$NON-NLS-2$
    String strUuid = UUIDUtil.getUUIDAsString().replaceAll("-", "_");
    content.append(// $NON-NLS-1$ //$NON-NLS-2$
    "<filters xmlns:xf=\"http://www.w3.org/2002/xforms\"><id>" + strUuid + "</id><title><![CDATA[" + Messages.getInstance().getEncodedString(name) + // $NON-NLS-1$
    "]]></title><description></description><help></help>" + "<action><![CDATA[" + actionUrl + // $NON-NLS-1$ //$NON-NLS-2$
    "]]></action>");
    if (error != null) {
        // $NON-NLS-1$
        content.append("<error>");
        content.append(error);
        // $NON-NLS-1$
        content.append("</error>");
    } else if (filterList == null) {
        // $NON-NLS-1$
        content.append("<error>");
        // $NON-NLS-1$
        content.append(Messages.getInstance().getString("FilterPanel.ERROR_0003_NO_FILTER_VALUES"));
        // $NON-NLS-1$
        content.append("</error>");
    } else {
        try {
            Iterator filtersIterator = filterList.iterator();
            StringBuffer xformHeader = new StringBuffer();
            String formName = null;
            while (filtersIterator.hasNext()) {
                FilterDefinition filterDefinition = (FilterDefinition) filtersIterator.next();
                String filterName = filterDefinition.getName();
                if (formName == null) {
                    formName = filterName;
                }
                String title = filterDefinition.getTitle();
                StringBuffer xformBody = new StringBuffer();
                // XForm.createXFormHeader(name, xformHeader);
                filterDefinition.getXForm(xformHeader, xformBody);
                // XForm.completeXForm(XForm.OUTPUT_HTML, filterName, new StringBuffer(), xformBody);
                // content.append( "<filter name=\""+filterName+"\">"
                // ).append(filterContent).append( "</filter>" );
                // //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                // $NON-NLS-1$ //$NON-NLS-2$
                content.append("<filter><name><![CDATA[" + filterName + "]]></name>").append(// $NON-NLS-1$ //$NON-NLS-2$
                "<title><![CDATA[" + title + "]]></title><control>").append(xformBody).append(// $NON-NLS-1$
                "</control></filter>");
            }
            XForm.completeXFormHeader(formName, xformHeader);
            content.append(xformHeader);
        } catch (Exception e) {
            // $NON-NLS-1$
            logger.error(Messages.getInstance().getErrorString("FilterPanel.ERROR_0004_COULD_NOT_CREATE_CONTENT"), e);
        }
    }
    // $NON-NLS-1$
    content.append("</filters>");
    if (FilterPanel.debug) {
        logger.debug(content.toString());
    }
    try {
        document = XmlDom4JHelper.getDocFromString(content.toString(), new PentahoEntityResolver());
    } catch (XmlParseException e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getErrorString("FilterPanel.ERROR_0004_COULD_NOT_CREATE_CONTENT"), e);
    }
    return document;
}
Also used : FilterDefinition(org.pentaho.platform.uifoundation.component.FilterDefinition) Iterator(java.util.Iterator) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) XmlParseException(org.pentaho.platform.api.util.XmlParseException)

Aggregations

Document (org.dom4j.Document)2 FilterDefinition (org.pentaho.platform.uifoundation.component.FilterDefinition)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ILogger (org.pentaho.platform.api.engine.ILogger)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 XmlParseException (org.pentaho.platform.api.util.XmlParseException)1 PentahoEntityResolver (org.pentaho.platform.engine.services.solution.PentahoEntityResolver)1 FilterPanel (org.pentaho.platform.uifoundation.component.xml.FilterPanel)1 FilterPanelException (org.pentaho.platform.uifoundation.component.xml.FilterPanelException)1 SimpleLogger (org.pentaho.platform.util.logging.SimpleLogger)1