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);
}
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"));
}
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();
}
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);
}
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)));
}
Aggregations