Search in sources :

Example 1 with MetaView

use of com.axelor.meta.db.MetaView in project axelor-open-suite by axelor.

the class ChartBuilderService method build.

/**
 * Root Method to access the service it generate AbstractView from ViewBuilder.
 *
 * @param viewBuilder ViewBuilder object of type chart.
 * @return AbstractView from meta schema.
 * @throws JAXBException
 * @throws AxelorException
 */
public void build(ChartBuilder chartBuilder) throws JAXBException, AxelorException {
    if (chartBuilder.getName().contains(" ")) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.CHART_BUILDER_1));
    }
    searchFields = new ArrayList<String>();
    // onNewFields = new ArrayList<RecordField>();
    joins = new ArrayList<String>();
    categType = "text";
    String[] queryString = prepareQuery(chartBuilder);
    // setOnNewAction(chartBuilder);
    String xml = createXml(chartBuilder, queryString);
    log.debug("Chart xml: {}", xml);
    ObjectViews chartView = XMLViews.fromXML(xml);
    MetaView metaView = metaService.generateMetaView(chartView.getViews().get(0));
    if (metaView != null) {
        chartBuilder.setMetaViewGenerated(metaView);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ObjectViews(com.axelor.meta.schema.ObjectViews) MetaView(com.axelor.meta.db.MetaView)

Example 2 with MetaView

use of com.axelor.meta.db.MetaView in project axelor-open-suite by axelor.

the class DashboardBuilderService method build.

/**
 * Method to generate Dashboard (meta schema) from View Builder.
 *
 * @param viewBuilder ViewBuilder of type dashboard.
 * @return Dashboard.
 */
public MetaView build(DashboardBuilder dashboardBuilder) {
    log.debug("Processing dashboard: {}", dashboardBuilder.getName());
    log.debug("Dashlet list: {}", dashboardBuilder.getDashletBuilderList());
    if (dashboardBuilder.getDashletBuilderList() == null || dashboardBuilder.getDashletBuilderList().isEmpty()) {
        return null;
    }
    Dashboard dashboard = new Dashboard();
    String boardName = dashboardBuilder.getName();
    dashboard.setTitle(dashboardBuilder.getTitle());
    dashboard.setName(dashboardBuilder.getName());
    List<AbstractWidget> dashlets = new ArrayList<AbstractWidget>();
    dashboardBuilder.clearGeneratedActions();
    for (DashletBuilder dashletBuilder : dashboardBuilder.getDashletBuilderList()) {
        Dashlet dashlet = new Dashlet();
        String name = null;
        String model = null;
        MetaView metaView = dashletBuilder.getMetaView();
        MetaAction action = dashletBuilder.getAction();
        String actionName = null;
        if (metaView != null) {
            name = metaView.getName();
            model = metaView.getModel();
            MetaAction metaAction = getAction(boardName, name, model, dashletBuilder);
            actionName = metaAction.getName();
            dashboardBuilder.addGeneratedAction(metaAction);
        } else if (action != null) {
            model = action.getModel();
            actionName = action.getName();
        }
        dashlet.setAction(actionName);
        dashlet.setHeight("350");
        Integer colSpan = dashletBuilder.getColspan();
        if (colSpan > 12) {
            colSpan = 12;
        } else if (colSpan <= 0) {
            colSpan = 6;
        }
        dashlet.setColSpan(colSpan);
        dashlets.add(dashlet);
    }
    if (dashlets.isEmpty()) {
        return null;
    }
    dashboard.setItems(dashlets);
    MetaStore.clear();
    return metaService.generateMetaView(dashboard);
}
Also used : DashletBuilder(com.axelor.studio.db.DashletBuilder) ArrayList(java.util.ArrayList) Dashboard(com.axelor.meta.schema.views.Dashboard) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget) Dashlet(com.axelor.meta.schema.views.Dashlet) MetaView(com.axelor.meta.db.MetaView) MetaAction(com.axelor.meta.db.MetaAction)

Example 3 with MetaView

use of com.axelor.meta.db.MetaView in project axelor-open-suite by axelor.

the class ReportBuilderService method createTable.

/**
 * Process panelRelated to find right grid view of reference model. Grid view used to create html
 * table.
 *
 * @param panelRelated PanelRelated to use.
 * @param refModel Name of model refer by panelRelated.
 * @return Html table string created.
 */
private String createTable(PanelRelated panelRelated, String refModel) {
    List<AbstractWidget> items = panelRelated.getItems();
    if (items != null && !items.isEmpty()) {
        return getHtmlTable(panelRelated.getName(), items, refModel);
    }
    MetaView gridView = findGridView(panelRelated.getGridView(), refModel);
    if (gridView != null) {
        try {
            ObjectViews views = XMLViews.fromXML(gridView.getXml());
            GridView grid = (GridView) views.getViews().get(0);
            return getHtmlTable(panelRelated.getName(), grid.getItems(), refModel);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
    return "";
}
Also used : JAXBException(javax.xml.bind.JAXBException) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget) ObjectViews(com.axelor.meta.schema.ObjectViews) MetaView(com.axelor.meta.db.MetaView) GridView(com.axelor.meta.schema.views.GridView)

Example 4 with MetaView

use of com.axelor.meta.db.MetaView in project axelor-open-suite by axelor.

the class ChartBuilderRepo method remove.

@Override
public void remove(ChartBuilder chartBuilder) {
    MetaView metaView = chartBuilder.getMetaViewGenerated();
    List<ChartBuilder> chartBuilders = all().filter("self.metaViewGenerated = ?1 and self.id != ?2", metaView, chartBuilder.getId()).fetch();
    for (ChartBuilder builder : chartBuilders) {
        builder.setMetaViewGenerated(null);
    }
    if (metaView != null) {
        metaViewRepo.remove(metaView);
    }
    super.remove(chartBuilder);
}
Also used : ChartBuilder(com.axelor.studio.db.ChartBuilder) MetaView(com.axelor.meta.db.MetaView)

Example 5 with MetaView

use of com.axelor.meta.db.MetaView in project axelor-open-suite by axelor.

the class DashboardBuilderRepo method save.

@Override
public DashboardBuilder save(DashboardBuilder dashboardBuilder) {
    dashboardBuilder = super.save(dashboardBuilder);
    MetaView metaView = dashboardBuilderService.build(dashboardBuilder);
    if (metaView != null) {
        dashboardBuilder.setMetaViewGenerated(metaView);
    } else {
        metaView = dashboardBuilder.getMetaViewGenerated();
        if (metaView != null) {
            metaViewRepo.remove(metaView);
        }
    }
    return dashboardBuilder;
}
Also used : MetaView(com.axelor.meta.db.MetaView)

Aggregations

MetaView (com.axelor.meta.db.MetaView)9 ObjectViews (com.axelor.meta.schema.ObjectViews)2 AbstractWidget (com.axelor.meta.schema.views.AbstractWidget)2 Model (com.axelor.db.Model)1 AxelorException (com.axelor.exception.AxelorException)1 MetaAction (com.axelor.meta.db.MetaAction)1 MetaViewRepository (com.axelor.meta.db.repo.MetaViewRepository)1 Dashboard (com.axelor.meta.schema.views.Dashboard)1 Dashlet (com.axelor.meta.schema.views.Dashlet)1 GridView (com.axelor.meta.schema.views.GridView)1 Context (com.axelor.rpc.Context)1 ActionBuilderView (com.axelor.studio.db.ActionBuilderView)1 ChartBuilder (com.axelor.studio.db.ChartBuilder)1 DashletBuilder (com.axelor.studio.db.DashletBuilder)1 Transactional (com.google.inject.persist.Transactional)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1