All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openl.rules.ui.ObjectViewer Maven / Gradle / Ivy

There is a newer version: 5.27.9
Show newest version
package org.openl.rules.ui;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.openl.rules.calc.SpreadsheetResult;
import org.openl.rules.lang.xls.syntax.TableSyntaxNode;
import org.openl.rules.lang.xls.types.meta.EmptyMetaInfoReader;
import org.openl.rules.lang.xls.types.meta.MetaInfoReader;
import org.openl.rules.table.IGridTable;
import org.openl.rules.table.ILogicalTable;
import org.openl.rules.table.Point;
import org.openl.rules.table.ui.filters.IGridFilter;
import org.openl.rules.tableeditor.model.ui.TableModel;
import org.openl.rules.tableeditor.renderkit.HTMLRenderer;
import org.openl.rules.testmethod.result.ComparedResult;
import org.openl.rules.webstudio.web.util.WebStudioUtils;

/**
 * @author snshor
 * @deprecated
 */
@Deprecated
public final class ObjectViewer {

    private ObjectViewer() {
    }

    /**
     * Display SpreadsheetResult with added filter for given fields as expected result and passed/failed icon
     **/
    public static String displaySpreadsheetResult(final SpreadsheetResult res,
                                                  Map spreadsheetCellsForTest) {
        return display(res, spreadsheetCellsForTest, true, false);
    }

    /**
     * Display SpreadsheetResult with filter for links to explanation for values
     */
    public static String displaySpreadsheetResult(final SpreadsheetResult res) {
        return display(res, null, true, false);
    }

    /**
     * Display SpreadsheetResult without any filters in the table
     **/
    public static String displaySpreadsheetResultNoFilters(final SpreadsheetResult res, boolean smartNumbers) {
        return display(res, null, false, smartNumbers);
    }

    private static String display(final SpreadsheetResult res,
                                  Map spreadsheetCellsForTest,
                                  boolean filter,
                                  boolean smartNumbers) {
        List filters = new ArrayList<>();
        filters.add(new TableValueFilter(res, smartNumbers));
        filters.add(CollectionCellFilter.INSTANCE);

        if (filter) {
            // Check if the cells for test are initialized,
            // Means Spreadsheet should be displayed with expected values for tests
            //
            if (spreadsheetCellsForTest != null) {
                filters.add(new ExpectedResultFilter(spreadsheetCellsForTest));
            }
        }

        ILogicalTable table = res.getLogicalTable();
        IGridTable gridtable = table.getSource();

        ProjectModel model = WebStudioUtils.getWebStudio().getModel();
        MetaInfoReader metaInfoReader = Optional.ofNullable(model.getNode(gridtable.getUri()))
                .map(TableSyntaxNode::getMetaInfoReader)
                .orElseGet(EmptyMetaInfoReader::getInstance);

        TableModel tableModel = TableModel
                .initializeTableModel(gridtable, filters.toArray(new IGridFilter[0]), metaInfoReader, smartNumbers);
        return new HTMLRenderer.TableRenderer(tableModel).render(false);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy