Search in sources :

Example 1 with ObjectViews

use of com.axelor.meta.schema.ObjectViews 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 ObjectViews

use of com.axelor.meta.schema.ObjectViews 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 3 with ObjectViews

use of com.axelor.meta.schema.ObjectViews in project axelor-open-suite by axelor.

the class MenuBuilderController method showMenuBuilderRecords.

public void showMenuBuilderRecords(ActionRequest request, ActionResponse response) {
    MenuBuilder menuBuilder = request.getContext().asType(MenuBuilder.class);
    if (menuBuilder.getMetaMenu() == null || menuBuilder.getMetaMenu().getAction() == null) {
        return;
    }
    try {
        MetaAction metaAction = menuBuilder.getMetaMenu().getAction();
        ObjectViews objectViews = XMLViews.fromXML(metaAction.getXml());
        ActionView actionView = (ActionView) objectViews.getActions().get(0);
        ActionViewBuilder actionViewBuilder = ActionView.define(I18n.get(actionView.getTitle()));
        actionViewBuilder.model(actionView.getModel());
        actionViewBuilder.icon(actionView.getIcon());
        actionViewBuilder.domain(actionView.getDomain());
        actionViewBuilder.context("jsonModel", menuBuilder.getActionBuilder().getModel());
        actionView.getViews().forEach(view -> actionViewBuilder.add(view.getType(), view.getName()));
        if (ObjectUtils.notEmpty(actionView.getParams())) {
            actionView.getParams().forEach(param -> actionViewBuilder.param(param.getName(), param.getValue()));
        }
        response.setView(actionViewBuilder.map());
    } catch (Exception e) {
    }
}
Also used : ActionView(com.axelor.meta.schema.actions.ActionView) ObjectViews(com.axelor.meta.schema.ObjectViews) MetaAction(com.axelor.meta.db.MetaAction) MenuBuilder(com.axelor.studio.db.MenuBuilder) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 4 with ObjectViews

use of com.axelor.meta.schema.ObjectViews in project axelor-open-suite by axelor.

the class MenuBuilderService method createActionBuilder.

@SuppressWarnings("unchecked")
public Optional<ActionBuilder> createActionBuilder(MetaAction metaAction) {
    try {
        ObjectViews objectViews = XMLViews.fromXML(metaAction.getXml());
        List<Action> actions = objectViews.getActions();
        if (actions != null && !actions.isEmpty()) {
            ActionView action = (ActionView) actions.get(0);
            if (action.getModel() != null && action.getModel().contentEquals(MetaJsonRecord.class.getName())) {
                return Optional.empty();
            }
            ActionBuilder actionBuilder = new ActionBuilder(action.getName());
            actionBuilder.setTitle(action.getTitle());
            actionBuilder.setModel(action.getModel());
            actionBuilder.setTypeSelect(ActionBuilderRepository.TYPE_SELECT_VIEW);
            String domain = action.getDomain();
            actionBuilder.setDomainCondition(domain);
            for (ActionView.View view : action.getViews()) {
                ActionBuilderView builderView = new ActionBuilderView();
                builderView.setViewType(view.getType());
                builderView.setViewName(view.getName());
                actionBuilder.addActionBuilderView(builderView);
            }
            if (action.getParams() != null) {
                for (ActionView.Param param : action.getParams()) {
                    ActionBuilderLine paramLine = new ActionBuilderLine();
                    paramLine.setName(param.getName());
                    paramLine.setValue(param.getValue());
                    actionBuilder.addViewParam(paramLine);
                }
            }
            if (action.getContext() != null) {
                for (ActionView.Context ctx : (List<ActionView.Context>) action.getContext()) {
                    ActionBuilderLine ctxLine = new ActionBuilderLine();
                    ctxLine.setName(ctx.getName());
                    if (ctx.getName().contentEquals("jsonModel") && domain != null && domain.contains("self.jsonModel = :jsonModel")) {
                        actionBuilder.setIsJson(true);
                        actionBuilder.setModel(ctx.getExpression());
                    }
                    ctxLine.setValue(ctx.getExpression());
                    actionBuilder.addLine(ctxLine);
                }
            }
            return Optional.of(actionBuilder);
        }
    } catch (JAXBException e) {
        TraceBackService.trace(e);
    }
    return Optional.empty();
}
Also used : MetaAction(com.axelor.meta.db.MetaAction) Action(com.axelor.meta.schema.actions.Action) ActionBuilder(com.axelor.studio.db.ActionBuilder) ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) JAXBException(javax.xml.bind.JAXBException) ActionView(com.axelor.meta.schema.actions.ActionView) ObjectViews(com.axelor.meta.schema.ObjectViews) ActionBuilderView(com.axelor.studio.db.ActionBuilderView) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ObjectViews

use of com.axelor.meta.schema.ObjectViews in project axelor-open-suite by axelor.

the class ReportBuilderService method processView.

/**
 * Method parse given xml to create html.
 *
 * @param xml View xml passed.
 * @throws JAXBException Xml parsing exception.
 */
private void processView(String xml) throws JAXBException {
    ObjectViews objectViews = XMLViews.fromXML(xml);
    AbstractView view = objectViews.getViews().get(0);
    FormView formView = (FormView) view;
    for (AbstractWidget widget : formView.getItems()) {
        if (widget instanceof PanelTabs) {
            PanelTabs panelTabs = (PanelTabs) widget;
            AbstractWidget tabItem = panelTabs.getItems().get(0);
            processAbstractWidget(tabItem, false);
            continue;
        }
        processAbstractWidget(widget, false);
    }
}
Also used : AbstractView(com.axelor.meta.schema.views.AbstractView) PanelTabs(com.axelor.meta.schema.views.PanelTabs) ObjectViews(com.axelor.meta.schema.ObjectViews) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget) FormView(com.axelor.meta.schema.views.FormView)

Aggregations

ObjectViews (com.axelor.meta.schema.ObjectViews)5 MetaAction (com.axelor.meta.db.MetaAction)2 MetaView (com.axelor.meta.db.MetaView)2 ActionView (com.axelor.meta.schema.actions.ActionView)2 AbstractWidget (com.axelor.meta.schema.views.AbstractWidget)2 JAXBException (javax.xml.bind.JAXBException)2 AxelorException (com.axelor.exception.AxelorException)1 Action (com.axelor.meta.schema.actions.Action)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1 AbstractView (com.axelor.meta.schema.views.AbstractView)1 FormView (com.axelor.meta.schema.views.FormView)1 GridView (com.axelor.meta.schema.views.GridView)1 PanelTabs (com.axelor.meta.schema.views.PanelTabs)1 ActionBuilder (com.axelor.studio.db.ActionBuilder)1 ActionBuilderLine (com.axelor.studio.db.ActionBuilderLine)1 ActionBuilderView (com.axelor.studio.db.ActionBuilderView)1 MenuBuilder (com.axelor.studio.db.MenuBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1