Search in sources :

Example 1 with JAXBGuiFragment

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

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)1 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)1 JAXBGuiFragment (org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)1