use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class ProfileTypeController method updateUserProfileType.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/profileTypes/{profileTypeCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<UserProfileTypeDto>> updateUserProfileType(@PathVariable String profileTypeCode, @Valid @RequestBody ProfileTypeDtoRequest request, BindingResult bindingResult) throws JsonProcessingException {
int result = this.getProfileTypeValidator().validateBodyName(profileTypeCode, request, bindingResult);
if (bindingResult.hasErrors()) {
if (result == 404) {
throw new ResourceNotFoundException(AbstractEntityTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "profile type", profileTypeCode);
} else {
throw new ValidationGenericException(bindingResult);
}
}
UserProfileTypeDto dto = this.getUserProfileTypeService().updateUserProfileType(request, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
logger.debug("Main Response -> {}", dto);
return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method restorePageConfiguration.
@Override
public PageConfigurationDto restorePageConfiguration(String pageCode) {
try {
IPage pageD = this.loadPage(pageCode, STATUS_DRAFT);
if (null == pageD) {
throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
IPage pageO = this.loadPage(pageCode, STATUS_ONLINE);
if (null == pageO) {
DataBinder binder = new DataBinder(pageCode);
BindingResult bindingResult = binder.getBindingResult();
bindingResult.reject(ERRCODE_STATUS_INVALID, new String[] { pageCode }, "page.status.invalid");
throw new ValidationGenericException(bindingResult);
}
pageD.setMetadata(pageO.getMetadata());
pageD.setWidgets(pageO.getWidgets());
this.getPageManager().updatePage(pageD);
PageConfigurationDto pageConfigurationDto = new PageConfigurationDto(pageO, STATUS_ONLINE);
return pageConfigurationDto;
} catch (ApsSystemException e) {
logger.error("Error restoring page {} configuration", pageCode, e);
throw new RestServerError("error in restoring page configuration", e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method getWidgetConfiguration.
@Override
public WidgetConfigurationDto getWidgetConfiguration(String pageCode, int frameId, String status) {
IPage page = this.loadPage(pageCode, status);
if (null == page) {
throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
if (frameId > page.getWidgets().length) {
throw new ResourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
}
Widget widget = page.getWidgets()[frameId];
if (null == widget) {
return null;
}
return new WidgetConfigurationDto(widget);
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method updatePage.
@Override
public PageDto updatePage(String pageCode, PageRequest pageRequest) {
IPage oldPage = this.getPageManager().getDraftPage(pageCode);
if (null == oldPage) {
throw new ResourceNotFoundException(null, "page", pageCode);
}
this.validateRequest(pageRequest);
if (!oldPage.getGroup().equals(pageRequest.getOwnerGroup())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(oldPage, "page");
bindingResult.reject(PageValidator.ERRCODE_GROUP_MISMATCH, new String[] { oldPage.getGroup(), pageRequest.getOwnerGroup() }, "page.update.group.invalid");
throw new ValidationGenericException(bindingResult);
}
try {
if (!oldPage.getParentCode().equals(pageRequest.getParentCode())) {
PagePositionRequest pagePositionRequest = new PagePositionRequest();
pagePositionRequest.setParentCode(pageRequest.getParentCode());
pagePositionRequest.setCode(pageCode);
int position = this.getPages(pageCode).size() + 1;
pagePositionRequest.setPosition(position);
this.movePage(pageCode, pagePositionRequest);
oldPage = this.getPageManager().getDraftPage(pageCode);
}
IPage newPage = this.updatePage(oldPage, pageRequest);
this.getPageManager().updatePage(newPage);
IPage updatePage = this.getPageManager().getDraftPage(pageCode);
PageDto page = this.getDtoBuilder().convert(updatePage);
page.setPosition(oldPage.getPosition());
return page;
} catch (ApsSystemException e) {
logger.error("Error updating page {}", pageCode, e);
throw new RestServerError("error in update page", e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageService method getPageReferences.
@Override
public PagedMetadata<?> getPageReferences(String pageCode, String managerName, RestListRequest requestList) {
IPage page = this.getPageManager().getDraftPage(pageCode);
if (null == page) {
logger.warn("no page found with code {}", pageCode);
throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
PageServiceUtilizer<?> utilizer = this.getPageServiceUtilizer(managerName);
if (null == utilizer) {
logger.warn("no references found for {}", managerName);
throw new ResourceNotFoundException(ERRCODE_PAGE_REFERENCES, "reference", managerName);
}
List<?> dtoList = utilizer.getPageUtilizer(pageCode);
List<?> subList = requestList.getSublist(dtoList);
SearcherDaoPaginatedResult<?> pagedResult = new SearcherDaoPaginatedResult<>(dtoList.size(), subList);
PagedMetadata<Object> pagedMetadata = new PagedMetadata<>(requestList, pagedResult);
pagedMetadata.setBody((List<Object>) subList);
return pagedMetadata;
}
Aggregations