Search in sources :

Example 1 with DashboardNotFoundException

use of io.gravitee.rest.api.service.exceptions.DashboardNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class DashboardServiceImpl method update.

@Override
public DashboardEntity update(UpdateDashboardEntity dashboardEntity) {
    try {
        final Optional<Dashboard> dashboardOptional = dashboardRepository.findById(dashboardEntity.getId());
        if (dashboardOptional.isPresent()) {
            final Dashboard dashboard = convert(dashboardEntity);
            final DashboardEntity savedDashboard;
            if (dashboard.getOrder() != dashboardOptional.get().getOrder()) {
                savedDashboard = reorderAndSaveDashboards(dashboard, false);
            } else {
                savedDashboard = convert(dashboardRepository.update(dashboard));
            }
            auditService.createEnvironmentAuditLog(Collections.singletonMap(DASHBOARD, dashboard.getId()), DASHBOARD_UPDATED, new Date(), dashboardOptional.get(), dashboard);
            return savedDashboard;
        } else {
            throw new DashboardNotFoundException(dashboardEntity.getId());
        }
    } catch (TechnicalException ex) {
        final String error = "An error occurred while trying to update dashboard " + dashboardEntity;
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    }
}
Also used : DashboardNotFoundException(io.gravitee.rest.api.service.exceptions.DashboardNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UpdateDashboardEntity(io.gravitee.rest.api.model.UpdateDashboardEntity) DashboardEntity(io.gravitee.rest.api.model.DashboardEntity) NewDashboardEntity(io.gravitee.rest.api.model.NewDashboardEntity) Dashboard(io.gravitee.repository.management.model.Dashboard) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with DashboardNotFoundException

use of io.gravitee.rest.api.service.exceptions.DashboardNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class DashboardServiceImpl method findById.

@Override
public DashboardEntity findById(String dashboardId) {
    try {
        LOGGER.debug("Find dashboard by ID: {}", dashboardId);
        Optional<Dashboard> optDashboard = dashboardRepository.findById(dashboardId);
        if (!optDashboard.isPresent()) {
            throw new DashboardNotFoundException(dashboardId);
        }
        return convert(optDashboard.get());
    } catch (TechnicalException ex) {
        final String error = "An error occurs while trying to find dashboard by ID";
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    }
}
Also used : DashboardNotFoundException(io.gravitee.rest.api.service.exceptions.DashboardNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Dashboard(io.gravitee.repository.management.model.Dashboard) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 Dashboard (io.gravitee.repository.management.model.Dashboard)2 UuidString (io.gravitee.rest.api.service.common.UuidString)2 DashboardNotFoundException (io.gravitee.rest.api.service.exceptions.DashboardNotFoundException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 DashboardEntity (io.gravitee.rest.api.model.DashboardEntity)1 NewDashboardEntity (io.gravitee.rest.api.model.NewDashboardEntity)1 UpdateDashboardEntity (io.gravitee.rest.api.model.UpdateDashboardEntity)1