use of io.gravitee.rest.api.model.NewDashboardEntity in project gravitee-management-rest-api by gravitee-io.
the class DefaultDashboardsUpgrader method createDashboard.
private void createDashboard(final DashboardReferenceType referenceType, final String prefixName) {
final NewDashboardEntity dashboard = new NewDashboardEntity();
dashboard.setName(prefixName + " dashboard");
dashboard.setReferenceId("DEFAULT");
dashboard.setReferenceType(io.gravitee.rest.api.model.DashboardReferenceType.valueOf(referenceType.name()));
dashboard.setEnabled(true);
final String filePath = format("/dashboards/%s_%s.json", referenceType.name().toLowerCase(), prefixName.toLowerCase());
try {
dashboard.setDefinition(IOUtils.toString(this.getClass().getResourceAsStream(filePath), defaultCharset()));
} catch (final Exception e) {
LOGGER.error("Error while trying to create a dashboard from the definition path: " + filePath, e);
}
dashboardService.create(dashboard);
}
use of io.gravitee.rest.api.model.NewDashboardEntity 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());
}
Aggregations