use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class GroupService method updateGroup.
@Override
public GroupDto updateGroup(String groupCode, String descr) {
Group group = this.getGroupManager().getGroup(groupCode);
if (null == group) {
throw new ResourceNotFoundException(GroupValidator.ERRCODE_GROUP_NOT_FOUND, "group", groupCode);
}
group.setDescription(descr);
try {
this.getGroupManager().updateGroup(group);
return this.getDtoBuilder().convert(group);
} catch (ApsSystemException e) {
logger.error("Error updating group {}", groupCode, e);
throw new RestServerError("error in update group", e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException 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 ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
if (page.getWidgets() == null || frameId > page.getWidgets().length) {
throw new ResourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
}
if (null == this.getWidgetType(widgetReq.getCode())) {
throw new ResourceNotFoundException(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.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method getPage.
@Override
public PageDto getPage(String pageCode, String status) {
IPage page = this.loadPage(pageCode, status);
if (null == page) {
logger.warn("no page found with code {} and status {}", pageCode, status);
DataBinder binder = new DataBinder(pageCode);
BindingResult bindingResult = binder.getBindingResult();
String errorCode = status.equals(STATUS_DRAFT) ? ERRCODE_PAGE_NOT_FOUND : ERRCODE_PAGE_ONLY_DRAFT;
bindingResult.reject(errorCode, new String[] { pageCode, status }, "page.NotFound");
throw new ResourceNotFoundException(bindingResult);
}
String token = this.getPageTokenManager().encrypt(pageCode);
PageDto pageDto = this.getDtoBuilder().convert(page);
pageDto.setToken(token);
pageDto.setReferences(this.getReferencesInfo(page));
return pageDto;
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method applyDefaultWidgets.
@Override
public PageConfigurationDto applyDefaultWidgets(String pageCode) {
try {
IPage page = this.loadPage(pageCode, STATUS_DRAFT);
if (null == page) {
throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
PageModel pageModel = page.getModel();
Widget[] defaultWidgets = pageModel.getDefaultWidget();
if (null == defaultWidgets) {
logger.info("no default widget configuration for model {}", pageModel.getCode());
return new PageConfigurationDto(page, STATUS_DRAFT);
}
Widget[] widgets = mergePageConfiguration(page, defaultWidgets);
page.setWidgets(widgets);
this.getPageManager().updatePage(page);
return new PageConfigurationDto(page, STATUS_DRAFT);
} catch (ApsSystemException e) {
logger.error("Error setting default widgets for page {}", pageCode, e);
throw new RestServerError("Error setting default widgets for page " + pageCode, e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method updatePageStatus.
@Override
public PageDto updatePageStatus(String pageCode, String status) {
IPage currentPage = this.getPageManager().getDraftPage(pageCode);
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(pageCode, "page");
if (null == currentPage) {
throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
if (status.equals(STATUS_DRAFT) && null == this.getPageManager().getOnlinePage(pageCode)) {
return this.getDtoBuilder().convert(currentPage);
}
try {
IPage newPage = null;
if (status.equals(STATUS_ONLINE)) {
IPage publicParent = this.getPageManager().getOnlinePage(currentPage.getParentCode());
if (null == publicParent) {
bindingResult.reject(PageValidator.ERRCODE_PAGE_WITH_NO_PUBLIC_PARENT, new String[] { pageCode, currentPage.getParentCode() }, "page.status.parent.unpublished");
throw new ValidationGenericException(bindingResult);
}
this.getPageManager().setPageOnline(pageCode);
newPage = this.getPageManager().getOnlinePage(pageCode);
} else if (status.equals(STATUS_DRAFT)) {
String[] childCodes = currentPage.getChildrenCodes();
for (String childCode : childCodes) {
IPage publicChild = this.getPageManager().getOnlinePage(childCode);
if (null != publicChild) {
bindingResult.reject(PageValidator.ERRCODE_PAGE_WITH_PUBLIC_CHILD, new String[] { pageCode }, "page.status.publicChild");
throw new ValidationGenericException(bindingResult);
}
}
Map<String, PageServiceUtilizer> beans = applicationContext.getBeansOfType(PageServiceUtilizer.class);
if (null != beans) {
Iterator<PageServiceUtilizer> iter = beans.values().iterator();
while (iter.hasNext()) {
PageServiceUtilizer serviceUtilizer = iter.next();
List utilizer = serviceUtilizer.getPageUtilizer(pageCode);
if (null != utilizer && utilizer.size() > 0) {
bindingResult.reject(PageValidator.ERRCODE_REFERENCED_ONLINE_PAGE, new String[] { pageCode }, "page.status.invalid.online.ref");
throw new ValidationGenericException(bindingResult);
}
}
}
this.getPageManager().setPageOffline(pageCode);
newPage = this.getPageManager().getDraftPage(pageCode);
}
return this.getDtoBuilder().convert(newPage);
} catch (ValidationGenericException e) {
throw e;
} catch (ApsSystemException e) {
logger.error("Error updating page {} status", pageCode, e);
throw new RestServerError("error in update page status", e);
}
}
Aggregations