use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class TestPageModelManager method testAddRemoveModel.
public void testAddRemoveModel() throws Throwable {
String testPageModelCode = "test_pagemodel";
assertNull(this._pageModelManager.getPageModel(testPageModelCode));
try {
PageModel mockModel = this.createMockPageModel(testPageModelCode);
this._pageModelManager.addPageModel(mockModel);
PageModel extractedMockModel = this._pageModelManager.getPageModel(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._pageModelManager.deletePageModel(testPageModelCode);
assertNull(this._pageModelManager.getPageModel(testPageModelCode));
}
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class ContentMapperCacheWrapperTest method createMockWidget.
private Widget createMockWidget() {
Widget widget = new Widget();
WidgetType type = new WidgetType();
type.setCode("type");
WidgetTypeParameter param1 = new WidgetTypeParameter();
param1.setName("contentId");
WidgetTypeParameter param2 = new WidgetTypeParameter();
param2.setName("testParam");
List<WidgetTypeParameter> params = Arrays.asList(new WidgetTypeParameter[] { param1, param2 });
type.setTypeParameters(params);
widget.setType(type);
ApsProperties props = new ApsProperties();
props.put("contentId", "ART1");
props.put("testParam", "test");
widget.setConfig(props);
return widget;
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class ContentMapperCacheWrapperTest method createMockPage.
private IPage createMockPage() {
Page root = new Page();
root.setCode("root_code");
root.setModel(this.createMockPageModel());
root.setGroup(Group.FREE_GROUP_NAME);
Widget[] widgets = new Widget[] { this.createMockWidget() };
root.setWidgets(widgets);
root.setChildrenCodes(new String[] {});
return root;
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class ApiServiceAction method copyFromWidget.
/**
* Copy an exist widget (physic and with parameters, joined with a exist api
* method) and value the form of creation of new api service.
*
* @return The result code.
*/
public String copyFromWidget() {
try {
String check = this.checkMasterMethod(this.getNamespace(), this.getResourceName());
if (null != check) {
return check;
}
ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
// TODO Verify if DRAFT/ONLINE
IPage page = this.getPageManager().getOnlinePage(this.getPageCode());
if (null == page) {
this.addFieldError("pageCode", this.getText("error.service.paste.invalidPageCode", new String[] { this.getPageCode() }));
return INPUT;
}
Widget[] widgets = page.getWidgets();
if (null == this.getFramePos() || this.getFramePos() > widgets.length || null == widgets[this.getFramePos()]) {
String framePosString = (null != this.getFramePos()) ? this.getFramePos().toString() : "null";
this.addFieldError("framePos", this.getText("error.service.paste.invalidFramePos", new String[] { this.getPageCode(), framePosString }));
return INPUT;
}
Widget masterWidget = widgets[this.getFramePos()];
WidgetType type = (masterWidget.getType().isLogic()) ? masterWidget.getType().getParentType() : masterWidget.getType();
if (null == masterMethod.getRelatedWidget() || !masterMethod.getRelatedWidget().getWidgetCode().equals(type.getCode())) {
this.addFieldError("framePos", this.getText("error.service.paste.invalidWidget", new String[] { masterWidget.getType().getCode(), masterMethod.getResourceName() }));
return INPUT;
}
ApsProperties parameters = this.extractParametersFromWidget(masterMethod.getRelatedWidget(), masterWidget);
this.setApiParameterValues(parameters);
this.setApiParameters(masterMethod.getParameters());
this.setStrutsAction(ApsAdminSystemConstants.PASTE);
this.setServiceKey(this.buildTempKey(masterMethod.getResourceName()));
} catch (Throwable t) {
_logger.error("error in copyFromWidget", t);
return FAILURE;
}
return SUCCESS;
}
use of com.agiletec.aps.system.services.page.Widget in project entando-core by entando.
the class TestPageAction method addPage.
private void addPage(String pageCode) throws ApsSystemException {
IPage parentPage = _pageManager.getOnlinePage("service");
PageModel pageModel = parentPage.getMetadata().getModel();
PageMetadata metadata = PageTestUtil.createPageMetadata(pageModel.getCode(), true, "pagina temporanea", null, null, false, null, null);
ApsProperties config = PageTestUtil.createProperties("tempKey", "tempValue", "contentId", "ART1");
Widget widgetToAdd = PageTestUtil.createWidget("content_viewer", config, this._widgetTypeManager);
Widget[] widgets = { widgetToAdd };
Page pageToAdd = PageTestUtil.createPage(pageCode, parentPage, "free", metadata, widgets);
this._pageManager.addPage(pageToAdd);
}
Aggregations