use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class PageValidator method validateReferences.
public void validateReferences(String pageCode, PageStatusRequest pageStatusRequest, Errors errors) {
List<Content> contents = new ArrayList<>();
List<String> invalidRefs = new ArrayList<>();
IPage page = this.getPageManager().getDraftPage(pageCode);
try {
List<String> contentIds = this.getPageUtilizer().getPageUtilizers(pageCode);
Optional.ofNullable(contentIds).ifPresent(ids -> ids.forEach(id -> {
try {
contents.add(this.getContentManager().loadContent(id, true));
} catch (ApsSystemException e) {
logger.error("Error loadingreferences for page {}", pageCode, e);
throw new RestServerError("Error loadingreferences for page", e);
}
}));
} catch (ApsSystemException e) {
logger.error("Error loadingreferences for page {}", pageCode, e);
throw new RestServerError("Error loadingreferences for page", e);
}
if (pageStatusRequest.getStatus().equals(IPageService.STATUS_ONLINE)) {
contents.stream().forEach(content -> {
if (!content.isOnLine()) {
invalidRefs.add(content.getId());
}
});
IPage parent = null;
if (invalidRefs.isEmpty()) {
parent = this.getPageManager().getDraftPage(page.getParentCode());
}
if (!invalidRefs.isEmpty() || !parent.isOnline()) {
errors.reject(PageController.ERRCODE_REFERENCED_DRAFT_PAGE, new String[] { pageCode }, "page.status.invalid.draft.ref");
}
} else {
boolean isRoot = this.getPageManager().getOnlineRoot().getCode().equals(pageCode);
if (contents.isEmpty() && !isRoot) {
Optional.ofNullable(page.getChildrenCodes()).ifPresent(children -> Arrays.asList(children).forEach(child -> {
IPage childPage = this.getPageManager().getDraftPage(child);
if (childPage.isOnline()) {
invalidRefs.add(child);
}
}));
}
if (isRoot || !contents.isEmpty() || !invalidRefs.isEmpty()) {
errors.reject(PageController.ERRCODE_REFERENCED_ONLINE_PAGE, new String[] { pageCode }, "page.status.invalid.online.ref");
}
}
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class CategoryService method updateCategory.
@Override
public CategoryDto updateCategory(CategoryDto categoryDto) {
Category parentCategory = this.getCategoryManager().getCategory(categoryDto.getParentCode());
if (null == parentCategory) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "parent category", categoryDto.getParentCode());
}
Category category = this.getCategoryManager().getCategory(categoryDto.getCode());
if (null == category) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryDto.getCode());
}
CategoryDto dto = null;
try {
category.setParentCode(categoryDto.getParentCode());
category.getTitles().clear();
category.getTitles().putAll(categoryDto.getTitles());
this.getCategoryManager().updateCategory(category);
dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
} catch (Exception e) {
logger.error("error updating category " + categoryDto.getCode(), e);
throw new RestServerError("error updating category " + categoryDto.getCode(), e);
}
return dto;
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class DatabaseService method getTableDump.
@Override
public byte[] getTableDump(String reportCode, String dataSource, String tableName) {
byte[] bytes = null;
try {
InputStream stream = this.getDatabaseManager().getTableDump(tableName, dataSource, reportCode);
if (null == stream) {
logger.warn("no dump found with code {}, dataSource {}, table {}", reportCode, dataSource, tableName);
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(tableName, "tableName");
bindingResult.reject(DatabaseValidator.ERRCODE_NO_TABLE_DUMP_FOUND, new Object[] { reportCode, dataSource, tableName }, "database.dump.table.notFound");
throw new RestRourceNotFoundException("code - dataSource - table", "'" + reportCode + "' - '" + dataSource + "' - '" + tableName + "'");
}
File tempFile = this.createTempFile(new Random().nextInt(100) + reportCode + "_" + dataSource + "_" + tableName, stream);
bytes = this.fileToByteArray(tempFile);
tempFile.delete();
} catch (RestRourceNotFoundException r) {
throw r;
} catch (Throwable t) {
logger.error("error extracting database dump with code {}, dataSource {}, table {}", reportCode, dataSource, tableName, t);
throw new RestServerError("error extracting database dump", t);
}
return bytes;
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class DatabaseService method getDumpReportDto.
@Override
public DumpReportDto getDumpReportDto(String reportCode) {
DumpReportDto dtos = null;
try {
DataSourceDumpReport report = this.getDatabaseManager().getBackupReport(reportCode);
if (null == report) {
logger.warn("no dump found with code {}", reportCode);
throw new RestRourceNotFoundException(DatabaseValidator.ERRCODE_NO_DUMP_FOUND, "reportCode", reportCode);
}
dtos = new DumpReportDto(report, this.getComponentManager());
} catch (RestRourceNotFoundException r) {
throw r;
} catch (Throwable t) {
logger.error("error extracting database report {}", reportCode, t);
throw new RestServerError("error extracting database report " + reportCode, t);
}
return dtos;
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class DataObjectService method getGroupUtilizer.
@Override
public List<DataObjectDto> getGroupUtilizer(String groupCode) {
try {
DataObjectManager entityManager = (DataObjectManager) this.extractEntityManager(this.getManagerName());
List<String> idList = ((GroupUtilizer<String>) entityManager).getGroupUtilizers(groupCode);
return this.buildDtoList(idList, entityManager);
} catch (ApsSystemException ex) {
logger.error("Error loading dataobject references for group {}", groupCode, ex);
throw new RestServerError("Error loading dataobject references for group", ex);
}
}
Aggregations