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 NewDashboardEntity dashboardEntity, final List<Dashboard> dashboards) {
final Dashboard dashboard = new Dashboard();
dashboard.setId(UuidString.generateRandom());
dashboard.setReferenceId(dashboardEntity.getReferenceId());
dashboard.setReferenceType(dashboardEntity.getReferenceType().name());
dashboard.setName(dashboardEntity.getName());
dashboard.setQueryFilter(dashboardEntity.getQueryFilter());
dashboard.setEnabled(dashboardEntity.isEnabled());
dashboard.setDefinition(dashboardEntity.getDefinition());
if (dashboards == null || dashboards.isEmpty()) {
dashboard.setOrder(1);
} else {
dashboard.setOrder(dashboards.stream().max(comparingInt(Dashboard::getOrder)).map(Dashboard::getOrder).get() + 1);
}
final Date now = new Date();
dashboard.setCreatedAt(now);
dashboard.setUpdatedAt(now);
return dashboard;
}
use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException {
final NewDashboardEntity newDashboardEntity = new NewDashboardEntity();
newDashboardEntity.setName("NAME");
newDashboardEntity.setDefinition("DEFINITION");
newDashboardEntity.setReferenceId("REF_ID");
newDashboardEntity.setReferenceType(PLATFORM);
newDashboardEntity.setQueryFilter("QUERY FILTER");
final Dashboard createdDashboard = new Dashboard();
createdDashboard.setId(DASHBOARD_ID);
createdDashboard.setName("NAME");
createdDashboard.setDefinition("DEFINITION");
createdDashboard.setOrder(1);
createdDashboard.setReferenceId("REF_ID");
createdDashboard.setReferenceType(PLATFORM.name());
createdDashboard.setQueryFilter("QUERY FILTER");
createdDashboard.setCreatedAt(new Date());
createdDashboard.setUpdatedAt(new Date());
when(dashboardRepository.create(any())).thenReturn(createdDashboard);
final Dashboard d = new Dashboard();
d.setOrder(0);
when(dashboardRepository.findByReferenceType(PLATFORM.name())).thenReturn(singletonList(d));
final DashboardEntity dashboardEntity = dashboardService.create(newDashboardEntity);
assertNotNull(dashboardEntity.getId());
assertEquals("NAME", dashboardEntity.getName());
assertEquals("DEFINITION", dashboardEntity.getDefinition());
assertEquals(1, dashboardEntity.getOrder());
assertEquals("REF_ID", dashboardEntity.getReferenceId());
assertEquals(PLATFORM.name(), dashboardEntity.getReferenceType());
assertEquals("QUERY FILTER", dashboardEntity.getQueryFilter());
assertNotNull(dashboardEntity.getCreatedAt());
assertNotNull(dashboardEntity.getUpdatedAt());
final Dashboard dashboard = new Dashboard();
dashboard.setName("NAME");
dashboard.setDefinition("DEFINITION");
dashboard.setOrder(1);
dashboard.setReferenceId("REF_ID");
dashboard.setReferenceType(PLATFORM.name());
dashboard.setQueryFilter("QUERY FILTER");
verify(dashboardRepository, times(1)).create(argThat(argument -> "NAME".equals(argument.getName()) && "DEFINITION".equals(argument.getDefinition()) && "REF_ID".equals(argument.getReferenceId()) && PLATFORM.name().equals(argument.getReferenceType()) && "QUERY FILTER".equals(argument.getQueryFilter()) && Integer.valueOf(1).equals(argument.getOrder()) && !argument.getId().isEmpty() && argument.getCreatedAt() != null && argument.getUpdatedAt() != null));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(DASHBOARD, DASHBOARD_ID)), eq(Dashboard.AuditEvent.DASHBOARD_CREATED), any(Date.class), isNull(), any());
}
use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
final UpdateDashboardEntity updateDashboardEntity = new UpdateDashboardEntity();
updateDashboardEntity.setId(DASHBOARD_ID);
updateDashboardEntity.setName("NAME");
updateDashboardEntity.setDefinition("DEFINITION");
updateDashboardEntity.setOrder(1);
updateDashboardEntity.setReferenceId("REF_ID");
updateDashboardEntity.setReferenceType(PLATFORM);
updateDashboardEntity.setQueryFilter("QUERY FILTER");
final Dashboard updatedDashboard = new Dashboard();
updatedDashboard.setId(DASHBOARD_ID);
updatedDashboard.setName("NAME");
updatedDashboard.setDefinition("DEFINITION");
updatedDashboard.setOrder(1);
updatedDashboard.setReferenceId("REF_ID");
updatedDashboard.setReferenceType(PLATFORM.name());
updatedDashboard.setQueryFilter("QUERY FILTER");
updatedDashboard.setCreatedAt(new Date());
updatedDashboard.setUpdatedAt(new Date());
when(dashboardRepository.update(any())).thenReturn(updatedDashboard);
when(dashboardRepository.findById(DASHBOARD_ID)).thenReturn(of(updatedDashboard));
final DashboardEntity dashboardEntity = dashboardService.update(updateDashboardEntity);
assertNotNull(dashboardEntity.getId());
assertEquals("NAME", dashboardEntity.getName());
assertEquals("DEFINITION", dashboardEntity.getDefinition());
assertEquals(1, dashboardEntity.getOrder());
assertEquals("REF_ID", dashboardEntity.getReferenceId());
assertEquals(PLATFORM.name(), dashboardEntity.getReferenceType());
assertEquals("QUERY FILTER", dashboardEntity.getQueryFilter());
assertNotNull(dashboardEntity.getCreatedAt());
assertNotNull(dashboardEntity.getUpdatedAt());
final Dashboard dashboard = new Dashboard();
dashboard.setName("NAME");
dashboard.setDefinition("DEFINITION");
dashboard.setOrder(1);
dashboard.setReferenceId("REF_ID");
dashboard.setReferenceType(PLATFORM.name());
dashboard.setQueryFilter("QUERY FILTER");
verify(dashboardRepository, times(1)).update(argThat(argument -> "NAME".equals(argument.getName()) && "DEFINITION".equals(argument.getDefinition()) && "REF_ID".equals(argument.getReferenceId()) && PLATFORM.name().equals(argument.getReferenceType()) && "QUERY FILTER".equals(argument.getQueryFilter()) && Integer.valueOf(1).equals(argument.getOrder()) && DASHBOARD_ID.equals(argument.getId()) && argument.getCreatedAt() == null && argument.getUpdatedAt() != null));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(DASHBOARD, DASHBOARD_ID)), eq(Dashboard.AuditEvent.DASHBOARD_UPDATED), any(Date.class), any(), any());
}
use of io.gravitee.repository.management.model.Dashboard 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);
}
}
use of io.gravitee.repository.management.model.Dashboard in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceTest method shouldFindByReferenceType.
@Test
public void shouldFindByReferenceType() throws TechnicalException {
final Dashboard dashboard = mock(Dashboard.class);
when(dashboard.getId()).thenReturn(DASHBOARD_ID);
when(dashboard.getName()).thenReturn("NAME");
when(dashboard.getDefinition()).thenReturn("DEFINITION");
when(dashboard.getOrder()).thenReturn(1);
when(dashboard.getReferenceId()).thenReturn("REF_ID");
when(dashboard.getReferenceType()).thenReturn(PLATFORM.name());
when(dashboard.getQueryFilter()).thenReturn("QUERY FILTER");
when(dashboard.getCreatedAt()).thenReturn(new Date(1));
when(dashboard.getUpdatedAt()).thenReturn(new Date(2));
when(dashboardRepository.findByReferenceType(PLATFORM.name())).thenReturn(singletonList(dashboard));
final List<DashboardEntity> dashboards = dashboardService.findByReferenceType(DashboardReferenceType.PLATFORM);
final DashboardEntity dashboardEntity = dashboards.iterator().next();
assertEquals(DASHBOARD_ID, dashboardEntity.getId());
assertEquals("NAME", dashboardEntity.getName());
assertEquals("DEFINITION", dashboardEntity.getDefinition());
assertEquals(1, dashboardEntity.getOrder());
assertEquals("REF_ID", dashboardEntity.getReferenceId());
assertEquals(PLATFORM.name(), dashboardEntity.getReferenceType());
assertEquals("QUERY FILTER", dashboardEntity.getQueryFilter());
assertEquals(new Date(1), dashboardEntity.getCreatedAt());
assertEquals(new Date(2), dashboardEntity.getUpdatedAt());
}
Aggregations