use of com.agiletec.aps.system.services.pagemodel.PageModelDOM in project entando-core by entando.
the class TestPageModelAction method testSave.
public void testSave() throws Throwable {
String testPageModelCode = "test_pagemodel";
assertNull(this._pageModelManager.getPageModel(testPageModelCode));
try {
PageModel mockModel = this.createMockPageModel(testPageModelCode);
this.setUserOnSession("admin");
this.initAction("/do/PageModel", "save");
super.addParameter("code", mockModel.getCode());
super.addParameter("description", mockModel.getDescription());
super.addParameter("template", mockModel.getTemplate());
PageModelDOM dom = new PageModelDOM(mockModel);
super.addParameter("xmlConfiguration", dom.getXMLDocument());
super.addParameter("strutsAction", ApsAdminSystemConstants.ADD);
String result = this.executeAction();
assertEquals(Action.SUCCESS, result);
assertNotNull(this._pageModelManager.getPageModel(testPageModelCode));
} catch (Exception e) {
throw e;
} finally {
this._pageModelManager.deletePageModel(testPageModelCode);
assertNull(this._pageModelManager.getPageModel(testPageModelCode));
}
}
use of com.agiletec.aps.system.services.pagemodel.PageModelDOM in project entando-core by entando.
the class PageModelAction method checkModelConfiguration.
private boolean checkModelConfiguration() throws Throwable {
try {
String xml = this.getXmlConfiguration();
PageModelDOM dom = new PageModelDOM(xml, this.getWidgetTypeManager());
Frame[] configuration = dom.getConfiguration();
return true;
} catch (Exception e) {
return false;
}
}
use of com.agiletec.aps.system.services.pagemodel.PageModelDOM 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;
}
use of com.agiletec.aps.system.services.pagemodel.PageModelDOM in project entando-core by entando.
the class PageModelAction method extractPageModelFormValues.
protected String extractPageModelFormValues() {
try {
PageModel pageModel = super.getPageModel(this.getCode());
if (null == pageModel) {
this.addActionError(this.getText("error.pageModel.notExist"));
return "pageModelList";
}
this.setDescription(pageModel.getDescription());
this.setPluginCode(pageModel.getPluginCode());
// TO DELETE - start
if (null != pageModel.getConfiguration()) {
PageModelDOM dom = new PageModelDOM(pageModel);
String xml = dom.getXMLDocument();
this.setXmlConfiguration(xml);
}
// TO DELETE - end
this.setTemplate(pageModel.getTemplate());
} catch (Throwable t) {
_logger.error("error in extractPageModelFormValues", t);
return FAILURE;
}
return SUCCESS;
}
use of com.agiletec.aps.system.services.pagemodel.PageModelDOM in project entando-core by entando.
the class PageModelAction method createPageModel.
protected PageModel createPageModel() throws Throwable {
PageModel model = null;
try {
if (ApsAdminSystemConstants.ADD == this.getStrutsAction()) {
model = new PageModel();
model.setCode(this.getCode());
} else {
model = this.getPageModel(this.getCode());
}
model.setDescription(this.getDescription());
String template = (!StringUtils.isBlank(this.getTemplate())) ? this.getTemplate() : null;
model.setTemplate(template);
// TO DELETE - start
String xml = this.getXmlConfiguration();
PageModelDOM dom = new PageModelDOM(xml, this.getWidgetTypeManager());
Frame[] configuration = dom.getConfiguration();
int mainFrame = dom.getMainFrame();
if (mainFrame > -1) {
model.setMainFrame(mainFrame);
}
model.setConfiguration(configuration);
// TO DELETE - end
} catch (Throwable t) {
_logger.error("error in creating page model", t);
throw t;
}
return model;
}
Aggregations