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);
}
}
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);
}
}
Aggregations