Search in sources :

Example 6 with MetaAction

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

the class MetaActionTool method actionToMetaAction.

/**
 * Creates a new {@code MetaAction} from the given action.<br>
 * This can be used for example to create a new menu entry with an {@code ActionView} generated
 * with user input.
 *
 * @param action The {@code Action} to be converted
 * @param name The {@code String} representing the name of the resulting {@code MetaAction}
 * @param type The {@code String} representing the type of the resulting {@code MetaAction}
 * @param module The {@code String} representing the name of the module that the resulting {@code
 *     MetaAction} should be attached to.
 * @return The {@code MetaAction} created from the given action
 */
public static MetaAction actionToMetaAction(Action action, String name, String type, String module) {
    MetaAction metaAction = new MetaAction();
    metaAction.setModel(action.getModel());
    metaAction.setModule(module);
    metaAction.setName(name);
    metaAction.setType(type);
    metaAction.setXml(XMLViews.toXml(action, true));
    return metaAction;
}
Also used : MetaAction(com.axelor.meta.db.MetaAction)

Example 7 with MetaAction

use of com.axelor.meta.db.MetaAction 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 8 with MetaAction

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

the class AccessTemplateServiceImpl method processMenu.

private void processMenu(Iterator<MetaMenu> menuIter) {
    if (!menuIter.hasNext()) {
        return;
    }
    MetaMenu menu = menuIter.next();
    String app = getApp(menu);
    menuApp.put(menu.getName(), app);
    MetaAction action = menu.getAction();
    if (action != null && action.getType().equals("action-view")) {
        String model = action.getModel();
        if (validModel(model)) {
            String menuName = getObjMenu(menu);
            if (menuName != null) {
                objMenu.put(model, menuName);
            }
        }
    }
    List<MetaMenu> menus = metaMenuRepo.all().filter("self.parent = ?1", menu).order("id").fetch();
    processMenu(menus.iterator());
    processMenu(menuIter);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction)

Example 9 with MetaAction

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

the class WkfMenuService method createOrUpdateAction.

@Transactional
public MetaAction createOrUpdateAction(MetaMenu metaMenu, WkfTaskConfig wkfTaskConfig, boolean userMenu) {
    if (wkfTaskConfig.getModelName() == null && wkfTaskConfig.getJsonModelName() == null) {
        return null;
    }
    String name = metaMenu.getName().replace("-", ".");
    MetaAction metaAction = metaActionRepository.findByName(name);
    if (metaAction == null) {
        metaAction = new MetaAction(name);
    }
    metaAction.setType("action-view");
    String model = getModelName(wkfTaskConfig);
    metaAction.setModel(model);
    boolean isJson = model.equals(MetaJsonRecord.class.getName());
    String query = createQuery(wkfTaskConfig, userMenu, isJson);
    Map<String, String> viewMap = getViewNames(wkfTaskConfig, userMenu, isJson);
    boolean permanent = userMenu ? wkfTaskConfig.getUserPermanentMenu() : wkfTaskConfig.getPermanentMenu();
    String xml = "<action-view name=\"" + name + "\" model=\"" + model + "\" title=\"" + metaMenu.getTitle() + "\">\n" + "\t<view type=\"grid\" name=\"" + viewMap.get("grid") + "\" />\n" + "\t<view type=\"form\" name=\"" + viewMap.get("form") + "\" />\n" + "\t<domain>" + query + "</domain>\n" + "\t<context name=\"processInstanceIds\" expr=\"call:" + WkfInstanceService.class.getName() + ":findProcessInstanceByNode('" + wkfTaskConfig.getName() + "','" + wkfTaskConfig.getProcessId() + "','" + wkfTaskConfig.getType() + "'," + permanent + ")\" />\n" + (userMenu ? "<context name=\"currentUserId\" expr=\"eval:__user__.id\" />\n" : "") + (isJson ? "<context name=\"jsonModel\" expr=\"" + wkfTaskConfig.getJsonModelName() + "\" />\n" : "") + "</action-view>";
    metaAction.setXml(xml);
    return metaActionRepository.save(metaAction);
}
Also used : WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService) MetaAction(com.axelor.meta.db.MetaAction) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord) Transactional(com.google.inject.persist.Transactional)

Example 10 with MetaAction

use of com.axelor.meta.db.MetaAction 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)

Aggregations

MetaAction (com.axelor.meta.db.MetaAction)11 Transactional (com.google.inject.persist.Transactional)6 MetaMenu (com.axelor.meta.db.MetaMenu)4 Group (com.axelor.auth.db.Group)2 Role (com.axelor.auth.db.Role)2 RoleRepository (com.axelor.auth.db.repo.RoleRepository)2 MetaMenuRepository (com.axelor.meta.db.repo.MetaMenuRepository)2 ObjectViews (com.axelor.meta.schema.ObjectViews)2 ActionView (com.axelor.meta.schema.actions.ActionView)2 ArrayList (java.util.ArrayList)2 WkfInstanceService (com.axelor.apps.bpm.service.execution.WkfInstanceService)1 User (com.axelor.auth.db.User)1 GroupRepository (com.axelor.auth.db.repo.GroupRepository)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)1 MetaView (com.axelor.meta.db.MetaView)1 MetaActionRepository (com.axelor.meta.db.repo.MetaActionRepository)1 Action (com.axelor.meta.schema.actions.Action)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1 AbstractWidget (com.axelor.meta.schema.views.AbstractWidget)1