Search in sources :

Example 1 with AlarmWithUserEmails

use of io.imunity.furms.domain.alarms.AlarmWithUserEmails in project furms by unity-idm.

the class AlarmAuditLogServiceTest method shouldDetectAlarmCreation.

@Test
void shouldDetectAlarmCreation() {
    // given
    AlarmId id = new AlarmId(UUID.randomUUID());
    AlarmWithUserEmails request = AlarmWithUserEmails.builder().id(id).projectId("projectId").name("userFacingName").alarmUser(Set.of()).build();
    AlarmWithUserIds response = AlarmWithUserIds.builder().id(id).projectId("projectId").name("userFacingName").alarmUser(Set.of()).build();
    when(alarmRepository.find(id)).thenReturn(Optional.of(response));
    when(alarmRepository.create(response)).thenReturn(id);
    // when
    service.create(request);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.ALARM_MANAGEMENT, argument.getValue().operationCategory);
    assertEquals(Action.CREATE, argument.getValue().action);
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AlarmWithUserIds(io.imunity.furms.domain.alarms.AlarmWithUserIds) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AlarmWithUserEmails

use of io.imunity.furms.domain.alarms.AlarmWithUserEmails in project furms by unity-idm.

the class AlarmServiceImplTest method shouldFind.

@Test
void shouldFind() {
    AlarmId alarmId = new AlarmId(UUID.randomUUID());
    String projectId = "projectId";
    FenixUserId fenixUserId = new FenixUserId("id");
    FenixUserId fenixUserId1 = new FenixUserId("id1");
    when(usersDAO.getAllUsers()).thenReturn(List.of(FURMSUser.builder().fenixUserId(fenixUserId).email("email").build(), FURMSUser.builder().fenixUserId(fenixUserId1).email("email1").build()));
    when(alarmRepository.find(alarmId)).thenReturn(Optional.of(AlarmWithUserIds.builder().id(alarmId).name("name").projectId(projectId).projectAllocationId("projectAllocationId").allUsers(true).alarmUser(Set.of(fenixUserId, fenixUserId1)).build()));
    when(alarmRepository.exist(projectId, alarmId)).thenReturn(true);
    Optional<AlarmWithUserEmails> alarmWithUserEmails = alarmService.find(projectId, alarmId);
    assertThat(alarmWithUserEmails).isPresent();
    assertThat(alarmWithUserEmails.get().id).isEqualTo(alarmId);
    assertThat(alarmWithUserEmails.get().name).isEqualTo("name");
    assertThat(alarmWithUserEmails.get().projectId).isEqualTo(projectId);
    assertThat(alarmWithUserEmails.get().projectAllocationId).isEqualTo("projectAllocationId");
    assertThat(alarmWithUserEmails.get().allUsers).isEqualTo(true);
    assertThat(alarmWithUserEmails.get().alarmUserEmails).isEqualTo(Set.of("email", "email1"));
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) FenixUserId(io.imunity.furms.domain.users.FenixUserId) Test(org.junit.jupiter.api.Test)

Example 3 with AlarmWithUserEmails

use of io.imunity.furms.domain.alarms.AlarmWithUserEmails in project furms by unity-idm.

the class ChartPowerService method getChartDataForProjectAlloc.

public ChartData getChartDataForProjectAlloc(String projectId, String projectAllocationId) {
    ProjectAllocationResolved projectAllocation = projectAllocationService.findByIdValidatingProjectsWithRelatedObjects(projectAllocationId, projectId).get();
    Set<ProjectAllocationChunk> allChunks = projectAllocationService.findAllChunks(projectId, projectAllocationId);
    Set<ResourceUsage> allResourceUsageHistory = resourceUsageService.findAllResourceUsageHistory(projectId, projectAllocationId);
    Optional<AlarmWithUserEmails> alarm = alarmService.find(projectId, projectAllocationId);
    Map<LocalDate, Double> timedChunkAmounts = dataMapper.prepareTimedChunkAmounts(allChunks);
    Map<LocalDate, Double> timedUsageAmounts = dataMapper.prepareTimedUsageAmounts(allResourceUsageHistory);
    LocalDate lastChunkTime = getLastChunkTime(allChunks);
    LocalDate lastUsageTime = getLastUsageTime(allResourceUsageHistory);
    LocalDate today = getToday();
    List<LocalDate> xAxis = getXAxisForProjectAlloc(projectAllocation, allChunks, allResourceUsageHistory, lastChunkTime, today);
    double threshold = dataMapper.prepareThreshold(projectAllocation, alarm);
    List<Double> chunks = ySeriesPreparer.prepareChunkSeries(xAxis, timedChunkAmounts);
    List<Double> usages = ySeriesPreparer.prepareUsagesSeries(xAxis, timedUsageAmounts, lastUsageTime, lastChunkTime, today);
    List<Double> thresholdSeries = ySeriesPreparer.prepareThresholdSeries(xAxis, threshold);
    return ChartData.builder().endTime(projectAllocation.resourceCredit.utcEndTime.toLocalDate()).projectAllocationName(projectAllocation.name).unit(projectAllocation.resourceType.unit.getSuffix()).threshold(threshold).chunks(chunks).resourceUsages(usages).times(xAxis).thresholds(thresholdSeries).build();
}
Also used : AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) ResourceUsage(io.imunity.furms.domain.resource_usage.ResourceUsage) UserResourceUsage(io.imunity.furms.domain.resource_usage.UserResourceUsage) ProjectAllocationChunk(io.imunity.furms.domain.project_allocation_installation.ProjectAllocationChunk) LocalDate(java.time.LocalDate) ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved)

Example 4 with AlarmWithUserEmails

use of io.imunity.furms.domain.alarms.AlarmWithUserEmails in project furms by unity-idm.

the class DataMapperTest method shouldPrepareThreshold.

@Test
void shouldPrepareThreshold() {
    ProjectAllocationResolved projectAllocationResolved = ProjectAllocationResolved.builder().amount(BigDecimal.TEN).build();
    AlarmWithUserEmails alarm = AlarmWithUserEmails.builder().threshold(7).build();
    double threshold = dataMapper.prepareThreshold(projectAllocationResolved, Optional.of(alarm));
    assertThat(threshold).isEqualTo(0.7);
}
Also used : AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved) Test(org.junit.jupiter.api.Test)

Example 5 with AlarmWithUserEmails

use of io.imunity.furms.domain.alarms.AlarmWithUserEmails in project furms by unity-idm.

the class AlarmServiceImpl method find.

@Override
@FurmsAuthorize(capability = PROJECT_LIMITED_READ, resourceType = PROJECT, id = "projectId")
public Optional<AlarmWithUserEmails> find(String projectId, String projectAllocationId) {
    projectAllocationRepository.findById(projectAllocationId).filter(allocation -> allocation.projectId.equals(projectId)).orElseThrow(() -> new IllegalArgumentException(String.format("Project id %s and project allocation id %s are not related", projectId, projectAllocationId)));
    Map<FenixUserId, String> groupedUsers = getUserEmails();
    return alarmRepository.find(projectAllocationId).map(alarm -> new AlarmWithUserEmails(alarm, getUserIds(groupedUsers, alarm)));
}
Also used : AlarmRemovedEvent(io.imunity.furms.domain.alarms.AlarmRemovedEvent) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) LoggerFactory(org.slf4j.LoggerFactory) AlarmRepository(io.imunity.furms.spi.alarms.AlarmRepository) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) UsersDAO(io.imunity.furms.spi.users.UsersDAO) PROJECT_LIMITED_READ(io.imunity.furms.domain.authz.roles.Capability.PROJECT_LIMITED_READ) AlarmUpdatedEvent(io.imunity.furms.domain.alarms.AlarmUpdatedEvent) ProjectAllocationRepository(io.imunity.furms.spi.project_allocation.ProjectAllocationRepository) Service(org.springframework.stereotype.Service) AlarmNotExistingException(io.imunity.furms.api.validation.exceptions.AlarmNotExistingException) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) PROJECT(io.imunity.furms.domain.authz.roles.ResourceType.PROJECT) AlarmWithUserIds(io.imunity.furms.domain.alarms.AlarmWithUserIds) AlarmCreatedEvent(io.imunity.furms.domain.alarms.AlarmCreatedEvent) FiredAlarmThresholdReduceException(io.imunity.furms.api.validation.exceptions.FiredAlarmThresholdReduceException) Logger(org.slf4j.Logger) PROJECT_LIMITED_WRITE(io.imunity.furms.domain.authz.roles.Capability.PROJECT_LIMITED_WRITE) MethodHandles(java.lang.invoke.MethodHandles) FurmsAuthorize(io.imunity.furms.core.config.security.method.FurmsAuthorize) Set(java.util.Set) AlarmId(io.imunity.furms.domain.alarms.AlarmId) Collectors(java.util.stream.Collectors) FenixUserId(io.imunity.furms.domain.users.FenixUserId) EmailNotPresentException(io.imunity.furms.api.validation.exceptions.EmailNotPresentException) AlarmAlreadyExceedThresholdException(io.imunity.furms.api.validation.exceptions.AlarmAlreadyExceedThresholdException) AlarmService(io.imunity.furms.api.alarms.AlarmService) Optional(java.util.Optional) Transactional(org.springframework.transaction.annotation.Transactional) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) FenixUserId(io.imunity.furms.domain.users.FenixUserId) FurmsAuthorize(io.imunity.furms.core.config.security.method.FurmsAuthorize)

Aggregations

AlarmWithUserEmails (io.imunity.furms.domain.alarms.AlarmWithUserEmails)10 AlarmId (io.imunity.furms.domain.alarms.AlarmId)6 Test (org.junit.jupiter.api.Test)6 AlarmWithUserIds (io.imunity.furms.domain.alarms.AlarmWithUserIds)4 AlarmAlreadyExceedThresholdException (io.imunity.furms.api.validation.exceptions.AlarmAlreadyExceedThresholdException)3 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)3 ProjectAllocationResolved (io.imunity.furms.domain.project_allocation.ProjectAllocationResolved)3 FenixUserId (io.imunity.furms.domain.users.FenixUserId)3 AlarmNotExistingException (io.imunity.furms.api.validation.exceptions.AlarmNotExistingException)2 EmailNotPresentException (io.imunity.furms.api.validation.exceptions.EmailNotPresentException)2 FiredAlarmThresholdReduceException (io.imunity.furms.api.validation.exceptions.FiredAlarmThresholdReduceException)2 AuditLogServiceImplTest (io.imunity.furms.core.audit_log.AuditLogServiceImplTest)2 AlarmCreatedEvent (io.imunity.furms.domain.alarms.AlarmCreatedEvent)2 AlarmRemovedEvent (io.imunity.furms.domain.alarms.AlarmRemovedEvent)2 AlarmUpdatedEvent (io.imunity.furms.domain.alarms.AlarmUpdatedEvent)2 AuditLog (io.imunity.furms.domain.audit_log.AuditLog)2 ProjectAllocationChunk (io.imunity.furms.domain.project_allocation_installation.ProjectAllocationChunk)2 ResourceUsage (io.imunity.furms.domain.resource_usage.ResourceUsage)2 UserResourceUsage (io.imunity.furms.domain.resource_usage.UserResourceUsage)2 AlarmRepository (io.imunity.furms.spi.alarms.AlarmRepository)2