Search in sources :

Example 16 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class WidgetTypeAction method save.

/**
 * Save a widget type.
 *
 * @return The result code.
 */
public String save() {
    try {
        if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT && (this.getStrutsAction() != ApsAdminSystemConstants.ADD)) {
            if (!this.hasCurrentUserPermission(Permission.SUPERUSER)) {
                return USER_NOT_ALLOWED;
            }
            return this.saveUserWidget();
        }
        WidgetType type = null;
        if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
            type = new WidgetType();
            type.setCode(this.getWidgetTypeCode());
        } else {
            String check = this.checkWidgetType();
            if (null != check) {
                return check;
            }
            type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
        }
        ApsProperties titles = new ApsProperties();
        titles.put("it", this.getItalianTitle());
        titles.put("en", this.getEnglishTitle());
        String mainGroupToSet = (this.hasCurrentUserPermission(Permission.SUPERUSER)) ? this.getMainGroup() : type.getMainGroup();
        String bundleIdToSet = (this.hasCurrentUserPermission(Permission.SUPERUSER)) ? this.getBundleId() : type.getBundleId();
        String configUiToSet = (this.hasCurrentUserPermission(Permission.SUPERUSER)) ? this.getConfigUi() : type.getConfigUi();
        if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
            type.setTitles(titles);
            type.setMainGroup(mainGroupToSet);
            type.setBundleId(bundleIdToSet);
            type.setConfigUi(configUiToSet);
            this.getWidgetTypeManager().addWidgetType(type);
        } else {
            ApsProperties configToSet = type.getConfig();
            if (type.isLogic() && type.isUserType() && !type.isLocked() && this.hasCurrentUserPermission(Permission.SUPERUSER)) {
                configToSet = this.extractWidgetTypeConfig(type.getParentType().getTypeParameters());
            }
            this.getWidgetTypeManager().updateWidgetType(this.getWidgetTypeCode(), titles, configToSet, mainGroupToSet, configUiToSet, bundleIdToSet);
        }
        if (!type.isLogic() && !super.isInternalServletWidget(this.getWidgetTypeCode())) {
            GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
            if (StringUtils.isNotBlank(this.getGui())) {
                if (null == guiFragment) {
                    guiFragment = new GuiFragment();
                    String code = this.extractUniqueGuiFragmentCode(this.getWidgetTypeCode());
                    guiFragment.setCode(code);
                    guiFragment.setPluginCode(type.getPluginCode());
                    guiFragment.setGui(this.getGui());
                    guiFragment.setWidgetTypeCode(this.getWidgetTypeCode());
                    this.getGuiFragmentManager().addGuiFragment(guiFragment);
                } else {
                    guiFragment.setGui(this.getGui());
                    this.getGuiFragmentManager().updateGuiFragment(guiFragment);
                }
            } else if (null != guiFragment) {
                if (StringUtils.isNotBlank(guiFragment.getDefaultGui())) {
                    guiFragment.setGui(null);
                    this.getGuiFragmentManager().updateGuiFragment(guiFragment);
                } else {
                    this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
                }
            }
        } else if (type.isLogic()) /* && super.isInternalServletWidget(type.getParentType().getCode())*/
        {
            this.buildGuisFromForm(type);
            List<String> guiFragmentCodes = this.extractGuiFragmentCodes(type.getCode());
            for (int i = 0; i < guiFragmentCodes.size(); i++) {
                String guiFragmentCode = guiFragmentCodes.get(i);
                GuiFragment guiFragment = this.getGuiFragment(guiFragmentCode);
                String fieldName = type.getCode() + "_" + guiFragmentCode;
                String value = this.getGuis().getProperty(fieldName);
                if ((null == value && null != guiFragment.getGui()) || (null != value && (StringUtils.isBlank(guiFragment.getGui()) || !value.equals(guiFragment.getGui())))) {
                    guiFragment.setGui(value);
                    this.getGuiFragmentManager().updateGuiFragment(guiFragment);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("error in save", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ArrayList(java.util.ArrayList) List(java.util.List) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 17 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class WidgetTypeAction method edit.

/**
 * Edit an exist widget type.
 *
 * @return The result code.
 */
public String edit() {
    try {
        String check = this.checkWidgetType();
        if (null != check) {
            return check;
        }
        this.setStrutsAction(ApsAdminSystemConstants.EDIT);
        WidgetType type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
        ApsProperties titles = type.getTitles();
        this.setItalianTitle(titles.getProperty("it"));
        this.setEnglishTitle(titles.getProperty("en"));
        String mainGroup = (StringUtils.isBlank(type.getMainGroup())) ? Group.FREE_GROUP_NAME : type.getMainGroup();
        this.setMainGroup(mainGroup);
        this.setBundleId(type.getBundleId());
        this.setConfigUi(type.getConfigUi());
        if (type.isLogic()) {
            List<String> guiFragmentCodes = this.extractGuiFragmentCodes(this.getWidgetTypeCode());
            for (int i = 0; i < guiFragmentCodes.size(); i++) {
                String guiFragmentCode = guiFragmentCodes.get(i);
                GuiFragment guiFragment = this.getGuiFragment(guiFragmentCode);
                if (StringUtils.isNotEmpty(guiFragment.getGui())) {
                    String fieldName = type.getCode() + "_" + guiFragmentCode;
                    this.getGuis().setProperty(fieldName, guiFragment.getGui());
                }
            }
        } else {
            GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(this.getWidgetTypeCode());
            if (null != guiFragment) {
                this.setGui(guiFragment.getGui());
            }
        }
    } catch (Throwable t) {
        _logger.error("error in edit", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 18 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class GuiFragmentResult method doExecute.

/**
 * Execute this result, using the specified fragment.
 * @param code The code of the fragment
 * @param invocation The invocation
 */
@Override
public void doExecute(String code, ActionInvocation invocation) throws Exception {
    if (null == code) {
        code = conditionalParse(this._code, invocation);
    }
    if (null == code) {
        this.executeDispatcherResult(invocation);
        return;
    }
    ActionContext ctx = invocation.getInvocationContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req);
    try {
        GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code);
        String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null;
        if (StringUtils.isBlank(output)) {
            _logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace());
            boolean execution = this.executeDispatcherResult(invocation);
            if (!execution) {
                output = "The fragment '" + code + "' is not available";
            } else {
                return;
            }
        }
        RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
        ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
        Writer writer = this.getWriter();
        Template template = new Template(code, new StringReader(output), ebc.getConfiguration());
        template.process(ebc.getTemplateModel(), writer);
    } catch (Throwable t) {
        _logger.error("Error processing GuiFragment result!", t);
        throw new RuntimeException("Error processing GuiFragment result!", t);
    }
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Template(freemarker.template.Template) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringReader(java.io.StringReader) RequestContext(com.agiletec.aps.system.RequestContext) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer) Writer(java.io.Writer)

Example 19 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class GuiFragmentAction method checkDelete.

private String checkDelete(String code) throws Throwable {
    GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
    if (null == guiFragment) {
        this.addActionError(this.getText("error.guiFragment.null"));
        return INPUT;
    }
    if (guiFragment.isLocked()) {
        this.addActionError(this.getText("error.guiFragment.locked"));
        return INPUT;
    }
    this.extractReferencingObjects(code);
    if (null != this.getReferences() && this.getReferences().size() > 0) {
        return "references";
    }
    return null;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment)

Example 20 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class GuiFragmentAction method trash.

public String trash() {
    try {
        GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(this.getCode());
        if (null == guiFragment) {
            this.addActionError(this.getText("error.guiFragment.null"));
            return INPUT;
        }
        String check = this.checkDelete(this.getCode());
        if (StringUtils.isNotBlank(check))
            return check;
        this.populateForm(guiFragment);
        this.setStrutsAction(ApsAdminSystemConstants.DELETE);
    } catch (Throwable t) {
        _logger.error("error in trash", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment)

Aggregations

GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)41 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)10 ArrayList (java.util.ArrayList)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)6 JAXBGuiFragment (org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)5 ApsProperties (com.agiletec.aps.util.ApsProperties)4 IGuiFragmentManager (org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager)4 List (java.util.List)3 Test (org.junit.Test)3 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)2 Template (freemarker.template.Template)2 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 ExecutorBeanContainer (org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)2 GuiFragmentUtilizer (org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer)2 GuiFragmentRequestBody (org.entando.entando.web.guifragment.model.GuiFragmentRequestBody)2 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)2 MapBindingResult (org.springframework.validation.MapBindingResult)2 RequestContext (com.agiletec.aps.system.RequestContext)1