use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class TestApiWidgetTypeInterface method testDeleteJaxbWidgetType_3.
public void testDeleteJaxbWidgetType_3() throws Throwable {
String code = "jaxb_test_delete_2";
String pageCode = "homepage";
int frame = 5;
assertNull(this._widgetTypeManager.getWidgetType(code));
IPage homepage = this._pageManager.getDraftPage(pageCode);
assertNull(homepage.getWidgets()[frame]);
assertNull(homepage.getWidgets()[frame]);
try {
this.addMockWidget(code);
WidgetType addedWidgetType = this._widgetTypeManager.getWidgetType(code);
assertNotNull(addedWidgetType);
Widget widget = new Widget();
widget.setType(addedWidgetType);
this.setPageWidgets(pageCode, frame, widget);
homepage = this._pageManager.getDraftPage(pageCode);
this.testInvokeDeleteJaxbNoLogicWidgetType(code, false);
this.setPageWidgets(pageCode, frame, null);
this._pageManager.updatePage(homepage);
this.testInvokeDeleteJaxbNoLogicWidgetType(code, true);
} catch (Throwable t) {
this.setPageWidgets(pageCode, frame, null);
throw t;
} finally {
this._widgetTypeManager.deleteWidgetType(code);
assertNull(this._widgetTypeManager.getWidgetType(code));
}
}
use of com.agiletec.aps.system.services.page.Widget 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);
}
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class PageConfigurationDto method buildWidgetsDto.
protected void buildWidgetsDto(Widget[] widgets) {
if (null == widgets) {
return;
}
List<WidgetConfigurationDto> widgetDtoList = new ArrayList<>();
for (Widget widget : widgets) {
if (null == widget) {
widgetDtoList.add(null);
} else {
widgetDtoList.add(new WidgetConfigurationDto(widget.getType().getCode(), widget.getConfig()));
}
}
this.setWidgets(widgetDtoList.toArray(new WidgetConfigurationDto[widgetDtoList.size()]));
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class TestPageModelDAO method testAddRemoveModel.
public void testAddRemoveModel() throws Throwable {
Map<String, PageModel> models = this._pageModelDAO.loadModels();
String testPageModelCode = "test_pagemodel";
try {
assertTrue(!models.containsKey(testPageModelCode));
PageModel mockModel = this.createMockPageModel(testPageModelCode);
this._pageModelDAO.addModel(mockModel);
models = this._pageModelDAO.loadModels();
PageModel extractedMockModel = models.get(testPageModelCode);
assertNotNull(extractedMockModel);
assertEquals(testPageModelCode, extractedMockModel.getCode());
assertTrue(extractedMockModel.getDescription().contains(testPageModelCode));
assertEquals(3, extractedMockModel.getFrames().length);
Widget[] defaultWidgets = extractedMockModel.getDefaultWidget();
assertEquals(3, defaultWidgets.length);
Widget defWidg0 = defaultWidgets[0];
assertNull(defWidg0);
Widget defWidg1 = defaultWidgets[1];
assertNotNull(defWidg1);
assertEquals("content_viewer_list", defWidg1.getType().getCode());
assertEquals(1, defWidg1.getConfig().size());
assertEquals("ART", defWidg1.getConfig().get("contentType"));
Widget defWidg2 = defaultWidgets[2];
assertNotNull(defWidg2);
assertEquals("login_form", defWidg2.getType().getCode());
assertNull(defWidg2.getConfig());
assertEquals("<strong>Freemarker template content</strong>", extractedMockModel.getTemplate());
} catch (Exception e) {
throw e;
} finally {
this._pageModelDAO.deleteModel(testPageModelCode);
models = this._pageModelDAO.loadModels();
assertTrue(!models.containsKey(testPageModelCode));
}
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class TestPageModelManager method testGetPageModel.
public void testGetPageModel() throws ApsSystemException {
PageModel pageModel = this._pageModelManager.getPageModel("home");
String code = pageModel.getCode();
String descr = pageModel.getDescription();
assertEquals(code, "home");
assertEquals(descr, "Modello home page");
Widget[] widgets = pageModel.getDefaultWidget();
for (int i = 0; i < widgets.length; i++) {
Widget widget = widgets[i];
assertEquals(widget, null);
}
String[] frames = pageModel.getFrames();
assertEquals(frames[0], "Box sinistra alto");
int mainFrame = pageModel.getMainFrame();
assertEquals(mainFrame, 2);
}
Aggregations