Search in sources :

Example 6 with WidgetConfigurationDto

use of org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto in project entando-core by entando.

the class PageServiceWidgetIntegrationTest method testRemovePageWidget.

public void testRemovePageWidget() throws JsonProcessingException, ApsSystemException {
    String pageCode = "temp001";
    IPage parentPage = pageManager.getDraftRoot();
    PageModel pageModel = parentPage.getMetadata().getModel();
    PageMetadata metadata = PageTestUtil.createPageMetadata(pageModel.getCode(), true, pageCode, null, null, false, null, null);
    Page pageToAdd = PageTestUtil.createPage(pageCode, parentPage, "free", metadata, null);
    try {
        pageManager.addPage(pageToAdd);
        WidgetConfigurationDto widgetConfigurationDto = this.pageService.getWidgetConfiguration(pageToAdd.getCode(), 0, IPageService.STATUS_DRAFT);
        assertThat(widgetConfigurationDto, is(nullValue()));
        WidgetConfigurationRequest widgetConfigurationRequest = new WidgetConfigurationRequest();
        widgetConfigurationRequest.setCode("login_form");
        widgetConfigurationRequest.setConfig(null);
        this.pageService.updateWidgetConfiguration(pageCode, 0, widgetConfigurationRequest);
        assertThat(this.pageService.getWidgetConfiguration(pageToAdd.getCode(), 0, IPageService.STATUS_DRAFT).getCode(), is("login_form"));
        this.pageService.deleteWidgetConfiguration(pageToAdd.getCode(), 0);
        assertThat(widgetConfigurationDto, is(nullValue()));
    } finally {
        pageManager.deletePage(pageCode);
    }
}
Also used : WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Example 7 with WidgetConfigurationDto

use of org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto in project entando-core by entando.

the class PageService method updateWidgetConfiguration.

@Override
public WidgetConfigurationDto updateWidgetConfiguration(String pageCode, int frameId, WidgetConfigurationRequest widgetReq) {
    try {
        IPage page = this.loadPage(pageCode, STATUS_DRAFT);
        if (null == page) {
            throw new RestRourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
        }
        if (frameId > page.getWidgets().length) {
            throw new RestRourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
        }
        if (null == this.getWidgetType(widgetReq.getCode())) {
            throw new RestRourceNotFoundException(ERRCODE_WIDGET_INVALID, "widget", String.valueOf(widgetReq.getCode()));
        }
        BeanPropertyBindingResult validation = this.getWidgetValidatorFactory().get(widgetReq.getCode()).validate(widgetReq, page);
        if (null != validation && validation.hasErrors()) {
            throw new ValidationConflictException(validation);
        }
        ApsProperties properties = (ApsProperties) this.getWidgetProcessorFactory().get(widgetReq.getCode()).buildConfiguration(widgetReq);
        WidgetType widgetType = this.getWidgetType(widgetReq.getCode());
        Widget widget = new Widget();
        widget.setType(widgetType);
        widget.setConfig(properties);
        this.getPageManager().joinWidget(pageCode, widget, frameId);
        ApsProperties outProperties = this.getWidgetProcessorFactory().get(widgetReq.getCode()).extractConfiguration(widget.getConfig());
        return new WidgetConfigurationDto(widget.getType().getCode(), outProperties);
    } catch (ApsSystemException e) {
        logger.error("Error in update widget configuration {}", pageCode, e);
        throw new RestServerError("error in update widget configuration", e);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) IPage(com.agiletec.aps.system.services.page.IPage) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)7 IPage (com.agiletec.aps.system.services.page.IPage)5 Page (com.agiletec.aps.system.services.page.Page)2 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)2 Widget (com.agiletec.aps.system.services.page.Widget)2 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)2 HashMap (java.util.HashMap)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)2 RestResponse (org.entando.entando.web.common.model.RestResponse)2 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 ApsProperties (com.agiletec.aps.util.ApsProperties)1 RestServerError (org.entando.entando.aps.system.exception.RestServerError)1 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)1 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1