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