Skip to content
Snippets Groups Projects
Commit a8dbfe8a authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Trying to fix dashboard queries

parent f27a8b4c
No related branches found
No related tags found
No related merge requests found
Pipeline #94445 passed
Showing
with 47 additions and 51 deletions
......@@ -16,7 +16,6 @@ import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.ArrayList;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
......@@ -52,7 +51,7 @@ public class DomainServiceIntTest {
domainService.createDomain(domainRequest1);
assertThat(domainService.getDomains().stream().map(Domain::getName).collect(Collectors.toList())).contains("GLOBAL", "domainName");
assertThat(domainService.getDomains().stream().map(Domain::getName).toList()).contains("GLOBAL", "domainName");
Long domainId = domainService.findDomain("domainName").orElseThrow().getId();
domainService.softRemoveDomain(domainId);
......
......@@ -31,7 +31,7 @@ public class DcnAdminController {
public List<DcnView> listAllDcns() {
return dcnRepositoryManager.loadAllNetworks().stream()
.map(DcnView::new)
.collect(Collectors.toList());
.toList();
}
}
......@@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
......@@ -31,19 +30,19 @@ public class MonitorManager {
public void createMonitorEntry(MonitorEntryView monitorEntryView) {
validateMonitorEntryCreation(monitorEntryView);
this.repository.save(modelMapper.map(monitorEntryView, MonitorEntry.class));
repository.save(modelMapper.map(monitorEntryView, MonitorEntry.class));
}
public void updateMonitorEntry(MonitorEntryView monitorEntryView) {
MonitorEntry monitorEntry = this.repository.findByServiceName(monitorEntryView.getServiceName())
MonitorEntry monitorEntry = repository.findByServiceName(monitorEntryView.getServiceName())
.orElseThrow(() -> new MonitorEntryNotFound(monitorEntryNotFoundMessage(monitorEntryView.getServiceName().getName())));
validateMonitorEntryUpdate(monitorEntryView);
monitorEntryView.setId(monitorEntry.getId());
this.repository.save(modelMapper.map(monitorEntryView, MonitorEntry.class));
repository.save(modelMapper.map(monitorEntryView, MonitorEntry.class));
}
public void updateMonitorEntry(Date lastCheck, ServiceType serviceType, MonitorStatus status) {
MonitorEntry monitorEntry = this.repository.findByServiceName(serviceType)
MonitorEntry monitorEntry = repository.findByServiceName(serviceType)
.orElseThrow(() -> new MonitorEntryNotFound(monitorEntryNotFoundMessage(serviceType.getName())));
validateMonitorEntryUpdate(lastCheck, status);
monitorEntry.setStatus(status);
......@@ -54,33 +53,33 @@ public class MonitorManager {
} else if (status.equals(MonitorStatus.FAILURE)) {
eventPublisher.publishEvent(new NotificationEvent(this, getMailAttributes(serviceType.getName())));
}
this.repository.save(monitorEntry);
repository.save(monitorEntry);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void deleteMonitorEntry(String serviceName) {
if (this.repository.existsByServiceName(ServiceType.valueOf(serviceName.toUpperCase()))) {
this.repository.deleteByServiceName(ServiceType.valueOf(serviceName.toUpperCase()));
if (repository.existsByServiceName(ServiceType.valueOf(serviceName.toUpperCase()))) {
repository.deleteByServiceName(ServiceType.valueOf(serviceName.toUpperCase()));
}
}
public List<MonitorEntryView> getAllMonitorEntries() {
return this.repository.findAll().stream()
.map(entity -> this.modelMapper.map(entity, MonitorEntryView.class))
.collect(Collectors.toList());
return repository.findAll().stream()
.map(entity -> modelMapper.map(entity, MonitorEntryView.class))
.toList();
}
public MonitorEntryView getMonitorEntries(String serviceName) {
return this.repository.findByServiceName(ServiceType.valueOf(serviceName.toUpperCase()))
.map(entity -> this.modelMapper.map(entity, MonitorEntryView.class))
return repository.findByServiceName(ServiceType.valueOf(serviceName.toUpperCase()))
.map(entity -> modelMapper.map(entity, MonitorEntryView.class))
.orElseThrow(() -> new MonitorEntryNotFound(monitorEntryNotFoundMessage(serviceName)));
}
public void changeJobState(String serviceName, boolean active) {
MonitorEntry monitorEntry = this.repository.findByServiceName(ServiceType.valueOf(serviceName.toUpperCase()))
MonitorEntry monitorEntry = repository.findByServiceName(ServiceType.valueOf(serviceName.toUpperCase()))
.orElseThrow(() -> new MonitorEntryNotFound(monitorEntryNotFoundMessage(serviceName.toUpperCase())));
monitorEntry.setActive(active);
this.repository.save(monitorEntry);
repository.save(monitorEntry);
}
public boolean existsByServiceName(ServiceType serviceName) {
......
......@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static net.geant.nmaas.nmservice.configuration.ConfigFilePreparerHelper.convertToFreemarkerTemplate;
import static net.geant.nmaas.nmservice.configuration.ConfigFilePreparerHelper.createModelEntriesFromUserInput;
......@@ -94,7 +93,7 @@ class ConfigFilePreparer {
}
List<String> ipAddresses = devices.stream()
.map(device -> (String) ((Map) device).get(DEFAULT_MANAGED_DEVICE_IP_ADDRESS_KEY))
.collect(Collectors.toList());
.toList();
nmServiceRepositoryManager.updateManagedDevices(deploymentId, ipAddresses);
}
......
......@@ -156,7 +156,7 @@ public class BulkController {
return ResponseEntity.ok(mapToViewList(filter(false, bulkDeploymentRepository.findByType(BulkType.DOMAIN))).stream()
.filter(bulk -> bulk.getCreator().getId().equals(user.getId()))
.collect(Collectors.toList()));
.toList());
}
@GetMapping("/apps")
......@@ -173,7 +173,7 @@ public class BulkController {
return ResponseEntity.ok(mapToViewList(filter(false, bulkDeploymentRepository.findByType(BulkType.APPLICATION))).stream()
.filter(bulk -> bulk.getCreator().getId().equals(user.getId()))
.collect(Collectors.toList()));
.toList());
}
@DeleteMapping("/{id}")
......@@ -206,7 +206,7 @@ public class BulkController {
private List<BulkDeploymentViewS> mapToViewList(List<BulkDeployment> deployments) {
return deployments.stream()
.map(bulk -> mapToView(bulk, BulkDeploymentViewS.class))
.collect(Collectors.toList());
.toList();
}
@GetMapping("/refresh/{id}")
......@@ -224,7 +224,7 @@ public class BulkController {
private List<BulkDeploymentViewS> mapToView(List<BulkDeployment> deployments) {
return deployments.stream()
.map(bulk -> mapToView(bulk, BulkDeploymentViewS.class))
.collect(Collectors.toList());
.toList();
}
private <T extends BulkDeploymentViewS> T mapToView(BulkDeployment bulk, Class<T> viewType) {
......
......@@ -50,16 +50,13 @@ public interface AppInstanceRepository extends JpaRepository<AppInstance, Long>
"'FAILED_APPLICATION_REMOVED')")
int isNameAvailableInDomain(@Param(value = "name") String name, @Param(value = "domain") String domain);
@Query("SELECT COUNT(ai.id) FROM AppInstance ai WHERE ai.createdAt >= :sinceTime")
int countAllDeployedSince(@Param("sinceTime") Long sinceTime);
@Query("SELECT COUNT(ai.id) FROM AppInstance ai WHERE ai.createdAt >= :sinceTime AND ai.createdAt < :endTime")
@Query(value = "SELECT COUNT(ai.id) FROM app_instance ai WHERE ai.created_at >= :sinceTime AND ai.created_at < :endTime", nativeQuery = true)
int countAllDeployedInTimePeriod(@Param("sinceTime") Long sinceTime, @Param("endTime") Long endTime);
@Query("SELECT COUNT(ai.id) FROM AppInstance ai JOIN AppDeployment ad ON ad.deploymentId = ai.internalId WHERE ai.application.name = ?1")
int countByName(String name);
@Query("SELECT ai FROM AppInstance ai WHERE ai.createdAt >= :sinceTime AND ai.createdAt <= :endTime")
@Query(value = "SELECT * FROM app_instance ai WHERE ai.created_at >= :sinceTime AND ai.created_at <= :endTime", nativeQuery = true)
List<AppInstance> findAllInTimePeriod(@Param("sinceTime") Long sinceTime, @Param("endTime") Long endTime);
int countAllByOwner(User user);
......
......@@ -66,7 +66,7 @@ public class CustomAccessTokenServiceImpl implements CustomAccessTokenService {
return userApiTokenRepository.findAllByUserId(userId).stream()
.filter(userApiToken -> !userApiToken.isDeleted())
.map(this::mapToView)
.collect(Collectors.toList());
.toList();
}
private UserApiToken createNewToken(User user, String name) {
......
......@@ -28,7 +28,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
......@@ -66,14 +65,14 @@ public class DomainGroupServiceImpl implements DomainGroupService {
//call existing webhooks
DomainGroupView domainGroupView = modelMapper.map(domainGroupEntity, DomainGroupView.class);
webhookEventRepository.findIdByEventType(WebhookEventType.DOMAIN_GROUP_CHANGE).forEach(id -> scheduleManager.createOneTimeJob(DomainGroupJob.class, "DomainGroup_" + id + "_" + domainGroupView.getId()+ "_" + LocalDateTime.now(), Map.of("webhookId", id, "action", "create","domainGroup",domainGroupView)));
webhookEventRepository.findIdByEventType(WebhookEventType.DOMAIN_GROUP_CHANGE).forEach(id -> scheduleManager.createOneTimeJob(DomainGroupJob.class, "DomainGroup_" + id + "_" + domainGroupView.getId() + "_" + LocalDateTime.now(), Map.of("webhookId", id, "action", "create", "domainGroup", domainGroupView)));
return modelMapper.map(domainGroupEntity, DomainGroupView.class);
}
@Override
public DomainGroupView addDomainsToGroup(List<Domain> domains, String groupCodeName) {
DomainGroup domainGroup = domainGroupRepository.findByCodename(groupCodeName).orElseThrow();
domains.forEach( domain -> {
domains.forEach(domain -> {
log.debug("Adding domain {}/{} to group {}", domain.getName(), domain.getCodename(), groupCodeName);
if (!domainGroup.getDomains().contains(domain)) {
domainGroup.addDomain(domain);
......@@ -104,7 +103,7 @@ public class DomainGroupServiceImpl implements DomainGroupService {
}
domainGroupRepository.deleteById(domainGroupId);
//call existing webhooks
webhookEventRepository.findIdByEventType(WebhookEventType.DOMAIN_GROUP_CHANGE).forEach(id -> scheduleManager.createOneTimeJob(DomainGroupJob.class, "DomainGroup_" + id + "_" + domainGroup.getId()+ "_" + LocalDateTime.now(), Map.of("webhookId", id, "action", "delete","domainGroup",domainGroupView)));
webhookEventRepository.findIdByEventType(WebhookEventType.DOMAIN_GROUP_CHANGE).forEach(id -> scheduleManager.createOneTimeJob(DomainGroupJob.class, "DomainGroup_" + id + "_" + domainGroup.getId() + "_" + LocalDateTime.now(), Map.of("webhookId", id, "action", "delete", "domainGroup", domainGroupView)));
}
@Override
......@@ -121,7 +120,7 @@ public class DomainGroupServiceImpl implements DomainGroupService {
public List<DomainGroupView> getAllDomainGroups() {
return domainGroupRepository.findAll().stream()
.map(g -> modelMapper.map(g, DomainGroupView.class))
.collect(Collectors.toList());
.toList();
}
@Override
......@@ -130,11 +129,14 @@ public class DomainGroupServiceImpl implements DomainGroupService {
throw new ProcessingException(String.format("Wrong domain group identifier (%s)", domainGroupId));
}
DomainGroup domainGroup = this.domainGroupRepository.findById(domainGroupId).orElseThrow();
// updateRolesInDomainsByUsers(view);
// updateRolesInDomainsByUsers(view);
domainGroup.setCodename(view.getCodename());
domainGroup.setName(view.getName());
domainGroup.setManagers(view.getManagers().stream().map(user -> modelMapper.map(user, User.class)).collect(Collectors.toList()));
for (ApplicationStatePerDomain appState: domainGroup.getApplicationStatePerDomain()) {
domainGroup.setManagers(view.getManagers().stream()
.map(user -> modelMapper.map(user, User.class))
.toList()
);
for (ApplicationStatePerDomain appState : domainGroup.getApplicationStatePerDomain()) {
for (ApplicationStatePerDomainView appStateView : view.getApplicationStatePerDomain()) {
if (appState.getApplicationBase().getId().equals(appStateView.getApplicationBaseId())) {
appState.applyChangedState(appStateView);
......@@ -146,7 +148,7 @@ public class DomainGroupServiceImpl implements DomainGroupService {
//call existing webhooks
DomainGroupView domainGroupView = modelMapper.map(domainGroup, DomainGroupView.class);
webhookEventRepository.findIdByEventType(WebhookEventType.DOMAIN_GROUP_CHANGE).forEach(id -> scheduleManager.createOneTimeJob(DomainGroupJob.class, "DomainGroup_" + id + "_" + domainGroupView.getId()+ "_" + LocalDateTime.now(), Map.of("webhookId", id, "action", "update","domainGroup",domainGroupView)));
webhookEventRepository.findIdByEventType(WebhookEventType.DOMAIN_GROUP_CHANGE).forEach(id -> scheduleManager.createOneTimeJob(DomainGroupJob.class, "DomainGroup_" + id + "_" + domainGroupView.getId() + "_" + LocalDateTime.now(), Map.of("webhookId", id, "action", "update", "domainGroup", domainGroupView)));
return domainGroupView;
}
......@@ -157,15 +159,16 @@ public class DomainGroupServiceImpl implements DomainGroupService {
}
public void deleteAppBaseFromAllAppState(ApplicationBase base) {
domainGroupRepository.findAll().forEach(d -> {
d.getApplicationStatePerDomain().removeIf(state -> state.getApplicationBase().equals(base));
});
domainGroupRepository.findAll().forEach(d ->
d.getApplicationStatePerDomain().removeIf(state -> state.getApplicationBase().equals(base))
);
}
@Override
public void deleteUserFromAllDomainsGroups(User user) {
domainGroupRepository.findAll().forEach(d -> {
d.getManagers().remove(user);
});
domainGroupRepository.findAll().forEach(d ->
d.getManagers().remove(user)
);
}
}
\ No newline at end of file
......@@ -129,7 +129,7 @@ public class DomainServiceImpl implements DomainService {
return domainRepository.findAll()
.stream()
.filter(domain -> !domain.isDeleted())
.collect(Collectors.toList());
.toList();
}
@Override
......@@ -432,7 +432,7 @@ public class DomainServiceImpl implements DomainService {
return this.userRoleRepository.findDomainMembers(domain).stream()
.filter(user -> user.getRoles().stream().anyMatch(role -> role.getRole().name().equalsIgnoreCase(Role.ROLE_DOMAIN_ADMIN.name()) && role.getDomain().getCodename().equals(domain)))
.map(user -> modelMapper.map(user, UserView.class))
.collect(Collectors.toList());
.toList();
}
@Override
......@@ -453,7 +453,7 @@ public class DomainServiceImpl implements DomainService {
app.setPvStorageSizeLimit(app.getPvStorageSizeLimit());
}
return app;
}).collect(Collectors.toList())
}).toList()
);
return domain;
......
......@@ -19,7 +19,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
......@@ -109,7 +108,7 @@ public class InternationalizationServiceImpl implements InternationalizationServ
return repository.findAll().stream()
.map(InternationalizationSimple::getAsInternationalizationView)
.map(lang -> modelMapper.map(lang, InternationalizationBriefView.class))
.collect(Collectors.toList());
.toList();
}
@Override
......@@ -136,7 +135,7 @@ public class InternationalizationServiceImpl implements InternationalizationServ
return repository.findAll().stream()
.filter(InternationalizationSimple::isEnabled)
.map(InternationalizationSimple::getLanguage)
.collect(Collectors.toList());
.toList();
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment