Search in sources :

Example 1 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class WidgetTypeDAO method createWidgetTypeFromResultSet.

protected WidgetType createWidgetTypeFromResultSet(ResultSet res) throws ApsSystemException {
    WidgetType widgetType = new WidgetType();
    String code = null;
    try {
        code = res.getString(1);
        widgetType.setCode(code);
        String xmlTitles = res.getString(2);
        ApsProperties titles = new ApsProperties();
        titles.loadFromXml(xmlTitles);
        widgetType.setTitles(titles);
        String xml = res.getString(3);
        if (null != xml && xml.trim().length() > 0) {
            WidgetTypeDOM showletTypeDom = new WidgetTypeDOM(xml, this.getLangManager().getLangs());
            widgetType.setTypeParameters(showletTypeDom.getParameters());
            widgetType.setAction(showletTypeDom.getAction());
        }
        widgetType.setPluginCode(res.getString(4));
        widgetType.setParentTypeCode(res.getString(5));
        String config = res.getString(6);
        if (null != config && config.trim().length() > 0) {
            ApsProperties defaultConfig = new ApsProperties();
            defaultConfig.loadFromXml(config);
            widgetType.setConfig(defaultConfig);
        }
        if ((null != widgetType.getConfig() && null == widgetType.getParentTypeCode())) {
            throw new ApsSystemException("Default configuration found in the type '" + code + "' with no parent type assigned");
        }
        int isLocked = res.getInt(7);
        widgetType.setLocked(isLocked == 1);
        String mainGroup = res.getString(8);
        if (null != mainGroup && mainGroup.trim().length() > 0) {
            widgetType.setMainGroup(mainGroup.trim());
        }
    } catch (Throwable t) {
        logger.error("Error parsing the Widget Type '{}'", code, t);
        throw new ApsSystemException("Error in the parsing in the Widget Type '" + code + "'", t);
    }
    return widgetType;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 2 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class WidgetTypeManager method addWidgetType.

@Override
public void addWidgetType(WidgetType widgetType) throws ApsSystemException {
    try {
        if (null == widgetType) {
            logger.error("Null Widget Type");
            return;
        }
        WidgetType type = this.getWidgetType(widgetType.getCode());
        if (null != type) {
            logger.error("Type already exists : type code {}", widgetType.getCode());
            return;
        }
        String parentTypeCode = widgetType.getParentTypeCode();
        if (null != parentTypeCode && null == this.getWidgetType(parentTypeCode)) {
            throw new ApsSystemException("ERROR : Parent type '" + parentTypeCode + "' doesn't exists");
        }
        if (null == parentTypeCode && null != widgetType.getConfig()) {
            throw new ApsSystemException("ERROR : Parent type null and default config not null");
        }
        if (null != widgetType.getTypeParameters() && null != widgetType.getConfig()) {
            throw new ApsSystemException("ERROR : Params not null and config not null");
        }
        this.getWidgetTypeDAO().addWidgetType(widgetType);
        this.getCacheWrapper().addWidgetType(widgetType);
        this.notifyWidgetTypeChanging(widgetType.getCode(), WidgetTypeChangedEvent.INSERT_OPERATION_CODE);
    } catch (Throwable t) {
        logger.error("Error adding a Widget Type", t);
        throw new ApsSystemException("Error adding a Widget Type", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 3 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class WidgetTypeManager method getWidgetTypes.

@Override
public SearcherDaoPaginatedResult<WidgetType> getWidgetTypes(List<FieldSearchFilter> fieldSearchFilters) throws ApsSystemException {
    SearcherDaoPaginatedResult<WidgetType> pagedResult = null;
    try {
        List<WidgetType> widgets = new ArrayList<>();
        FieldSearchFilter[] array = null;
        if (null != fieldSearchFilters) {
            array = fieldSearchFilters.toArray(new FieldSearchFilter[fieldSearchFilters.size()]);
        }
        int count = this.getWidgetTypeDAO().countWidgetTypes(array);
        List<String> widgetCodes = this.getWidgetTypeDAO().searchWidgetTypes(array);
        for (String widgetCode : widgetCodes) {
            widgets.add(this.getWidgetType(widgetCode));
        }
        pagedResult = new SearcherDaoPaginatedResult<>(count, widgets);
    } catch (Throwable t) {
        logger.error("Error searching groups", t);
        throw new ApsSystemException("Error searching groups", t);
    }
    return pagedResult;
}
Also used : ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 4 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiWidgetTypeInterface method checkAndSaveFragment.

protected void checkAndSaveFragment(WidgetType type, JAXBWidgetType jaxbWidgetType, boolean isAdd, StringApiResponse response, List<GuiFragment> addedFragments, List<GuiFragment> updatedFragment) throws Throwable {
    try {
        if (!type.isLogic() && !this.isInternalServletWidget(type.getCode())) {
            GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(type.getCode());
            if (StringUtils.isNotBlank(jaxbWidgetType.getGui())) {
                if (null == guiFragment) {
                    guiFragment = new GuiFragment();
                    String code = this.extractUniqueGuiFragmentCode(type.getCode());
                    guiFragment.setCode(code);
                    guiFragment.setPluginCode(type.getPluginCode());
                    guiFragment.setGui(jaxbWidgetType.getGui());
                    guiFragment.setWidgetTypeCode(type.getCode());
                    addedFragments.add(guiFragment);
                    this.getGuiFragmentManager().addGuiFragment(guiFragment);
                } else if (!isAdd) {
                    GuiFragment clone = guiFragment.clone();
                    updatedFragment.add(guiFragment);
                    clone.setGui(jaxbWidgetType.getGui());
                    this.getGuiFragmentManager().updateGuiFragment(clone);
                }
            } else {
                if (null != guiFragment && !isAdd) {
                    if (StringUtils.isNotBlank(guiFragment.getDefaultGui())) {
                        GuiFragment clone = guiFragment.clone();
                        updatedFragment.add(guiFragment);
                        clone.setGui(null);
                        this.getGuiFragmentManager().updateGuiFragment(clone);
                    } else {
                    // nothing to do...
                    // this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
                    }
                }
            }
        } else if (type.isLogic() && !isAdd) {
            boolean isInternalServlet = this.isInternalServletWidget(type.getParentType().getCode());
            if (!isInternalServlet && (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0)) {
                if (null != response) {
                    ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Fragments mustn't be updated on a 'not internal servlet' logic widget type");
                    response.addError(error);
                }
            // throw new
            // ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
            // "Fragments mustn't be updated on a 'not internal servlet'
            // logic widget type", Response.Status.CONFLICT);
            } else {
                List<JAXBGuiFragment> fragments = jaxbWidgetType.getFragments();
                if (null != fragments && fragments.size() > 0) {
                    for (int i = 0; i < fragments.size(); i++) {
                        JAXBGuiFragment jaxbGuiFragment = fragments.get(i);
                        GuiFragment fragment = jaxbGuiFragment.getGuiFragment();
                        GuiFragment existingFragment = this.getGuiFragmentManager().getGuiFragment(fragment.getCode());
                        if (null != existingFragment) {
                            if (StringUtils.isBlank(existingFragment.getDefaultGui()) && StringUtils.isBlank(jaxbWidgetType.getGui())) {
                                ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued on fragment '" + existingFragment.getCode() + "'");
                                response.addError(error);
                                continue;
                            }
                            GuiFragment clone = existingFragment.clone();
                            updatedFragment.add(existingFragment);
                            clone.setGui(jaxbGuiFragment.getGui());
                        } else {
                            ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment '" + fragment.getCode() + "' does not exists");
                            response.addError(error);
                        }
                    }
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("error checking and saving fragment", t);
        throw new ApsSystemException("error checking and saving fragment", 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) List(java.util.List) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 5 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class WidgetTypeManagerCacheWrapper method initCache.

@Override
public void initCache(IWidgetTypeDAO widgetTypeDAO) throws ApsSystemException {
    try {
        Cache cache = this.getCache();
        this.releaseCachedObjects(cache);
        Map<String, WidgetType> widgetTypes = widgetTypeDAO.loadWidgetTypes();
        Iterator<WidgetType> iter = widgetTypes.values().iterator();
        while (iter.hasNext()) {
            WidgetType type = iter.next();
            String mainTypeCode = type.getParentTypeCode();
            if (null != mainTypeCode) {
                type.setParentType(widgetTypes.get(mainTypeCode));
            }
        }
        this.insertObjectsOnCache(cache, widgetTypes);
    } catch (Throwable t) {
        _logger.error("Error loading widgets types", t);
        throw new ApsSystemException("Error loading widgets types", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) Cache(org.springframework.cache.Cache)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15