use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceImpl method create.
@Override
public DashboardEntity create(final NewDashboardEntity dashboardEntity) {
try {
final List<Dashboard> dashboards = dashboardRepository.findByReferenceType(dashboardEntity.getReferenceType().name());
Dashboard dashboard = dashboardRepository.create(convert(dashboardEntity, dashboards));
auditService.createEnvironmentAuditLog(Collections.singletonMap(DASHBOARD, dashboard.getId()), DASHBOARD_CREATED, dashboard.getCreatedAt(), null, dashboard);
return convert(dashboard);
} catch (TechnicalException ex) {
final String error = "An error occurred while trying to create dashboard " + dashboardEntity;
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceImpl method reorderAndSaveDashboards.
private DashboardEntity reorderAndSaveDashboards(final Dashboard dashboardToReorder, final boolean deleted) throws TechnicalException {
final Collection<Dashboard> dashboards = dashboardRepository.findByReferenceType(dashboardToReorder.getReferenceType());
final Dashboard[] dashboardsToReorder = dashboards.stream().filter(d -> !Objects.equals(d.getId(), dashboardToReorder.getId())).toArray(Dashboard[]::new);
if (dashboardToReorder.getOrder() < 1) {
dashboardToReorder.setOrder(1);
} else if (dashboardToReorder.getOrder() > dashboardsToReorder.length + 1) {
dashboardToReorder.setOrder(dashboardsToReorder.length + 1);
}
try {
for (int i = 0; i < dashboardsToReorder.length; i++) {
if (deleted) {
if (dashboardsToReorder[i].getOrder() > dashboardToReorder.getOrder()) {
dashboardsToReorder[i].setOrder(dashboardsToReorder[i].getOrder() - 1);
dashboardRepository.update(dashboardsToReorder[i]);
}
} else {
int newOrder = (i + 1) < dashboardToReorder.getOrder() ? (i + 1) : (i + 2);
if (dashboardsToReorder[i].getOrder() != newOrder) {
dashboardsToReorder[i].setOrder(newOrder);
dashboardRepository.update(dashboardsToReorder[i]);
}
}
}
if (deleted) {
return null;
}
return convert(dashboardRepository.update(dashboardToReorder));
} catch (final TechnicalException ex) {
final String error = "An error occurs while trying to update dashboard " + dashboardToReorder.getId();
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceImpl method delete.
@Override
public void delete(final String dashboardId) {
try {
Optional<Dashboard> dashboardOptional = dashboardRepository.findById(dashboardId);
if (dashboardOptional.isPresent()) {
dashboardRepository.delete(dashboardId);
reorderAndSaveDashboards(dashboardOptional.get(), true);
auditService.createEnvironmentAuditLog(Collections.singletonMap(DASHBOARD, dashboardId), DASHBOARD_DELETED, new Date(), null, dashboardOptional.get());
}
} catch (TechnicalException ex) {
final String error = "An error occurs while trying to delete dashboard " + dashboardId;
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceImpl method convert.
private Dashboard convert(final UpdateDashboardEntity dashboardEntity) {
final Dashboard dashboard = new Dashboard();
dashboard.setId(dashboardEntity.getId());
dashboard.setReferenceId(dashboardEntity.getReferenceId());
dashboard.setReferenceType(dashboardEntity.getReferenceType().name());
dashboard.setName(dashboardEntity.getName());
dashboard.setQueryFilter(dashboardEntity.getQueryFilter());
dashboard.setOrder(dashboardEntity.getOrder());
dashboard.setEnabled(dashboardEntity.isEnabled());
dashboard.setDefinition(dashboardEntity.getDefinition());
dashboard.setUpdatedAt(new Date());
return dashboard;
}
use of io.gravitee.repository.management.model.Dashboard 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);
}
}
Aggregations