Search in sources :

Example 1 with UpdateDashboardEntity

use of io.gravitee.rest.api.model.UpdateDashboardEntity 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);
    }
}
Also used : DashboardNotFoundException(io.gravitee.rest.api.service.exceptions.DashboardNotFoundException) 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) Dashboard(io.gravitee.repository.management.model.Dashboard) UuidString(io.gravitee.rest.api.service.common.UuidString) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with UpdateDashboardEntity

use of io.gravitee.rest.api.model.UpdateDashboardEntity 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());
}
Also used : Optional.empty(java.util.Optional.empty) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) Mock(org.mockito.Mock) Optional.of(java.util.Optional.of) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) DASHBOARD(io.gravitee.repository.management.model.Audit.AuditProperties.DASHBOARD) Collections.singletonList(java.util.Collections.singletonList) Collections.singleton(java.util.Collections.singleton) PLATFORM(io.gravitee.rest.api.model.DashboardReferenceType.PLATFORM) UpdateDashboardEntity(io.gravitee.rest.api.model.UpdateDashboardEntity) DashboardRepository(io.gravitee.repository.management.api.DashboardRepository) DashboardServiceImpl(io.gravitee.rest.api.service.impl.DashboardServiceImpl) InjectMocks(org.mockito.InjectMocks) Dashboard(io.gravitee.repository.management.model.Dashboard) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito(org.mockito.Mockito) List(java.util.List) DashboardNotFoundException(io.gravitee.rest.api.service.exceptions.DashboardNotFoundException) DashboardReferenceType(io.gravitee.repository.management.model.DashboardReferenceType) DashboardEntity(io.gravitee.rest.api.model.DashboardEntity) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) NewDashboardEntity(io.gravitee.rest.api.model.NewDashboardEntity) 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) UpdateDashboardEntity(io.gravitee.rest.api.model.UpdateDashboardEntity) Date(java.util.Date) Test(org.junit.Test)

Example 3 with UpdateDashboardEntity

use of io.gravitee.rest.api.model.UpdateDashboardEntity in project gravitee-management-rest-api by gravitee-io.

the class DashboardServiceTest method shouldNotUpdate.

@Test(expected = DashboardNotFoundException.class)
public void shouldNotUpdate() throws TechnicalException {
    final UpdateDashboardEntity updateDashboardEntity = new UpdateDashboardEntity();
    updateDashboardEntity.setId(DASHBOARD_ID);
    when(dashboardRepository.findById(DASHBOARD_ID)).thenReturn(empty());
    dashboardService.update(updateDashboardEntity);
}
Also used : UpdateDashboardEntity(io.gravitee.rest.api.model.UpdateDashboardEntity) Test(org.junit.Test)

Aggregations

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