Search in sources :

Example 21 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class WidgetService method updateWidget.

@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
    WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
    if (type == null) {
        throw new RestRourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
    } else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
        BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
        bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
        throw new ValidationGenericException(bindingResult);
    }
    this.processWidgetType(type, widgetRequest);
    WidgetDto widgetDto = dtoBuilder.convert(type);
    try {
        this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup());
        if (!StringUtils.isEmpty(widgetCode)) {
            GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
            if (null == guiFragment) {
                this.createAndAddFragment(type, widgetRequest);
            } else {
                guiFragment.setGui(widgetRequest.getCustomUi());
                this.getGuiFragmentManager().updateGuiFragment(guiFragment);
            }
        }
        this.addFragments(widgetDto);
    } catch (Throwable e) {
        logger.error("failed to update widget type", e);
        throw new RestServerError("Failed to update widget", e);
    }
    return widgetDto;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 22 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class CategoryService method addCategory.

@Override
public CategoryDto addCategory(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) {
        BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
        bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_ALREADY_EXISTS, new String[] { category.getCode() }, "category.exists");
        throw new ValidationGenericException(bindingResult);
    }
    CategoryDto dto = null;
    try {
        Category categoryToAdd = new Category();
        categoryToAdd.setCode(categoryDto.getCode());
        categoryToAdd.setParentCode(categoryDto.getParentCode());
        categoryToAdd.getTitles().putAll(categoryDto.getTitles());
        this.getCategoryManager().addCategory(categoryToAdd);
        dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
    } catch (Exception e) {
        logger.error("error adding category " + categoryDto.getCode(), e);
        throw new RestServerError("error adding 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) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 23 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class CategoryService method getCategory.

@Override
public CategoryDto getCategory(String categoryCode) {
    Category category = this.getCategoryManager().getCategory(categoryCode);
    if (null == category) {
        throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryCode);
    }
    CategoryDto dto = null;
    try {
        dto = this.getDtoBuilder().convert(category);
        for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
            List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
            dto.getReferences().put(((IManager) categoryUtilizer).getName(), (null != references && !references.isEmpty()));
        }
    } catch (Exception e) {
        logger.error("error extracting category " + categoryCode, e);
        throw new RestServerError("error extracting category " + categoryCode, 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) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) List(java.util.List) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 24 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class CategoryService method deleteCategory.

@Override
public void deleteCategory(String categoryCode) {
    Category category = this.getCategoryManager().getCategory(categoryCode);
    if (null == category) {
        return;
    }
    try {
        for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
            List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
            if (null != references && !references.isEmpty()) {
                BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
                bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_REFERENCES, new String[] { categoryCode }, "category.cannot.delete.references");
                throw new ValidationGenericException(bindingResult);
            }
        }
        this.getCategoryManager().deleteCategory(categoryCode);
    } catch (ValidationGenericException e) {
        throw e;
    } catch (Exception e) {
        logger.error("error deleting category " + categoryCode, e);
        throw new RestServerError("error deleting category " + categoryCode, e);
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) List(java.util.List) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 25 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class DatabaseService method getShortDumpReportDtos.

@Override
public PagedMetadata<ShortDumpReportDto> getShortDumpReportDtos(RestListRequest requestList) {
    PagedMetadata<ShortDumpReportDto> result = null;
    List<ShortDumpReportDto> dtos = new ArrayList<>();
    try {
        List<DataSourceDumpReport> reports = this.getDatabaseManager().getBackupReports();
        if (null != reports) {
            reports.stream().forEach(report -> dtos.add(new ShortDumpReportDto(report)));
        }
        List<ShortDumpReportDto> sublist = requestList.getSublist(dtos);
        int size = (null != reports) ? reports.size() : 0;
        SearcherDaoPaginatedResult searchResult = new SearcherDaoPaginatedResult(size, sublist);
        result = new PagedMetadata<>(requestList, searchResult);
        result.setBody(sublist);
    } catch (Throwable t) {
        logger.error("error extracting database reports", t);
        throw new RestServerError("error extracting database reports", t);
    }
    return result;
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ShortDumpReportDto(org.entando.entando.aps.system.services.database.model.ShortDumpReportDto)

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