Search in sources :

Example 61 with Widget

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));
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 62 with Widget

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

Example 63 with Widget

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()]));
}
Also used : ArrayList(java.util.ArrayList) Widget(com.agiletec.aps.system.services.page.Widget)

Example 64 with Widget

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));
    }
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget)

Example 65 with Widget

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);
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget)

Aggregations

Widget (com.agiletec.aps.system.services.page.Widget)117 ApsProperties (com.agiletec.aps.util.ApsProperties)60 IPage (com.agiletec.aps.system.services.page.IPage)41 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)20 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)17 HashMap (java.util.HashMap)12 Lang (com.agiletec.aps.system.services.lang.Lang)10 Page (com.agiletec.aps.system.services.page.Page)7 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)7 ArrayList (java.util.ArrayList)7 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)6 NavigatorExpression (com.agiletec.aps.system.services.page.widget.NavigatorExpression)6 Properties (java.util.Properties)6 RequestContext (com.agiletec.aps.system.RequestContext)5 ActionSupport (com.opensymphony.xwork2.ActionSupport)4 JspException (javax.servlet.jsp.JspException)4 WidgetTypeParameter (org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter)4 List (java.util.List)3 ServletRequest (javax.servlet.ServletRequest)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3