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

Refactor

parent c60cc3bc
Branches
No related tags found
No related merge requests found
Pipeline #94419 failed
......@@ -243,9 +243,11 @@ public class RemoteClusterManager implements ClusterMonitoringService {
}
}
private RemoteClusterView toView(KCluster KCluster) {
RemoteClusterView view = modelMapper.map(KCluster, RemoteClusterView.class);
view.setDomainNames(KCluster.getDomains().stream().map(Domain::getName).toList());
private RemoteClusterView toView(KCluster kCluster) {
RemoteClusterView view = modelMapper.map(kCluster, RemoteClusterView.class);
if (Objects.nonNull(kCluster.getDomains())) {
view.setDomainNames(kCluster.getDomains().stream().map(Domain::getName).toList());
}
return view;
}
......
package net.geant.nmaas.portal.api.configuration;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import net.geant.nmaas.portal.exceptions.ConfigurationNotFoundException;
import net.geant.nmaas.portal.exceptions.OnlyOneConfigurationSupportedException;
import net.geant.nmaas.portal.service.ConfigurationManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/api/configuration")
@RequiredArgsConstructor
public class ConfigurationController {
private ConfigurationManager configurationManager;
@Autowired
public ConfigurationController(ConfigurationManager configurationManager) {
this.configurationManager = configurationManager;
}
private final ConfigurationManager configurationManager;
@GetMapping
public ConfigurationView getConfiguration(){
public ConfigurationView getConfiguration() {
return this.configurationManager.getConfiguration();
}
......@@ -33,7 +36,7 @@ public class ConfigurationController {
return this.configurationManager.setConfiguration(configuration);
}
@PutMapping(value="/{id}")
@PutMapping(value = "/{id}")
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')")
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void updateConfiguration(@PathVariable("id") Long id, @RequestBody @Valid ConfigurationView configuration) {
......@@ -42,13 +45,13 @@ public class ConfigurationController {
@ExceptionHandler(OnlyOneConfigurationSupportedException.class)
@ResponseStatus(code = HttpStatus.NOT_FOUND)
public String handleOnlyOneConfigurationSupportedException(OnlyOneConfigurationSupportedException e){
public String handleOnlyOneConfigurationSupportedException(OnlyOneConfigurationSupportedException e) {
return e.getMessage();
}
@ExceptionHandler(ConfigurationNotFoundException.class)
@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE)
public String handleConfigurationNotFoundException(ConfigurationNotFoundException e){
public String handleConfigurationNotFoundException(ConfigurationNotFoundException e) {
return e.getMessage();
}
}
......@@ -26,8 +26,8 @@ public class GeneralInformationController {
@GetMapping(value = "/changelog", produces = "application/json")
public FileSystemResource getChangelog() throws IOException {
Path tempJsonFile = Files.createTempFile("changelog",".json");
try(InputStream inputStream = changelogPath.getInputStream()) {
Path tempJsonFile = Files.createTempFile("changelog", ".json");
try (InputStream inputStream = changelogPath.getInputStream()) {
Files.copy(inputStream, tempJsonFile, StandardCopyOption.REPLACE_EXISTING);
}
return new FileSystemResource(tempJsonFile);
......
......@@ -41,7 +41,7 @@ public interface AppInstanceRepository extends JpaRepository<AppInstance, Long>
@Modifying
@Query("update AppInstance ai set ai.application = :application, ai.previousApplicationId = :previousApplicationId where ai.id = :id")
void updateApplication(@Param(value = "id") long id, @Param(value = "previousApplicationId") long previousApplicationId, @Param(value = "application") Application application);
void updateApplication(@Param(value = "id") Long id, @Param(value = "previousApplicationId") Long previousApplicationId, @Param(value = "application") Application application);
@Query("SELECT COUNT(ai.id) FROM AppInstance ai JOIN AppDeployment ad ON ad.deploymentId = ai.internalId WHERE ai.name = :name AND ai.domain.codename = :domain AND ad.state NOT IN" +
"('APPLICATION_REMOVED'," +
......@@ -51,16 +51,16 @@ public interface AppInstanceRepository extends JpaRepository<AppInstance, Long>
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);
int countAllDeployedSince(@Param("sinceTime") Long sinceTime);
@Query("SELECT COUNT(ai.id) FROM AppInstance ai WHERE ai.createdAt >= :sinceTime AND ai.createdAt < :endTime")
int countAllDeployedInTimePeriod(@Param("sinceTime") long sinceTime, @Param("endTime") long endTime);
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")
List<AppInstance> findAllInTimePeriod(@Param("sinceTime") long sinceTime, @Param("endTime") long endTime);
List<AppInstance> findAllInTimePeriod(@Param("sinceTime") Long sinceTime, @Param("endTime") Long endTime);
int countAllByOwner(User user);
......
......@@ -75,7 +75,7 @@ public class DashboardServiceImpl implements DashboardService {
.instanceCountInPeriod(appInstanceRepository.countAllDeployedInTimePeriod(startTimeStamp, endTimeStamp))
.instanceCountInPeriodDetails(deploymentsViews)
.popularApps(applicationDeploymentCountPerName).build();
log.info("Response: {}", systemView.toString());
log.debug("Response: {}", systemView.toString());
return systemView;
}
......@@ -116,7 +116,7 @@ public class DashboardServiceImpl implements DashboardService {
.applicationDeployed(appsDeployed)
.applicationUpgradeStatus(upgradePossible)
.build();
log.info("Response: {}", view.toString());
log.debug("Response: {}", view.toString());
return view;
} else {
log.error("Domain {} not present. Returning empty...", domainId);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment