Search in sources :

Example 31 with GuiFragment

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

the class WidgetTypeManager method deleteWidgetType.

@Override
public void deleteWidgetType(String widgetTypeCode) throws ApsSystemException {
    List<GuiFragment> deletedFragments = new ArrayList<GuiFragment>();
    try {
        WidgetType type = this.getWidgetType(widgetTypeCode);
        if (null == type) {
            logger.error("Type not exists : type code {}", widgetTypeCode);
            return;
        }
        if (type.isLocked()) {
            logger.error("A locked widget can't be deleted - type {}", widgetTypeCode);
            return;
        }
        List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
        if (null != fragmentCodes) {
            for (int i = 0; i < fragmentCodes.size(); i++) {
                String fragmentCode = fragmentCodes.get(i);
                GuiFragment fragmentToDelete = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
                deletedFragments.add(fragmentToDelete);
                this.getGuiFragmentManager().deleteGuiFragment(fragmentCode);
            }
        }
        this.getWidgetTypeDAO().deleteWidgetType(widgetTypeCode);
        this.getCacheWrapper().deleteWidgetType(widgetTypeCode);
        this.notifyWidgetTypeChanging(widgetTypeCode, WidgetTypeChangedEvent.REMOVE_OPERATION_CODE);
    } catch (Throwable t) {
        for (int i = 0; i < deletedFragments.size(); i++) {
            GuiFragment guiFragment = deletedFragments.get(i);
            if (null == this.getGuiFragmentManager().getGuiFragment(guiFragment.getCode())) {
                this.getGuiFragmentManager().addGuiFragment(guiFragment);
            }
        }
        logger.error("Error deleting widget type", t);
        throw new ApsSystemException("Error deleting widget type", t);
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 32 with GuiFragment

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

the class WidgetTypeManager method getGuiFragmentUtilizers.

@Override
public List getGuiFragmentUtilizers(String guiFragmentCode) throws ApsSystemException {
    List<WidgetType> utilizers = new ArrayList<WidgetType>();
    try {
        FieldSearchFilter codeFilter = new FieldSearchFilter("code", guiFragmentCode, false);
        FieldSearchFilter widgetTypeFilter = new FieldSearchFilter("widgettypecode");
        FieldSearchFilter[] filters = { codeFilter, widgetTypeFilter };
        List<String> widgetUtilizers = this.getGuiFragmentManager().searchGuiFragments(filters);
        if (null != widgetUtilizers && !widgetUtilizers.isEmpty()) {
            for (int i = 0; i < widgetUtilizers.size(); i++) {
                String code = widgetUtilizers.get(i);
                GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(code);
                WidgetType widgetType = this.getWidgetType(fragment.getWidgetTypeCode());
                if (null != widgetType) {
                    utilizers.add(widgetType);
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error extracting utilizers", t);
        throw new ApsSystemException("Error extracting utilizers", t);
    }
    return utilizers;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 33 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment 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 34 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment 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 35 with GuiFragment

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

the class GuiFragmentTag method extractFragmentOutput.

protected String extractFragmentOutput(RequestContext reqCtx) throws ApsSystemException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, this.pageContext);
        GuiFragment guiFragment = guiFragmentManager.getGuiFragment(this.getCode());
        if (null == guiFragment || StringUtils.isBlank(guiFragment.getCurrentGui())) {
            return null;
        }
        ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
        Writer out = new OutputStreamWriter(baos);
        Template template = new Template(this.getCode(), new StringReader(guiFragment.getCurrentGui()), ebc.getConfiguration());
        template.process(ebc.getTemplateModel(), out);
        out.flush();
    } catch (Throwable t) {
        String msg = "Error creating fragment output - code '" + this.getCode() + "'";
        _logger.error(msg, t);
        throw new ApsSystemException(msg, t);
    }
    return baos.toString();
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) StringReader(java.io.StringReader) OutputStreamWriter(java.io.OutputStreamWriter) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Template(freemarker.template.Template)

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