Skip to content

Commit

Permalink
Merge pull request #820 from lserveriiev/task/single-check-style
Browse files Browse the repository at this point in the history
Reformate code
  • Loading branch information
kdhrubo authored Nov 29, 2024
2 parents d94d3d6 + bef35a4 commit dd9630e
Show file tree
Hide file tree
Showing 227 changed files with 3,286 additions and 3,164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,55 @@

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;


@Slf4j
@Component
public class DatabaseContextRequestInterceptor implements AsyncHandlerInterceptor {

private final List<String> whiteList = List.of(
"/swagger-ui/**", "/v3/api-docs/**", "/actuator/**",
VERSION + "/$dbs");
private final List<String> whiteList = List.of(
"/swagger-ui/**", "/v3/api-docs/**", "/actuator/**",
VERSION + "/$dbs");

private final AntPathMatcher antPathMatcher = new AntPathMatcher();
private final AntPathMatcher antPathMatcher = new AntPathMatcher();

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.debug("Pre handle - {}", request.getRequestURI());
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.debug("Pre handle - {}", request.getRequestURI());

if(!isWhileListed(request.getRequestURI())) {
final Map<String, String> pathVariables = (Map<String, String>) request
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
if (!isWhileListed(request.getRequestURI())) {
final Map<String, String> pathVariables = (Map<String, String>) request
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

log.debug("pathVariables - {}", pathVariables);
log.debug("pathVariables - {}", pathVariables);

if(Objects.isNull(pathVariables)) throw new GenericDataAccessException("Database ID not found.");
if (Objects.isNull(pathVariables)) {
throw new GenericDataAccessException("Database ID not found.");
}

String dbId = pathVariables.get("dbId");
String dbId = pathVariables.get("dbId");

log.debug("Db identifier : {}", dbId);
log.debug("Db identifier : {}", dbId);

if(StringUtils.isNotBlank(dbId)) {
this.setTenantContext(dbId);
}
else{
log.info("DB could not be determined.");
throw new GenericDataAccessException("Database ID not found.");
}
}
if (StringUtils.isNotBlank(dbId)) {
this.setTenantContext(dbId);
} else {
log.info("DB could not be determined.");
throw new GenericDataAccessException("Database ID not found.");
}
}

return true;
}
return true;
}

private boolean isWhileListed(String uri) {
return whiteList.stream().anyMatch(w -> antPathMatcher.match(w, uri));
}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
DatabaseContextHolder.clear();
}
private void setTenantContext(String tenant) {
DatabaseContextHolder.setCurrentDbId(tenant);
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
DatabaseContextHolder.clear();
}

private void setTenantContext(String tenant) {
DatabaseContextHolder.setCurrentDbId(tenant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class JdbcConfiguration {


private final DatabaseProperties databaseProperties;
private final ObjectMapper objectMapper;


@Bean
@ConditionalOnMissingBean(DataSource.class)
public DataSource dataSource() {
Expand All @@ -78,15 +75,15 @@ private Map<Object, Object> buildDataSources() {

log.debug("Databases - {}", databaseProperties.getDatabases());

if(!databaseProperties.isRdbmsConfigured()) {
if (!databaseProperties.isRdbmsConfigured()) {
log.info("*** No RDBMS configured.");
return result;
}


for (DatabaseConnectionDetail connectionDetail : databaseProperties.getDatabases()) {

if(connectionDetail.isJdbcPresent())
if (connectionDetail.isJdbcPresent())
result.put(connectionDetail.id(), this.buildDataSource(connectionDetail));
}

Expand Down Expand Up @@ -227,7 +224,7 @@ public ExistsQueryService existsQueryService(
SqlCreatorTemplate sqlCreatorTemplate,
List<ReadProcessor> processorList,
DbOperationService dbOperationService) {
return new JdbcExistsQueryService(jdbcManager,dbOperationService, processorList, sqlCreatorTemplate);
return new JdbcExistsQueryService(jdbcManager, dbOperationService, processorList, sqlCreatorTemplate);
}

@Bean
Expand All @@ -236,7 +233,7 @@ public FindOneService findOneService(
SqlCreatorTemplate sqlCreatorTemplate,
List<ReadProcessor> processorList,
DbOperationService dbOperationService) {
return new JdbcFindOneService(jdbcManager,sqlCreatorTemplate, processorList, dbOperationService);
return new JdbcFindOneService(jdbcManager, sqlCreatorTemplate, processorList, dbOperationService);
}

@Bean
Expand Down Expand Up @@ -336,7 +333,7 @@ public FindOneController findOneController(FindOneService findOneService) {

@Bean
@ConditionalOnBean(ReadService.class)
public ReadController readController(ReadService readService, Db2RestConfigProperties configProperties) {
public ReadController readController(ReadService readService, Db2RestConfigProperties configProperties) {
return new ReadController(readService, configProperties);
}

Expand Down Expand Up @@ -381,7 +378,7 @@ public SQLTemplateController sqlTemplateController(
) {
return new SQLTemplateController(sqlTemplateExecutorService);
}

@ConditionalOnBean(JdbcManager.class)
public DbInfoController dbInfoController(JdbcManager jdbcManager) {
return new DbInfoController(jdbcManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.hubspot.jinjava.tree.parse.DefaultTokenScannerSymbols;

public class DisabledExpressionTokenScannerSymbols extends DefaultTokenScannerSymbols {
@Override
public int getExprStart() {
return 0;
}
@Override
public int getExprStart() {
return 0;
}

@Override
public int getExprEnd() {
return 0;
}
@Override
public int getExprEnd() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import com.homihq.db2rest.core.dto.CreateResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.homihq.db2rest.jdbc.rest.create;


import com.homihq.db2rest.jdbc.core.service.CreateService;
import com.homihq.db2rest.core.dto.CreateResponse;
import com.homihq.db2rest.jdbc.core.service.CreateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -19,12 +19,13 @@ public class CreateController implements CreateRestApi {

@Override
public CreateResponse save(
String dbId, String schemaName,
String tableName,
List<String> includeColumns,
List<String> sequences,
Map<String, Object> data,
boolean tsIdEnabled) {
String dbId, String schemaName,
String tableName,
List<String> includeColumns,
List<String> sequences,
Map<String, Object> data,
boolean tsIdEnabled
) {

return createService
.save(dbId, schemaName, tableName, includeColumns, data, tsIdEnabled, sequences);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.homihq.db2rest.jdbc.rest.create;

import com.homihq.db2rest.core.dto.CreateResponse;
import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.List;
import java.util.Map;

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;

public interface CreateRestApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(VERSION + "/{dbId}/{tableName}")
CreateResponse save(@PathVariable String dbId,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@RequestHeader(name = "Content-Profile", required = false) String schemaName,
@PathVariable String tableName,
@RequestParam(name = "columns", required = false) List<String> includeColumns,
@RequestParam(name = "sequences", required = false) List<String> sequences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.homihq.db2rest.jdbc.rest.delete;

import com.homihq.db2rest.config.Db2RestConfigProperties;
import com.homihq.db2rest.jdbc.core.service.DeleteService;
import com.homihq.db2rest.core.dto.DeleteResponse;
import com.homihq.db2rest.jdbc.core.service.DeleteService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
Expand All @@ -20,7 +20,8 @@ public DeleteResponse delete(
String dbId,
String schemaName,
String tableName,
String filter) {
String filter
) {

db2RestConfigProperties.checkDeleteAllowed(filter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import com.homihq.db2rest.core.dto.DeleteResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;

public interface DeleteRestApi {
@ResponseStatus(HttpStatus.OK)
@DeleteMapping(VERSION + "/{dbId}/{tableName}")
DeleteResponse delete(
@PathVariable String dbId,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@PathVariable String tableName,
@RequestParam(name = "filter", required = false, defaultValue = "") String filter);
@PathVariable String dbId,
@RequestHeader(name = "Content-Profile", required = false) String schemaName,
@PathVariable String tableName,
@RequestParam(required = false, defaultValue = "") String filter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@
public class DbInfoController implements DbInfoRestApi {

private final JdbcManager jdbcManager;

@Override
public List<DbInfoObject> getObjects() {
List<DbInfoObject> dbInfoObjects = new ArrayList<>();
jdbcManager.getDbMetaMap().forEach(
(k,v) -> dbInfoObjects.add(new DbInfoObject(k, v.productName(), v.majorVersion(), v.driverName(), v.driverVersion()))
(k, v) -> dbInfoObjects.add(new DbInfoObject(k, v.productName(), v.majorVersion(), v.driverName(), v.driverVersion()))
);

return dbInfoObjects;
}






}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package com.homihq.db2rest.jdbc.rest.meta.db;

public record DbInfoObject(String dbId, String productName, int majorVersion, String driverName, String driverVersion) {
}
public record DbInfoObject(
String dbId,
String productName,
int majorVersion,
String driverName,
String driverVersion
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;

@RequestMapping(VERSION + "/$dbs")
Expand All @@ -14,7 +15,9 @@ public interface DbInfoRestApi {


@Operation(summary = "Get all database info details",
description = "Get all database info details", tags = { "DB Info Objects" })
description = "Get all database info details",
tags = {"DB Info Objects"}
)
@GetMapping()
List<DbInfoObject> getObjects();

Expand Down
Loading

0 comments on commit dd9630e

Please sign in to comment.