use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class AbstractEntityService method deleteEntityType.
protected void deleteEntityType(String entityManagerCode, String entityTypeCode) {
IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
try {
IApsEntity entityType = entityManager.getEntityPrototype(entityTypeCode);
if (null == entityType) {
return;
}
List<String> ids = entityManager.searchId(entityTypeCode, null);
if (null != ids && ids.size() > 0) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(entityType, "entityType");
bindingResult.reject(EntityTypeValidator.ERRCODE_ENTITY_TYPE_REFERENCES, new Object[] { entityTypeCode }, "entityType.cannot.delete.references");
throw new ValidationConflictException(bindingResult);
}
((IEntityTypesConfigurer) entityManager).removeEntityPrototype(entityTypeCode);
} catch (ApsSystemException e) {
logger.error("Error in delete entityType {}", entityTypeCode, e);
throw new RestServerError("error in delete entityType", e);
}
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class LanguageService method disableLang.
protected LanguageDto disableLang(String code) {
try {
Lang sysLang = this.getLangManager().getAssignableLangs().stream().filter(i -> i.getCode().equals(code)).findFirst().orElse(null);
if (null == sysLang) {
logger.warn("no lang found with code {}", code);
throw new RestRourceNotFoundException(LanguageValidator.ERRCODE_LANGUAGE_DOES_NOT_EXISTS, "language", code);
}
// idempotent
Lang lang = this.getLangManager().getLang(code);
if (null != this.getLangManager().getLang(code)) {
BeanPropertyBindingResult validations = this.validateDisable(lang);
if (validations.hasErrors()) {
throw new ValidationConflictException(validations);
}
}
this.getLangManager().removeLang(code);
return this.getLanguageDtoBuilder().convert(sysLang);
} catch (ApsSystemException ex) {
throw new RestServerError("error disabling language " + code, ex);
}
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class PageService method updateWidgetConfiguration.
@Override
public WidgetConfigurationDto updateWidgetConfiguration(String pageCode, int frameId, WidgetConfigurationRequest widgetReq) {
try {
IPage page = this.loadPage(pageCode, STATUS_DRAFT);
if (null == page) {
throw new RestRourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
if (frameId > page.getWidgets().length) {
throw new RestRourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
}
if (null == this.getWidgetType(widgetReq.getCode())) {
throw new RestRourceNotFoundException(ERRCODE_WIDGET_INVALID, "widget", String.valueOf(widgetReq.getCode()));
}
BeanPropertyBindingResult validation = this.getWidgetValidatorFactory().get(widgetReq.getCode()).validate(widgetReq, page);
if (null != validation && validation.hasErrors()) {
throw new ValidationConflictException(validation);
}
ApsProperties properties = (ApsProperties) this.getWidgetProcessorFactory().get(widgetReq.getCode()).buildConfiguration(widgetReq);
WidgetType widgetType = this.getWidgetType(widgetReq.getCode());
Widget widget = new Widget();
widget.setType(widgetType);
widget.setConfig(properties);
this.getPageManager().joinWidget(pageCode, widget, frameId);
ApsProperties outProperties = this.getWidgetProcessorFactory().get(widgetReq.getCode()).extractConfiguration(widget.getConfig());
return new WidgetConfigurationDto(widget.getType().getCode(), outProperties);
} catch (ApsSystemException e) {
logger.error("Error in update widget configuration {}", pageCode, e);
throw new RestServerError("error in update widget configuration", e);
}
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class PageModelService method addPageModel.
@Override
public PageModelDto addPageModel(PageModelRequest pageModelRequest) {
try {
BeanPropertyBindingResult validationResult = this.validateAdd(pageModelRequest);
if (validationResult.hasErrors()) {
throw new ValidationConflictException(validationResult);
}
PageModel pageModel = this.createPageModel(pageModelRequest);
this.getPageModelManager().addPageModel(pageModel);
return this.getDtoBuilder().convert(pageModel);
} catch (ApsSystemException e) {
logger.error("Error in add pageModel", e);
throw new RestServerError("error in add pageModel", e);
}
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class RoleService method updateRole.
@Override
public RoleDto updateRole(RoleRequest roleRequest) {
try {
Role role = this.getRoleManager().getRole(roleRequest.getCode());
if (null == role) {
logger.warn("no role found with code {}", roleRequest.getCode());
throw new RestRourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleRequest.getCode());
}
role.setDescription(roleRequest.getName());
role.getPermissions().clear();
if (null != roleRequest.getPermissions()) {
roleRequest.getPermissions().entrySet().stream().filter(entry -> null != entry.getValue() && entry.getValue().booleanValue()).forEach(i -> role.addPermission(i.getKey()));
}
BeanPropertyBindingResult validationResult = this.validateRoleForUpdate(role);
if (validationResult.hasErrors()) {
throw new ValidationConflictException(validationResult);
}
this.getRoleManager().updateRole(role);
RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
return dto;
} catch (ApsSystemException e) {
logger.error("Error updating a role", e);
throw new RestServerError("error in update role", e);
}
}
Aggregations