Search in sources :

Example 1 with GuiFragmentUtilizer

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

the class GuiFragmentActionHelper method getReferencingObjects.

@SuppressWarnings("unchecked")
@Override
public Map<String, List<Object>> getReferencingObjects(GuiFragment fragment, HttpServletRequest request) throws ApsSystemException {
    Map<String, List<Object>> references = new HashMap<String, List<Object>>();
    try {
        String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(GuiFragmentUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
            } catch (Throwable t) {
                _logger.error("error in hasReferencingObjects", t);
                service = null;
            }
            if (service != null) {
                GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service;
                List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(fragment.getCode());
                if (utilizers != null && !utilizers.isEmpty()) {
                    // FIXME UNIFORMARE E STUDIARE CHIAVE IDONEA
                    references.put(guiFragUtilizer.getName() + "Utilizers", utilizers);
                }
            }
        }
    } catch (Throwable t) {
        throw new ApsSystemException("Error in getReferencingObjects", t);
    }
    return references;
}
Also used : GuiFragmentUtilizer(org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer) HashMap(java.util.HashMap) List(java.util.List) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 2 with GuiFragmentUtilizer

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

use of org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer 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);
    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)

Aggregations

GuiFragmentUtilizer (org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)2 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)2 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)1 ArrayList (java.util.ArrayList)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)1