use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class TestWidgetTypeAction method testTrashType.
public void testTrashType() throws Throwable {
String pageCode = "pagina_1";
int frame = 1;
String widgetTypeCode = "test_widgetType_trash3";
try {
assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
WidgetType type = this.createNewWidgetType(widgetTypeCode);
this._widgetTypeManager.addWidgetType(type);
assertNotNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
IPage pagina_1 = this._pageManager.getDraftPage(pageCode);
assertNull(pagina_1.getWidgets()[frame]);
String result = this.executeJoinWidget(pageCode, frame, widgetTypeCode, "admin");
assertEquals(Action.SUCCESS, result);
pagina_1 = this._pageManager.getDraftPage(pageCode);
assertNotNull(pagina_1.getWidgets()[frame]);
result = this.executeTrash(widgetTypeCode, "admin");
assertEquals("inputWidgetTypes", result);
ActionSupport action = this.getAction();
assertEquals(1, action.getActionErrors().size());
result = this.executeDeleteWidgetFromPage(pageCode, frame, "admin");
assertEquals(Action.SUCCESS, result);
result = this.executeTrash(widgetTypeCode, "admin");
assertEquals(Action.SUCCESS, result);
result = this.executeDelete(widgetTypeCode, "admin");
assertEquals(Action.SUCCESS, result);
assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
} catch (Throwable t) {
throw t;
} finally {
IPage pagina_1 = this._pageManager.getDraftPage(pageCode);
pagina_1.getWidgets()[frame] = null;
this._pageManager.updatePage(pagina_1);
if (null != this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
this._mockWidgetTypeDAO.deleteWidgetType(widgetTypeCode);
}
((IManager) this._widgetTypeManager).refresh();
assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
}
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class TestWidgetTypeAction method testPasteNewWidgetType_2.
public void testPasteNewWidgetType_2() throws Throwable {
String widgetTypeCode = "randomWidgetCode-2";
String pageDest = "pagina_1";
int frameDest = 1;
Widget temp = this._pageManager.getDraftPage("pagina_11").getWidgets()[2];
assertNotNull(temp);
assertEquals("content_viewer", temp.getType().getCode());
IPage page = this._pageManager.getDraftPage(pageDest);
try {
assertNull(page.getWidgets()[frameDest]);
page.getWidgets()[frameDest] = temp;
this._pageManager.updatePage(page);
this.setUserOnSession("admin");
this.initAction("/do/Portal/WidgetType", "save");
this.addParameter("widgetTypeCode", widgetTypeCode);
this.addParameter("englishTitle", "en");
this.addParameter("italianTitle", "it");
this.addParameter("pageCode", pageDest);
this.addParameter("framePos", frameDest);
this.addParameter("strutsAction", ApsAdminSystemConstants.PASTE);
this.addParameter("replaceOnPage", "true");
String result = this.executeAction();
assertEquals("replaceOnPage", result);
Widget newWidget = this._pageManager.getDraftPage(pageDest).getWidgets()[frameDest];
assertNotNull(newWidget);
assertNotNull(newWidget.getConfig());
WidgetType addedType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(addedType);
assertEquals(newWidget.getType().getCode(), addedType.getCode());
ApsProperties config = addedType.getConfig();
Iterator<Object> keysIter = config.keySet().iterator();
while (keysIter.hasNext()) {
String key = (String) keysIter.next();
assertEquals(newWidget.getConfig().getProperty(key), config.getProperty(key));
}
} catch (Throwable t) {
throw t;
} finally {
page.getWidgets()[frameDest] = null;
this._pageManager.updatePage(page);
this._widgetTypeManager.deleteWidgetType(widgetTypeCode);
}
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class PageAction method setViewerPageAPI.
public String setViewerPageAPI() {
IPage page = null;
try {
page = this.getPage(this.getPageCode());
int mainFrame = page.getMetadata().getModel().getMainFrame();
if (mainFrame > -1) {
IWidgetTypeManager showletTypeManager = (IWidgetTypeManager) ApsWebApplicationUtils.getBean(SystemConstants.WIDGET_TYPE_MANAGER, this.getRequest());
Widget viewer = new Widget();
viewer.setConfig(new ApsProperties());
WidgetType type = showletTypeManager.getWidgetType(this.getViewerWidgetCode());
if (null == type) {
_logger.warn("No widget found for on-the-fly publishing config for page {}", page.getCode());
return SUCCESS;
}
viewer.setType(type);
Widget[] widgets = page.getWidgets();
widgets[mainFrame] = viewer;
}
this.getPageManager().updatePage(page);
} catch (Throwable t) {
_logger.error("Error setting on-the-fly publishing config to page {}", page.getCode(), t);
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class PageConfigAction method joinWidgetJson.
public String joinWidgetJson() {
try {
String result = this.checkBaseParams();
if (null != result) {
return result;
}
IPage page = this.getPage(this.getPageCode());
if (null != page.getWidgets()[this.getFrame()]) {
this.addActionError(this.getText("error.page.join.frameNotEmpty"));
return "pageTree";
}
if (null != this.getWidgetTypeCode() && this.getWidgetTypeCode().length() == 0) {
this.addActionError(this.getText("error.page.widgetTypeCodeUnknown"));
return INPUT;
}
_logger.debug("code={}, pageCode={}, frame={}" + this.getWidgetTypeCode(), this.getPageCode(), this.getFrame());
WidgetType widgetType = this.getShowletType(this.getWidgetTypeCode());
if (null == widgetType) {
this.addActionError(this.getText("error.page.widgetTypeCodeUnknown"));
return INPUT;
}
if (null == widgetType.getConfig() && null != widgetType.getAction()) {
this.setWidgetAction(widgetType.getAction());
// continue to widget configuration
return "configureSpecialWidget";
}
Widget widget = new Widget();
widget.setType(widgetType);
this.getPageManager().joinWidget(this.getPageCode(), widget, this.getFrame());
this.addActivityStreamInfo(ApsAdminSystemConstants.ADD, true);
} catch (Exception e) {
_logger.error("error in joinWidget", e);
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class WidgetTypeAction method save.
/**
* Save a widget type.
*
* @return The result code.
*/
public String save() {
try {
if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT && (this.getStrutsAction() != ApsAdminSystemConstants.ADD)) {
if (!this.hasCurrentUserPermission(Permission.SUPERUSER)) {
return USER_NOT_ALLOWED;
}
return this.saveUserWidget();
}
WidgetType type = null;
if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
type = new WidgetType();
type.setCode(this.getWidgetTypeCode());
} else {
String check = this.checkWidgetType();
if (null != check) {
return check;
}
type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
}
ApsProperties titles = new ApsProperties();
titles.put("it", this.getItalianTitle());
titles.put("en", this.getEnglishTitle());
String mainGroupToSet = (this.hasCurrentUserPermission(Permission.SUPERUSER)) ? this.getMainGroup() : type.getMainGroup();
if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
type.setTitles(titles);
type.setMainGroup(mainGroupToSet);
this.getWidgetTypeManager().addWidgetType(type);
} else {
ApsProperties configToSet = type.getConfig();
if (type.isLogic() && type.isUserType() && !type.isLocked() && this.hasCurrentUserPermission(Permission.SUPERUSER)) {
configToSet = this.extractWidgetTypeConfig(type.getParentType().getTypeParameters());
}
this.getWidgetTypeManager().updateWidgetType(this.getWidgetTypeCode(), titles, configToSet, mainGroupToSet);
}
if (!type.isLogic() && !super.isInternalServletWidget(this.getWidgetTypeCode())) {
GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
if (StringUtils.isNotBlank(this.getGui())) {
if (null == guiFragment) {
guiFragment = new GuiFragment();
String code = this.extractUniqueGuiFragmentCode(this.getWidgetTypeCode());
guiFragment.setCode(code);
guiFragment.setPluginCode(type.getPluginCode());
guiFragment.setGui(this.getGui());
guiFragment.setWidgetTypeCode(this.getWidgetTypeCode());
this.getGuiFragmentManager().addGuiFragment(guiFragment);
} else {
guiFragment.setGui(this.getGui());
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
} else if (null != guiFragment) {
if (StringUtils.isNotBlank(guiFragment.getDefaultGui())) {
guiFragment.setGui(null);
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
} else {
this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
}
}
} else if (type.isLogic()) /* && super.isInternalServletWidget(type.getParentType().getCode())*/
{
this.buildGuisFromForm(type);
List<String> guiFragmentCodes = this.extractGuiFragmentCodes(type.getCode());
for (int i = 0; i < guiFragmentCodes.size(); i++) {
String guiFragmentCode = guiFragmentCodes.get(i);
GuiFragment guiFragment = this.getGuiFragment(guiFragmentCode);
String fieldName = type.getCode() + "_" + guiFragmentCode;
String value = this.getGuis().getProperty(fieldName);
if ((null == value && null != guiFragment.getGui()) || (null != value && (StringUtils.isBlank(guiFragment.getGui()) || !value.equals(guiFragment.getGui())))) {
guiFragment.setGui(value);
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
}
} catch (Throwable t) {
_logger.error("error in save", t);
return FAILURE;
}
return SUCCESS;
}
Aggregations