use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class PageConfigAction method joinWidget.
public String joinWidget() {
try {
String result = this.checkBaseParams();
if (null != result) {
return result;
}
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 PageTreeMenuAction method getWidgetFlavoursMapping.
protected Map<String, List<SelectItem>> getWidgetFlavoursMapping(List<String> pluginCodes) {
Map<String, List<SelectItem>> mapping = new HashMap<String, List<SelectItem>>();
List<WidgetType> types = this.getWidgetTypeManager().getWidgetTypes();
for (int i = 0; i < types.size(); i++) {
WidgetType type = types.get(i);
String pluginCode = type.getPluginCode();
if (null != pluginCode && pluginCode.trim().length() > 0) {
// is a plugin's widgets
if (!pluginCodes.contains(pluginCode)) {
pluginCodes.add(pluginCode);
}
this.addFlavourWidgetType(pluginCode, type, mapping);
} else if (type.isUserType()) {
// is a user widgets
this.addFlavourWidgetType(USER_WIDGETS_CODE, type, mapping);
} else if (this.getStockWidgetCodes().contains(type.getCode())) {
this.addFlavourWidgetType(STOCK_WIDGETS_CODE, type, mapping);
} else {
this.addFlavourWidgetType(CUSTOM_WIDGETS_CODE, type, mapping);
}
}
Collections.sort(pluginCodes);
return mapping;
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class WidgetTypeAction method checkGui.
private boolean checkGui() throws Throwable {
if (this.getStrutsAction() == NEW_USER_WIDGET || this.getStrutsAction() == ApsAdminSystemConstants.PASTE) {
return true;
}
boolean isValuedGui = StringUtils.isNotBlank(this.getGui());
if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
return isValuedGui;
}
if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT) {
throw new RuntimeException("Invalid Struts Action " + this.getStrutsAction());
}
WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
if (type.isLogic() || this.isInternalServletWidget(this.getWidgetTypeCode())) {
return true;
}
String pluginCode = type.getPluginCode();
String jspPath = WidgetType.getJspPath(this.getWidgetTypeCode(), pluginCode);
String folderPath = this.getRequest().getSession().getServletContext().getRealPath("/");
boolean existsJsp = (new File(folderPath + jspPath)).exists();
if (existsJsp) {
return true;
}
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("file:**" + jspPath);
for (int i = 0; i < resources.length; i++) {
Resource resource = resources[i];
if (resource.exists()) {
return true;
}
}
GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
if (!isValuedGui && (guiFragment == null || StringUtils.isBlank(guiFragment.getDefaultGui()))) {
return false;
} else {
return true;
}
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class WidgetTypeAction method saveUserWidget.
protected String saveUserWidget() {
try {
boolean isCopy = (null != this.getPageCode() && this.getPageCode().trim().length() > 0);
String check = (isCopy) ? this.checkWidgetToCopy() : this.checkNewUserWidget();
if (null != check) {
return check;
}
WidgetType newType = null;
Widget widgetToCopy = this.extractWidgetToCopy();
if (null == widgetToCopy) {
this.setReplaceOnPage(false);
newType = this.createNewWidgetType();
WidgetType parentType = this.getWidgetTypeManager().getWidgetType(this.getParentWidgetTypeCode());
newType.setParentType(parentType);
ApsProperties config = this.extractWidgetTypeConfig(parentType.getTypeParameters());
newType.setConfig(config);
} else {
newType = this.createCopiedWidget(widgetToCopy);
}
// TODO CHECK MainGroup
newType.setMainGroup(this.getMainGroup());
this.getWidgetTypeManager().addWidgetType(newType);
if (this.isReplaceOnPage()) {
WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
Widget widget = new Widget();
widget.setType(type);
IPage page = this.getPageManager().getDraftPage(this.getPageCode());
page.getWidgets()[this.getFramePos()] = widget;
this.getPageManager().updatePage(page);
return "replaceOnPage";
}
} catch (Throwable t) {
_logger.error("error in saveUserWidget", t);
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class WidgetTypeAction method checkDeleteWidgetType.
private String checkDeleteWidgetType() {
try {
List<IPage> utilizers = new ArrayList<>();
String check = this.checkWidgetType();
if (null != check) {
return check;
}
WidgetType type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
if (type.isLocked()) {
this.addActionError(this.getText("error.widgetType.locked.undeletable", new String[] { this.getWidgetTypeCode() }));
return "inputWidgetTypes";
}
List<IPage> draftUtilizers = this.getPageManager().getDraftWidgetUtilizers(this.getWidgetTypeCode());
if (null != draftUtilizers && draftUtilizers.size() > 0) {
utilizers.addAll(draftUtilizers);
}
List<IPage> onlineUtilizers = this.getPageManager().getOnlineWidgetUtilizers(this.getWidgetTypeCode());
if (null != onlineUtilizers && onlineUtilizers.size() > 0) {
utilizers.addAll(onlineUtilizers);
}
if (utilizers.size() > 0) {
this.addActionError(this.getText("error.widgetType.used.undeletable", new String[] { this.getWidgetTypeCode() }));
return "inputWidgetTypes";
}
} catch (Throwable t) {
_logger.error("Error on checking delete operatione : widget type code {}", this.getWidgetTypeCode(), t);
throw new RuntimeException("Error on checking delete operatione : widget type code " + this.getWidgetTypeCode(), t);
}
return null;
}
Aggregations