use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeGetJaxbWidgetType.
private void testInvokeGetJaxbWidgetType(String widgetTypeCode) throws Throwable {
Properties properties = new Properties();
properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
properties.put("code", widgetTypeCode);
WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
try {
JAXBWidgetType jaxbwt = this._apiWidgetTypeInterface.getWidgetType(properties);
assertNotNull(jaxbwt);
assertEquals(widgetTypeCode, jaxbwt.getCode());
assertEquals(widgetType.getTitles(), jaxbwt.getTitles());
} catch (ApiException ae) {
if (null != widgetType) {
fail();
}
} catch (Throwable t) {
throw t;
}
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class ApiWidgetTypeInterface method addWidgetType.
public void addWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
if (null != widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " already exists", Response.Status.CONFLICT);
}
widgetType = jaxbWidgetType.getNewWidgetType(this.getWidgetTypeManager());
if (!widgetType.isLogic() && StringUtils.isBlank(jaxbWidgetType.getGui())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Gui is mandatory", Response.Status.CONFLICT);
}
if (widgetType.isLogic() && (StringUtils.isNotBlank(jaxbWidgetType.getGui()) || (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0))) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment mustn't be added on the new logic widget type", Response.Status.CONFLICT);
}
if (widgetType.isLogic() && this.isInternalServletWidget(widgetType.getParentType().getCode())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Logic type with parent 'Internal Servlet' widget mustn't be added", Response.Status.CONFLICT);
}
this.getWidgetTypeManager().addWidgetType(widgetType);
if (!widgetType.isLogic()) {
this.checkAndSaveFragment(widgetType, jaxbWidgetType, true, null, addedFragments, updatedFragments);
}
} catch (ApiException ae) {
this.revertPreviousObject(null, addedFragments, updatedFragments);
throw ae;
} catch (Throwable t) {
this.revertPreviousObject(null, addedFragments, updatedFragments);
this.getWidgetTypeManager().deleteWidgetType(jaxbWidgetType.getCode());
_logger.error("Error adding new widget type", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class ApiWidgetTypeInterface method getWidgetType.
public JAXBWidgetType getWidgetType(Properties properties) throws ApiException, Throwable {
String widgetTypeCode = properties.getProperty("code");
JAXBWidgetType jaxbWidgetType = null;
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(widgetTypeCode);
if (null == widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code '" + widgetTypeCode + "' does not exist", Response.Status.CONFLICT);
}
GuiFragment singleGuiFragment = null;
List<GuiFragment> fragments = new ArrayList<GuiFragment>();
if (!widgetType.isLogic()) {
singleGuiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetTypeCode);
} else {
List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
if (null != fragmentCodes) {
for (int i = 0; i < fragmentCodes.size(); i++) {
String fragmentCode = fragmentCodes.get(i);
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
if (null != fragment) {
fragments.add(fragment);
}
}
}
}
jaxbWidgetType = new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error creating widget type - code '{}'", widgetTypeCode, t);
throw t;
}
return jaxbWidgetType;
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class JAXBWidgetType method getModifiedWidgetType.
public WidgetType getModifiedWidgetType(IWidgetTypeManager widgetTypeManager) throws ApiException {
WidgetType type = widgetTypeManager.getWidgetType(this.getCode());
type.setTitles(this.getTitles());
if (type.isLogic()) {
ApsProperties configuration = this.getConfig();
type.setConfig(configuration);
} else {
List<WidgetTypeParameter> parameters = this.getTypeParameters();
if (null != parameters && !parameters.isEmpty()) {
// type.setAction("configSimpleParameter");
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Parameters of existing widget mustn't been changed", Response.Status.CONFLICT);
}
}
type.setMainGroup(this.getMainGroup());
// type.setPluginCode(this.getPluginCode());
return type;
}
use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.
the class ContentListViewerWidgetValidator method validateFilters.
protected void validateFilters(WidgetConfigurationRequest widget, BeanPropertyBindingResult errors) {
WidgetType type = this.getWidgetTypeManager().getWidgetType(widget.getCode());
Map<String, Object> config = (Map<String, Object>) widget.getConfig();
if (null != config && null != type && type.hasParameter(WIDGET_CONFIG_KEY_CATEGORIES) && type.hasParameter(WIDGET_CONFIG_KEY_MAXELEMFORITEM) && type.hasParameter(WIDGET_CONFIG_KEY_MAXELEMENTS) && StringUtils.isNotEmpty((String) config.get(WIDGET_CONFIG_KEY_CONTENTTYPE)) && StringUtils.isEmpty((String) config.get(WIDGET_CONFIG_KEY_CATEGORIES)) && StringUtils.isEmpty((String) config.get(WIDGET_CONFIG_KEY_MAXELEMFORITEM)) && StringUtils.isEmpty((String) config.get(WIDGET_CONFIG_KEY_MAXELEMENTS))) {
errors.reject(WidgetValidatorCmsHelper.ERRCODE_INVALID_CONFIGURATION, new String[] {}, WIDGET_CODE + ".parameters.invalid");
}
}
Aggregations