Search in sources :

Example 16 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class TestPageModelAction method testValidate_2.

public void testValidate_2() throws Throwable {
    String testPageModelCode = "internal";
    PageModel model = this._pageModelManager.getPageModel(testPageModelCode);
    assertNotNull(model);
    try {
        this.setUserOnSession("admin");
        this.initAction("/do/PageModel", "save");
        super.addParameter("code", testPageModelCode);
        super.addParameter("description", "Description");
        super.addParameter("strutsAction", ApsAdminSystemConstants.ADD);
        String result = this.executeAction();
        ActionSupport action = super.getAction();
        assertEquals(Action.INPUT, result);
        assertEquals(3, action.getFieldErrors().size());
        assertNotNull(action.getFieldErrors().get("code"));
        assertNotNull(action.getFieldErrors().get("template"));
        assertNotNull(action.getFieldErrors().get("xmlConfiguration"));
    } catch (Exception e) {
        this._pageModelManager.updatePageModel(model);
        throw e;
    }
}
Also used : ActionSupport(com.opensymphony.xwork2.ActionSupport) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Example 17 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageModelAction method updateSketch.

/**
 * Updates the sketch info.
 * The body format must be the same returned by /do/rs/PageModel/frames?code=code
 * @return 200 - the page model xml representation, updated with the sketch info provided;
 */
@SuppressWarnings("unchecked")
public String updateSketch() {
    try {
        PageModel pageModel = this.getPageModelManager().getPageModel(this.getCode());
        if (null != pageModel) {
            String payload = getBody(this.getRequest());
            if (StringUtils.isNotBlank(payload)) {
                List<Object> list = (List<Object>) JSONUtil.deserialize(payload);
                Iterator<Object> it = list.iterator();
                while (it.hasNext()) {
                    Map<String, Object> framemap = (Map<String, Object>) it.next();
                    Long posVal = (Long) framemap.get("pos");
                    Map<String, Object> sketchMap = (Map<String, Object>) framemap.get("sketch");
                    if (null != sketchMap) {
                        Number x1 = (Number) sketchMap.get("x1");
                        Number y1 = (Number) sketchMap.get("y1");
                        Number x2 = (Number) sketchMap.get("x2");
                        Number y2 = (Number) sketchMap.get("y2");
                        FrameSketch fs = new FrameSketch();
                        fs.setCoords(x1.intValue(), y1.intValue(), x2.intValue(), y2.intValue());
                        if (null != pageModel.getFrameConfig(posVal.intValue())) {
                            pageModel.getFrameConfig(posVal.intValue()).setSketch(fs);
                        }
                    }
                }
                this.getPageModelManager().updatePageModel(pageModel);
                String xml = new PageModelDOM(pageModel).getXMLDocument();
                this._response.getWriter().write(xml);
                this._response.setStatus(HttpStatus.OK.value());
                return Action.NONE;
            }
        }
    } catch (Throwable t) {
        _logger.error("error in updateSketch", t);
        this._response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return Action.NONE;
    }
    this._response.setStatus(HttpStatus.NOT_ACCEPTABLE.value());
    return Action.NONE;
}
Also used : PageModelDOM(com.agiletec.aps.system.services.pagemodel.PageModelDOM) FrameSketch(com.agiletec.aps.system.services.pagemodel.FrameSketch) List(java.util.List) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Map(java.util.Map)

Example 18 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageAction method setDefaultWidgets.

public String setDefaultWidgets() {
    Page page = null;
    try {
        page = (Page) this.getPage(this.getPageCode());
        PageModel model = page.getMetadata().getModel();
        Widget[] defaultWidgets = model.getDefaultWidget();
        if (null == defaultWidgets) {
            _logger.info("No default Widget found for pagemodel '{}' of page '{}'", model.getCode(), page.getCode());
            return SUCCESS;
        }
        Widget[] widgets = new Widget[defaultWidgets.length];
        for (int i = 0; i < defaultWidgets.length; i++) {
            Widget defaultWidget = defaultWidgets[i];
            if (null != defaultWidget) {
                if (null == defaultWidget.getType()) {
                    _logger.info("Widget Type null when adding defaulWidget (of pagemodel '{}') on frame '{}' of page '{}'", model.getCode(), i, page.getCode());
                    continue;
                }
                widgets[i] = defaultWidget;
            }
        }
        page.setWidgets(widgets);
        this.getPageManager().updatePage(page);
    } catch (Throwable t) {
        _logger.error("Error setting default widget to page {}", page.getCode(), t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) 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 19 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageAction method valueMetadataFromForm.

private void valueMetadataFromForm(PageMetadata metadata) {
    if (metadata.getModel() == null || !metadata.getModel().getCode().equals(this.getModel())) {
        // Ho cambiato modello e allora cancello tutte le showlets
        // Precedenti
        PageModel model = this.getPageModelManager().getPageModel(this.getModel());
        metadata.setModel(model);
    }
    metadata.setShowable(this.isShowable());
    metadata.setUseExtraTitles(this.isUseExtraTitles());
    metadata.setTitles(this.getTitles());
    metadata.setExtraGroups(this.getExtraGroups());
    String charset = this.getCharset();
    metadata.setCharset(StringUtils.isNotBlank(charset) ? charset : null);
    String mimetype = this.getMimeType();
    metadata.setMimeType(StringUtils.isNotBlank(mimetype) ? mimetype : null);
}
Also used : PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Example 20 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageAction method getUpdatedPage.

protected IPage getUpdatedPage() throws ApsSystemException {
    Page page = null;
    try {
        page = (Page) this.getPage(this.getPageCode());
        page.setGroup(this.getGroup());
        PageMetadata metadata = page.getMetadata();
        if (metadata == null) {
            metadata = new PageMetadata();
            page.setMetadata(metadata);
        }
        PageModel oldModel = metadata.getModel();
        this.valueMetadataFromForm(metadata);
        if (oldModel == null || !oldModel.getCode().equals(this.getModel())) {
            // The model is changed, so I drop all the previous widgets
            page.setWidgets(new Widget[metadata.getModel().getFrames().length]);
        }
    // if (this.isDefaultShowlet()) {
    // this.setDefaultWidgets(page);
    // }
    } catch (Throwable t) {
        _logger.error("Error updating page", t);
        throw new ApsSystemException("Error updating page", t);
    }
    return page;
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Aggregations

PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)47 IPage (com.agiletec.aps.system.services.page.IPage)13 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)11 Page (com.agiletec.aps.system.services.page.Page)10 Widget (com.agiletec.aps.system.services.page.Widget)10 ApsProperties (com.agiletec.aps.util.ApsProperties)10 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)7 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)6 Frame (com.agiletec.aps.system.services.pagemodel.Frame)5 Map (java.util.Map)5 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)5 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)5 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 IPageModelManager (com.agiletec.aps.system.services.pagemodel.IPageModelManager)4 PageModelDOM (com.agiletec.aps.system.services.pagemodel.PageModelDOM)4 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)4