Search in sources :

Example 26 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class PageConfigAction method joinWidget.

public String joinWidget() {
    try {
        String result = this.checkBaseParams();
        if (null != result) {
            return result;
        }
        if (null != this.getWidgetTypeCode() && this.getWidgetTypeCode().length() == 0) {
            this.addActionError(this.getText("error.page.widgetTypeCodeUnknown"));
            return INPUT;
        }
        _logger.debug("code={}, pageCode={}, frame={}" + this.getWidgetTypeCode(), this.getPageCode(), this.getFrame());
        WidgetType widgetType = this.getShowletType(this.getWidgetTypeCode());
        if (null == widgetType) {
            this.addActionError(this.getText("error.page.widgetTypeCodeUnknown"));
            return INPUT;
        }
        if (null == widgetType.getConfig() && null != widgetType.getAction()) {
            this.setWidgetAction(widgetType.getAction());
            // continue to widget configuration
            return "configureSpecialWidget";
        }
        Widget widget = new Widget();
        widget.setType(widgetType);
        this.getPageManager().joinWidget(this.getPageCode(), widget, this.getFrame());
        this.addActivityStreamInfo(ApsAdminSystemConstants.ADD, true);
    } catch (Exception e) {
        _logger.error("error in joinWidget", e);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 27 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class PageTreeMenuAction method getWidgetFlavoursMapping.

protected Map<String, List<SelectItem>> getWidgetFlavoursMapping(List<String> pluginCodes) {
    Map<String, List<SelectItem>> mapping = new HashMap<String, List<SelectItem>>();
    List<WidgetType> types = this.getWidgetTypeManager().getWidgetTypes();
    for (int i = 0; i < types.size(); i++) {
        WidgetType type = types.get(i);
        String pluginCode = type.getPluginCode();
        if (null != pluginCode && pluginCode.trim().length() > 0) {
            // is a plugin's widgets
            if (!pluginCodes.contains(pluginCode)) {
                pluginCodes.add(pluginCode);
            }
            this.addFlavourWidgetType(pluginCode, type, mapping);
        } else if (type.isUserType()) {
            // is a user widgets
            this.addFlavourWidgetType(USER_WIDGETS_CODE, type, mapping);
        } else if (this.getStockWidgetCodes().contains(type.getCode())) {
            this.addFlavourWidgetType(STOCK_WIDGETS_CODE, type, mapping);
        } else {
            this.addFlavourWidgetType(CUSTOM_WIDGETS_CODE, type, mapping);
        }
    }
    Collections.sort(pluginCodes);
    return mapping;
}
Also used : HashMap(java.util.HashMap) SelectItem(com.agiletec.aps.util.SelectItem) ArrayList(java.util.ArrayList) List(java.util.List) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 28 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class WidgetTypeAction method checkGui.

private boolean checkGui() throws Throwable {
    if (this.getStrutsAction() == NEW_USER_WIDGET || this.getStrutsAction() == ApsAdminSystemConstants.PASTE) {
        return true;
    }
    boolean isValuedGui = StringUtils.isNotBlank(this.getGui());
    if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        return isValuedGui;
    }
    if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT) {
        throw new RuntimeException("Invalid Struts Action " + this.getStrutsAction());
    }
    WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
    if (type.isLogic() || this.isInternalServletWidget(this.getWidgetTypeCode())) {
        return true;
    }
    String pluginCode = type.getPluginCode();
    String jspPath = WidgetType.getJspPath(this.getWidgetTypeCode(), pluginCode);
    String folderPath = this.getRequest().getSession().getServletContext().getRealPath("/");
    boolean existsJsp = (new File(folderPath + jspPath)).exists();
    if (existsJsp) {
        return true;
    }
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("file:**" + jspPath);
    for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        if (resource.exists()) {
            return true;
        }
    }
    GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
    if (!isValuedGui && (guiFragment == null || StringUtils.isBlank(guiFragment.getDefaultGui()))) {
        return false;
    } else {
        return true;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) Resource(org.springframework.core.io.Resource) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) File(java.io.File)

Example 29 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class WidgetTypeAction method saveUserWidget.

protected String saveUserWidget() {
    try {
        boolean isCopy = (null != this.getPageCode() && this.getPageCode().trim().length() > 0);
        String check = (isCopy) ? this.checkWidgetToCopy() : this.checkNewUserWidget();
        if (null != check) {
            return check;
        }
        WidgetType newType = null;
        Widget widgetToCopy = this.extractWidgetToCopy();
        if (null == widgetToCopy) {
            this.setReplaceOnPage(false);
            newType = this.createNewWidgetType();
            WidgetType parentType = this.getWidgetTypeManager().getWidgetType(this.getParentWidgetTypeCode());
            newType.setParentType(parentType);
            ApsProperties config = this.extractWidgetTypeConfig(parentType.getTypeParameters());
            newType.setConfig(config);
        } else {
            newType = this.createCopiedWidget(widgetToCopy);
        }
        // TODO CHECK MainGroup
        newType.setMainGroup(this.getMainGroup());
        this.getWidgetTypeManager().addWidgetType(newType);
        if (this.isReplaceOnPage()) {
            WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
            Widget widget = new Widget();
            widget.setType(type);
            IPage page = this.getPageManager().getDraftPage(this.getPageCode());
            page.getWidgets()[this.getFramePos()] = widget;
            this.getPageManager().updatePage(page);
            return "replaceOnPage";
        }
    } catch (Throwable t) {
        _logger.error("error in saveUserWidget", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 30 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class WidgetTypeAction method checkDeleteWidgetType.

private String checkDeleteWidgetType() {
    try {
        List<IPage> utilizers = new ArrayList<>();
        String check = this.checkWidgetType();
        if (null != check) {
            return check;
        }
        WidgetType type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
        if (type.isLocked()) {
            this.addActionError(this.getText("error.widgetType.locked.undeletable", new String[] { this.getWidgetTypeCode() }));
            return "inputWidgetTypes";
        }
        List<IPage> draftUtilizers = this.getPageManager().getDraftWidgetUtilizers(this.getWidgetTypeCode());
        if (null != draftUtilizers && draftUtilizers.size() > 0) {
            utilizers.addAll(draftUtilizers);
        }
        List<IPage> onlineUtilizers = this.getPageManager().getOnlineWidgetUtilizers(this.getWidgetTypeCode());
        if (null != onlineUtilizers && onlineUtilizers.size() > 0) {
            utilizers.addAll(onlineUtilizers);
        }
        if (utilizers.size() > 0) {
            this.addActionError(this.getText("error.widgetType.used.undeletable", new String[] { this.getWidgetTypeCode() }));
            return "inputWidgetTypes";
        }
    } catch (Throwable t) {
        _logger.error("Error on checking delete operatione : widget type code {}", this.getWidgetTypeCode(), t);
        throw new RuntimeException("Error on checking delete operatione : widget type code " + this.getWidgetTypeCode(), t);
    }
    return null;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Aggregations

WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)70 ApsProperties (com.agiletec.aps.util.ApsProperties)33 Widget (com.agiletec.aps.system.services.page.Widget)20 IPage (com.agiletec.aps.system.services.page.IPage)11 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)10 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 WidgetTypeParameter (org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter)5 ActionSupport (com.opensymphony.xwork2.ActionSupport)4 IManager (com.agiletec.aps.system.common.IManager)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Lang (com.agiletec.aps.system.services.lang.Lang)3 List (java.util.List)3 JAXBGuiFragment (org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)3 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)3 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)2 SelectItem (com.agiletec.aps.util.SelectItem)2 Properties (java.util.Properties)2 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)2