Search in sources :

Example 36 with RestServerError

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");
        }
    }
}
Also used : Arrays(java.util.Arrays) Errors(org.springframework.validation.Errors) Validator(org.springframework.validation.Validator) PageRequest(org.entando.entando.web.page.model.PageRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageStatusRequest(org.entando.entando.web.page.model.PageStatusRequest) PageController(org.entando.entando.web.page.PageController) LoggerFactory(org.slf4j.LoggerFactory) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) Autowired(org.springframework.beans.factory.annotation.Autowired) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) StringUtils(org.apache.commons.lang3.StringUtils) Group(com.agiletec.aps.system.services.group.Group) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) IPageService(org.entando.entando.aps.system.services.page.IPageService) List(java.util.List) Component(org.springframework.stereotype.Component) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IPageManager(com.agiletec.aps.system.services.page.IPageManager) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) Optional(java.util.Optional) IPage(com.agiletec.aps.system.services.page.IPage) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 37 with RestServerError

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;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) 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) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 38 with RestServerError

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

Example 39 with RestServerError

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

Example 40 with RestServerError

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);
    }
}
Also used : RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Aggregations

RestServerError (org.entando.entando.aps.system.exception.RestServerError)65 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)45 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)28 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)25 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)13 ArrayList (java.util.ArrayList)12 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)12 IPage (com.agiletec.aps.system.services.page.IPage)10 List (java.util.List)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)9 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)8 LoggerFactory (org.slf4j.LoggerFactory)8 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 Logger (org.slf4j.Logger)7 ApsProperties (com.agiletec.aps.util.ApsProperties)6 Group (com.agiletec.aps.system.services.group.Group)5 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Category (com.agiletec.aps.system.services.category.Category)4