use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class DatabaseService method startDatabaseRestore.
@Override
public void startDatabaseRestore(String reportCode) {
try {
DataSourceDumpReport report = this.getDatabaseManager().getBackupReport(reportCode);
if (null == report) {
logger.warn("no dump found with code {}", reportCode);
throw new ResourceNotFoundException(DatabaseValidator.ERRCODE_NO_DUMP_FOUND, "reportCode", reportCode);
}
this.getDatabaseManager().dropAndRestoreBackup(reportCode);
} catch (ResourceNotFoundException r) {
throw r;
} catch (Throwable t) {
logger.error("error starting restore", t);
throw new RestServerError("error starting restore", t);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class DatabaseService method getTableDump.
@Override
public byte[] getTableDump(String reportCode, String dataSource, String tableName) {
File tempFile = null;
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 ResourceNotFoundException("code - dataSource - table", "'" + reportCode + "' - '" + dataSource + "' - '" + tableName + "'");
}
tempFile = FileTextReader.createTempFile(new Random().nextInt(100) + reportCode + "_" + dataSource + "_" + tableName, stream);
bytes = FileTextReader.fileToByteArray(tempFile);
} catch (ResourceNotFoundException 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);
} finally {
if (null != tempFile) {
boolean deleted = tempFile.delete();
if (!deleted) {
logger.warn("Failed to create temp file {}", tempFile.getAbsolutePath());
}
}
}
return bytes;
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException 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 ResourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "parent category", categoryDto.getParentCode());
}
Category category = this.getCategoryManager().getCategory(categoryDto.getCode());
if (null == category) {
throw new ResourceNotFoundException(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.ResourceNotFoundException in project entando-core by entando.
the class AbstractPaginationValidator method validateRestListResult.
public void validateRestListResult(RestListRequest listRequest, PagedMetadata<?> result) {
if (listRequest.getPage() > 1 && (null == result.getBody() || result.getBody().isEmpty())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(listRequest, "listRequest");
bindingResult.reject(ERRCODE_NO_ITEM_ON_PAGE, new String[] { String.valueOf(listRequest.getPage()) }, "pagination.item.empty");
throw new ResourceNotFoundException(bindingResult);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class DataObjectModelController method getDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataModelDto>> getDataObjectModel(@PathVariable String dataModelId) {
logger.debug("Requested data object model -> {}", dataModelId);
MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
int result = this.getDataObjectModelValidator().checkModelId(dataModelId, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_DOES_NOT_EXIST, "dataObjectModel", dataModelId);
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().getDataObjectModel(Long.parseLong(dataModelId));
return new ResponseEntity<>(new SimpleRestResponse<>(dataModelDto), HttpStatus.OK);
}
Aggregations