Search in sources :

Example 1 with GuiFragment

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

the class ApiWidgetTypeInterface method updateWidgetType.

public StringApiResponse updateWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    WidgetType widgetTypeToUpdate = null;
    List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
    List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
    try {
        widgetTypeToUpdate = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
        if (null == widgetTypeToUpdate) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " does not exists", Response.Status.CONFLICT);
        }
        WidgetType widgetType = jaxbWidgetType.getModifiedWidgetType(this.getWidgetTypeManager());
        this.checkAndSaveFragment(widgetType, jaxbWidgetType, false, response, addedFragments, updatedFragments);
        this.getWidgetTypeManager().updateWidgetType(widgetType.getCode(), widgetType.getTitles(), widgetType.getConfig(), widgetType.getMainGroup());
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
        throw ae;
    } catch (Throwable t) {
        this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
        _logger.error("Error updating widget type", t);
        throw t;
    }
    return response;
}
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) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 2 with GuiFragment

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

the class ApiWidgetTypeInterface method revertPreviousObject.

private void revertPreviousObject(WidgetType widgetTypeToUpdate, List<GuiFragment> addedFragments, List<GuiFragment> updatedFragments) throws Throwable {
    if (null != widgetTypeToUpdate) {
        this.getWidgetTypeManager().updateWidgetType(widgetTypeToUpdate.getCode(), widgetTypeToUpdate.getTitles(), widgetTypeToUpdate.getConfig(), widgetTypeToUpdate.getMainGroup());
    }
    for (int i = 0; i < addedFragments.size(); i++) {
        GuiFragment guiFragment = addedFragments.get(i);
        this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
    }
    for (int i = 0; i < updatedFragments.size(); i++) {
        GuiFragment guiFragment = updatedFragments.get(i);
        this.getGuiFragmentManager().updateGuiFragment(guiFragment);
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)

Example 3 with GuiFragment

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

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

the class WidgetService method updateWidget.

@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
    WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
    if (type == null) {
        throw new RestRourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
    } else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
        BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
        bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
        throw new ValidationGenericException(bindingResult);
    }
    this.processWidgetType(type, widgetRequest);
    WidgetDto widgetDto = dtoBuilder.convert(type);
    try {
        this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup());
        if (!StringUtils.isEmpty(widgetCode)) {
            GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
            if (null == guiFragment) {
                this.createAndAddFragment(type, widgetRequest);
            } else {
                guiFragment.setGui(widgetRequest.getCustomUi());
                this.getGuiFragmentManager().updateGuiFragment(guiFragment);
            }
        }
        this.addFragments(widgetDto);
    } catch (Throwable e) {
        logger.error("failed to update widget type", e);
        throw new RestServerError("Failed to update widget", e);
    }
    return widgetDto;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 5 with GuiFragment

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

the class ApiGuiFragmentInterface method addGuiFragment.

public void addGuiFragment(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() + " already exists", 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().addGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error adding new 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)

Aggregations

GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)39 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 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 Test (org.junit.Test)2 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)2 MapBindingResult (org.springframework.validation.MapBindingResult)2 RequestContext (com.agiletec.aps.system.RequestContext)1