Search in sources :

Example 36 with WidgetType

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

the class TestApiWidgetTypeInterface method testInvokeGetJaxbWidgetType.

private void testInvokeGetJaxbWidgetType(String widgetTypeCode) throws Throwable {
    Properties properties = new Properties();
    properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
    properties.put("code", widgetTypeCode);
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    try {
        JAXBWidgetType jaxbwt = this._apiWidgetTypeInterface.getWidgetType(properties);
        assertNotNull(jaxbwt);
        assertEquals(widgetTypeCode, jaxbwt.getCode());
        assertEquals(widgetType.getTitles(), jaxbwt.getTitles());
    } catch (ApiException ae) {
        if (null != widgetType) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    }
}
Also used : Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 37 with WidgetType

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

the class ApiWidgetTypeInterface method addWidgetType.

public void addWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
    List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
    List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
    try {
        WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
        if (null != widgetType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " already exists", Response.Status.CONFLICT);
        }
        widgetType = jaxbWidgetType.getNewWidgetType(this.getWidgetTypeManager());
        if (!widgetType.isLogic() && StringUtils.isBlank(jaxbWidgetType.getGui())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Gui is mandatory", Response.Status.CONFLICT);
        }
        if (widgetType.isLogic() && (StringUtils.isNotBlank(jaxbWidgetType.getGui()) || (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0))) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment mustn't be added on the new logic widget type", Response.Status.CONFLICT);
        }
        if (widgetType.isLogic() && this.isInternalServletWidget(widgetType.getParentType().getCode())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Logic type with parent 'Internal Servlet' widget mustn't be added", Response.Status.CONFLICT);
        }
        this.getWidgetTypeManager().addWidgetType(widgetType);
        if (!widgetType.isLogic()) {
            this.checkAndSaveFragment(widgetType, jaxbWidgetType, true, null, addedFragments, updatedFragments);
        }
    } catch (ApiException ae) {
        this.revertPreviousObject(null, addedFragments, updatedFragments);
        throw ae;
    } catch (Throwable t) {
        this.revertPreviousObject(null, addedFragments, updatedFragments);
        this.getWidgetTypeManager().deleteWidgetType(jaxbWidgetType.getCode());
        _logger.error("Error adding new widget type", t);
        throw t;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 38 with WidgetType

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

the class ApiWidgetTypeInterface method getWidgetType.

public JAXBWidgetType getWidgetType(Properties properties) throws ApiException, Throwable {
    String widgetTypeCode = properties.getProperty("code");
    JAXBWidgetType jaxbWidgetType = null;
    try {
        WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(widgetTypeCode);
        if (null == widgetType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code '" + widgetTypeCode + "' does not exist", Response.Status.CONFLICT);
        }
        GuiFragment singleGuiFragment = null;
        List<GuiFragment> fragments = new ArrayList<GuiFragment>();
        if (!widgetType.isLogic()) {
            singleGuiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetTypeCode);
        } else {
            List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
            if (null != fragmentCodes) {
                for (int i = 0; i < fragmentCodes.size(); i++) {
                    String fragmentCode = fragmentCodes.get(i);
                    GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
                    if (null != fragment) {
                        fragments.add(fragment);
                    }
                }
            }
        }
        jaxbWidgetType = new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error creating widget type - code '{}'", widgetTypeCode, t);
        throw t;
    }
    return jaxbWidgetType;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 39 with WidgetType

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

the class JAXBWidgetType method getModifiedWidgetType.

public WidgetType getModifiedWidgetType(IWidgetTypeManager widgetTypeManager) throws ApiException {
    WidgetType type = widgetTypeManager.getWidgetType(this.getCode());
    type.setTitles(this.getTitles());
    if (type.isLogic()) {
        ApsProperties configuration = this.getConfig();
        type.setConfig(configuration);
    } else {
        List<WidgetTypeParameter> parameters = this.getTypeParameters();
        if (null != parameters && !parameters.isEmpty()) {
            // type.setAction("configSimpleParameter");
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Parameters of existing widget mustn't been changed", Response.Status.CONFLICT);
        }
    }
    type.setMainGroup(this.getMainGroup());
    // type.setPluginCode(this.getPluginCode());
    return type;
}
Also used : WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetTypeParameter(org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 40 with WidgetType

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

the class ContentListViewerWidgetValidator method validateFilters.

protected void validateFilters(WidgetConfigurationRequest widget, BeanPropertyBindingResult errors) {
    WidgetType type = this.getWidgetTypeManager().getWidgetType(widget.getCode());
    Map<String, Object> config = (Map<String, Object>) widget.getConfig();
    if (null != config && null != type && type.hasParameter(WIDGET_CONFIG_KEY_CATEGORIES) && type.hasParameter(WIDGET_CONFIG_KEY_MAXELEMFORITEM) && type.hasParameter(WIDGET_CONFIG_KEY_MAXELEMENTS) && StringUtils.isNotEmpty((String) config.get(WIDGET_CONFIG_KEY_CONTENTTYPE)) && StringUtils.isEmpty((String) config.get(WIDGET_CONFIG_KEY_CATEGORIES)) && StringUtils.isEmpty((String) config.get(WIDGET_CONFIG_KEY_MAXELEMFORITEM)) && StringUtils.isEmpty((String) config.get(WIDGET_CONFIG_KEY_MAXELEMENTS))) {
        errors.reject(WidgetValidatorCmsHelper.ERRCODE_INVALID_CONFIGURATION, new String[] {}, WIDGET_CODE + ".parameters.invalid");
    }
}
Also used : WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) Map(java.util.Map)

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