use of io.gravitee.rest.api.model.DashboardEntity in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceImpl method findByReferenceType.
@Override
public List<DashboardEntity> findByReferenceType(final DashboardReferenceType referenceType) {
try {
LOGGER.debug("Find all dashboards by reference type");
if (DashboardReferenceType.HOME.equals(referenceType)) {
DashboardEntity dashboard = new DashboardEntity();
dashboard.setDefinition(this.getHomeDashboardDefinition());
dashboard.setReferenceType(referenceType.name());
dashboard.setEnabled(true);
dashboard.setName("Home dashboard");
dashboard.setReferenceId("DEFAULT");
return Collections.singletonList(dashboard);
} else {
return dashboardRepository.findByReferenceType(referenceType.name()).stream().map(this::convert).collect(toList());
}
} catch (TechnicalException ex) {
final String error = "An error occurs while trying to find all dashboards by reference type";
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.rest.api.model.DashboardEntity 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());
}
use of io.gravitee.rest.api.model.DashboardEntity in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceTest method shouldFindAll.
@Test
public void shouldFindAll() 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.findAll()).thenReturn(singleton(dashboard));
final List<DashboardEntity> dashboards = dashboardService.findAll();
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());
}
use of io.gravitee.rest.api.model.DashboardEntity in project gravitee-management-rest-api by gravitee-io.
the class DashboardServiceTest method shouldFindById.
@Test
public void shouldFindById() 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.findById(DASHBOARD_ID)).thenReturn(of(dashboard));
final DashboardEntity dashboardEntity = dashboardService.findById(DASHBOARD_ID);
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