Search in sources :

Example 1 with FrameSketch

use of com.agiletec.aps.system.services.pagemodel.FrameSketch 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)

Aggregations

FrameSketch (com.agiletec.aps.system.services.pagemodel.FrameSketch)1 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)1 PageModelDOM (com.agiletec.aps.system.services.pagemodel.PageModelDOM)1 List (java.util.List)1 Map (java.util.Map)1