Search in sources :

Example 6 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(), widgetTypeToUpdate.getConfigUi(), widgetTypeToUpdate.getBundleId());
    }
    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 7 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(), widgetType.getConfigUi(), widgetType.getBundleId());
        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 8 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 9 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 ResourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
    }
    WidgetDto widgetDto = null;
    try {
        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);
        }
        if (type.isUserType() && StringUtils.isBlank(widgetRequest.getCustomUi()) && !WidgetType.existsJsp(this.srvCtx, widgetCode, widgetCode)) {
            BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
            bindingResult.reject(WidgetValidator.ERRCODE_NOT_BLANK, new String[] { type.getCode() }, "widgettype.customUi.notBlank");
            throw new ValidationGenericException(bindingResult);
        }
        this.processWidgetType(type, widgetRequest);
        widgetDto = dtoBuilder.convert(type);
        this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup(), type.getConfigUi(), type.getBundleId());
        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 (ValidationGenericException vge) {
        logger.error("Found an error on validation, throwing original exception", vge);
        throw vge;
    } catch (Throwable e) {
        logger.error("failed to update widget type", e);
        throw new RestServerError("Failed to update widget", e);
    }
    return widgetDto;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 10 with GuiFragment

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

the class WidgetTypeAction method checkGui.

private boolean checkGui() throws Throwable {
    if (this.getStrutsAction() == NEW_USER_WIDGET || this.getStrutsAction() == ApsAdminSystemConstants.PASTE) {
        return true;
    }
    boolean isValuedGui = StringUtils.isNotBlank(this.getGui());
    if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
        return isValuedGui;
    }
    if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT) {
        throw new RuntimeException("Invalid Struts Action " + this.getStrutsAction());
    }
    WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
    if (type.isLogic() || this.isInternalServletWidget(this.getWidgetTypeCode())) {
        return true;
    }
    String pluginCode = type.getPluginCode();
    ServletContext srvCtx = this.getRequest().getSession().getServletContext();
    if (WidgetType.existsJsp(srvCtx, this.getWidgetTypeCode(), pluginCode)) {
        return true;
    }
    GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
    if (!isValuedGui && (guiFragment == null || StringUtils.isBlank(guiFragment.getDefaultGui()))) {
        return false;
    } else {
        return true;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ServletContext(javax.servlet.ServletContext) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

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