Search in sources :

Example 36 with ResourceNotFoundException

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);
    }
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 37 with ResourceNotFoundException

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;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) Random(java.util.Random) InputStream(java.io.InputStream) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) File(java.io.File)

Example 38 with ResourceNotFoundException

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;
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) Category(com.agiletec.aps.system.services.category.Category) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 39 with ResourceNotFoundException

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);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 40 with ResourceNotFoundException

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);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ResponseEntity(org.springframework.http.ResponseEntity) MapBindingResult(org.springframework.validation.MapBindingResult) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)53 RestServerError (org.entando.entando.aps.system.exception.RestServerError)27 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)20 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)15 IPage (com.agiletec.aps.system.services.page.IPage)9 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)9 Category (com.agiletec.aps.system.services.category.Category)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 ResponseEntity (org.springframework.http.ResponseEntity)7 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 Group (com.agiletec.aps.system.services.group.Group)3 Widget (com.agiletec.aps.system.services.page.Widget)3 Role (com.agiletec.aps.system.services.role.Role)3