Search in sources :

Example 6 with DashboardEntity

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);
    }
}
Also used : 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) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 7 with DashboardEntity

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());
}
Also used : 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) Date(java.util.Date) Test(org.junit.Test)

Example 8 with DashboardEntity

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());
}
Also used : 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) Date(java.util.Date) Test(org.junit.Test)

Example 9 with DashboardEntity

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());
}
Also used : 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) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DashboardEntity (io.gravitee.rest.api.model.DashboardEntity)9 NewDashboardEntity (io.gravitee.rest.api.model.NewDashboardEntity)9 UpdateDashboardEntity (io.gravitee.rest.api.model.UpdateDashboardEntity)9 Dashboard (io.gravitee.repository.management.model.Dashboard)7 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)5 Date (java.util.Date)5 Test (org.junit.Test)5 DashboardNotFoundException (io.gravitee.rest.api.service.exceptions.DashboardNotFoundException)4 DashboardRepository (io.gravitee.repository.management.api.DashboardRepository)3 DASHBOARD (io.gravitee.repository.management.model.Audit.AuditProperties.DASHBOARD)3 DashboardReferenceType (io.gravitee.repository.management.model.DashboardReferenceType)3 UuidString (io.gravitee.rest.api.service.common.UuidString)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 PLATFORM (io.gravitee.rest.api.model.DashboardReferenceType.PLATFORM)2 DashboardServiceImpl (io.gravitee.rest.api.service.impl.DashboardServiceImpl)2 Collections.singleton (java.util.Collections.singleton)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2