Search in sources :

Example 26 with GuiFragment

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

the class GuiFragmentDtoBuilder method toDto.

@Override
protected GuiFragmentDto toDto(GuiFragment src) {
    if (null == src) {
        return null;
    }
    WidgetType type = null;
    if (StringUtils.isNotEmpty(src.getWidgetTypeCode())) {
        type = this.getWidgetTypeManager().getWidgetType(src.getWidgetTypeCode());
    }
    GuiFragmentDto dest = new GuiFragmentDto(src, type, langManager);
    ListableBeanFactory factory = (ListableBeanFactory) this.beanFactory;
    String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
    for (String defName : defNames) {
        GuiFragmentUtilizer utilizers = null;
        try {
            utilizers = this.beanFactory.getBean(defName, GuiFragmentUtilizer.class);
            List<Object> references = utilizers.getGuiFragmentUtilizers(src.getCode());
            if (null != references) {
                for (Object reference : references) {
                    if (reference instanceof GuiFragment) {
                        dest.addFragmentRef((GuiFragment) reference);
                    } else if (reference instanceof PageModel) {
                        dest.addPageModelRef((PageModel) reference);
                    } else {
                        logger.info("unexpected reference - type {}", reference.getClass());
                    }
                }
            }
        } catch (Throwable t) {
            logger.error("Error extracting reference from bean '{}'", defName);
            utilizers = null;
        }
    }
    return dest;
}
Also used : GuiFragmentUtilizer(org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 27 with GuiFragment

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

the class ApiGuiFragmentInterface method updateGuiFragment.

public void updateGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
    try {
        if (null == this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + jaxbGuiFragment.getCode() + "' does not exist", Response.Status.CONFLICT);
        }
        GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
        if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
        }
        this.getGuiFragmentManager().updateGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating fragment", t);
        throw t;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 28 with GuiFragment

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

the class ApiGuiFragmentInterface method deleteGuiFragment.

public void deleteGuiFragment(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    try {
        GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
        if (null == guiFragment) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' does not exist", Response.Status.CONFLICT);
        }
        if (guiFragment.isLocked()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' are locked", Response.Status.CONFLICT);
        }
        Map<String, List<Object>> references = new HashMap<String, List<Object>>();
        ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
        String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = this.getBeanFactory().getBean(defNames[i]);
            } catch (Throwable t) {
                _logger.error("error extracting bean with name '{}'", defNames[i], t);
                throw new ApsSystemException("error extracting bean with name '" + defNames[i] + "'", t);
            }
            if (service != null) {
                GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service;
                List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(code);
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(guiFragUtilizer.getName(), utilizers);
                }
            }
        }
        if (!references.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + code + " has references with other object", Response.Status.CONFLICT);
        }
        this.getGuiFragmentManager().deleteGuiFragment(code);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting fragment throw api", t);
        throw t;
    }
}
Also used : GuiFragmentUtilizer(org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer) HashMap(java.util.HashMap) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ArrayList(java.util.ArrayList) List(java.util.List) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 29 with GuiFragment

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

the class WidgetService method addFragments.

private void addFragments(WidgetDto widgetDto) throws Exception {
    List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetDto.getCode());
    if (fragmentCodes != null) {
        for (String fragmentCode : fragmentCodes) {
            GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
            widgetDto.addGuiFragmentRef(fragment.getCode(), fragment.getCurrentGui(), fragment.getDefaultGui());
        }
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment)

Example 30 with GuiFragment

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

the class WidgetService method createAndAddFragment.

private void createAndAddFragment(WidgetType widgetType, WidgetRequest widgetRequest) throws Exception {
    GuiFragment guiFragment = new GuiFragment();
    String code = this.extractUniqueGuiFragmentCode(widgetType.getCode());
    guiFragment.setCode(code);
    guiFragment.setPluginCode(widgetType.getPluginCode());
    guiFragment.setGui(widgetRequest.getCustomUi());
    guiFragment.setWidgetTypeCode(widgetType.getCode());
    this.getGuiFragmentManager().addGuiFragment(guiFragment);
}
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