use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeUpdateJaxbNoLogicWidgetType.
private void testInvokeUpdateJaxbNoLogicWidgetType(String widgetTypeCode, ApsProperties titles, boolean removeParametersFromCall, String customSingleGui, boolean expectedSuccess) throws Throwable {
WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(widgetType);
WidgetType widgetTypeToEdit = widgetType.clone();
GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
ApsProperties originalTitles = widgetType.getTitles();
try {
JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(widgetTypeToEdit);
if (StringUtils.isNotBlank(customSingleGui)) {
jaxbWidgetType.setGui(customSingleGui);
}
if (null != titles) {
jaxbWidgetType.setTitles(titles);
}
if (removeParametersFromCall) {
jaxbWidgetType.setTypeParameters(null);
}
this._apiWidgetTypeInterface.updateWidgetType(jaxbWidgetType);
if (!expectedSuccess) {
fail();
}
WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(extractedWidgetType);
assertEquals(widgetType.getMainGroup(), extractedWidgetType.getMainGroup());
assertEquals(titles, extractedWidgetType.getTitles());
assertEquals(widgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
assertEquals(widgetType.isLocked(), extractedWidgetType.isLocked());
if (StringUtils.isNotBlank(customSingleGui) && null == previousFragment) {
assertNotNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
}
} catch (ApiException ae) {
if (expectedSuccess) {
fail();
}
} catch (Throwable t) {
throw t;
} finally {
if (null == previousFragment) {
List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode);
if (null != codes) {
for (int i = 0; i < codes.size(); i++) {
String code = codes.get(i);
this._guiFragmentManager.deleteGuiFragment(code);
}
}
} else {
if (null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
this._guiFragmentManager.addGuiFragment(previousFragment);
} else {
this._guiFragmentManager.updateGuiFragment(previousFragment);
}
}
this._widgetTypeManager.updateWidgetType(widgetType.getCode(), originalTitles, widgetType.getConfig(), widgetType.getMainGroup());
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeDeleteJaxbNoLogicWidgetType.
private void testInvokeDeleteJaxbNoLogicWidgetType(String widgetTypeCode, boolean expectedSuccess) 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);
assertNotNull(widgetType);
WidgetType widgetTypeToDelete = widgetType.clone();
GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
try {
this._apiWidgetTypeInterface.deleteWidgetType(properties);
if (!expectedSuccess) {
fail();
}
assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
assertNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
} catch (ApiException ae) {
if (expectedSuccess) {
fail();
}
} catch (Throwable t) {
throw t;
} finally {
if (null != previousFragment && null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
this._guiFragmentManager.addGuiFragment(previousFragment);
}
if (null == this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
this._widgetTypeManager.addWidgetType(widgetTypeToDelete);
}
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method addLabel.
public void addLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException, ApsSystemException {
try {
this.checkLabels(jaxbI18nLabel);
String key = jaxbI18nLabel.getKey();
ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
if (null != labelGroups) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' already exists", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
this.getI18nManager().addLabelGroup(key, labels);
} catch (ApiException | ApsSystemException ae) {
_logger.error("Error adding label", ae);
throw new ApsSystemException("Error adding labels", ae);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method updateLabel.
public void updateLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException, ApsSystemException {
try {
this.checkLabels(jaxbI18nLabel);
String key = jaxbI18nLabel.getKey();
ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
if (null == labelGroups) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
this.getI18nManager().updateLabelGroup(key, labels);
} catch (ApiException ae) {
throw new ApiException("Error updating label", ae);
} catch (ApsSystemException t) {
_logger.error("Error updating label", t);
throw new ApsSystemException("Error updating labels", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method checkLabels.
protected void checkLabels(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
try {
String key = jaxbI18nLabel.getKey();
if (null == key || key.trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label key required", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
if (null == labels || labels.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list can't be empty", Response.Status.CONFLICT);
}
Lang defaultLang = this.getLangManager().getDefaultLang();
Object defaultLangValue = labels.get(defaultLang.getCode());
if (null == defaultLangValue || defaultLangValue.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list must contain a label for the default language '" + defaultLang.getCode() + "'", Response.Status.CONFLICT);
}
Iterator<Object> labelCodeIter = labels.keySet().iterator();
while (labelCodeIter.hasNext()) {
Object langCode = labelCodeIter.next();
Object value = labels.get(langCode);
if (null == value || value.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label for the language '" + langCode + "' is empty", Response.Status.CONFLICT);
}
}
} catch (ApiException ae) {
throw new ApiException("Error in method checkLabels ", ae);
}
}
Aggregations