Skip to content

Commit

Permalink
refactor: add the defaultconfig for the query of compareconfig from s…
Browse files Browse the repository at this point in the history
…chedule-api (#304)
  • Loading branch information
coryhh authored Oct 31, 2023
1 parent f5d08a0 commit dd8e916
Show file tree
Hide file tree
Showing 14 changed files with 672 additions and 529 deletions.
2 changes: 1 addition & 1 deletion arex-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<parent>
<artifactId>arex-web</artifactId>
<groupId>com.arextest</groupId>
<version>0.6.0.3</version>
<version>0.6.0.4</version>
</parent>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.arextest.web.api.service.controller.config;

import com.arextest.common.model.response.Response;
import com.arextest.common.utils.ResponseUtils;
import com.arextest.web.core.business.config.replay.ComparisonSummaryService;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonSummaryConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ReplayCompareConfig;
import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -10,39 +14,35 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.arextest.common.model.response.Response;
import com.arextest.common.utils.ResponseUtils;
import com.arextest.web.core.business.config.replay.ComparisonSummaryService;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonSummaryConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ReplayCompareConfig;

/**
* Created by rchen9 on 2023/1/9.
*/
@Controller
@RequestMapping("/api/config/comparison/summary")
public class ComparisonSummaryController {

@Resource
ComparisonSummaryService comparisonSummaryService;

@RequestMapping("/queryByInterfaceId")
@ResponseBody
public final Response queryByInterfaceId(@RequestParam String interfaceId) {
if (StringUtils.isEmpty(interfaceId)) {
return InvalidResponse.REQUESTED_INTERFACE_ID_IS_EMPTY;
}
ComparisonSummaryConfiguration comparisonDetailsSummary =
comparisonSummaryService.getComparisonDetailsSummary(interfaceId);

return ResponseUtils.successResponse(comparisonDetailsSummary);
}
@Resource
ComparisonSummaryService comparisonSummaryService;

@GetMapping("/queryByAppId/{appId}")
@ResponseBody
public Response queryConfigByAppId(@PathVariable String appId) {
ReplayCompareConfig replayCompareConfig = comparisonSummaryService.getReplayComparisonConfig(appId);
return ResponseUtils.successResponse(replayCompareConfig);
@RequestMapping("/queryByInterfaceId")
@ResponseBody
public final Response queryByInterfaceId(@RequestParam String interfaceId) {
if (StringUtils.isEmpty(interfaceId)) {
return InvalidResponse.REQUESTED_INTERFACE_ID_IS_EMPTY;
}
ComparisonSummaryConfiguration comparisonDetailsSummary =
comparisonSummaryService.getComparisonDetailsSummary(interfaceId);

return ResponseUtils.successResponse(comparisonDetailsSummary);
}

@Deprecated
@GetMapping("/queryByAppId/{appId}")
@ResponseBody
public Response queryConfigByAppId(@PathVariable String appId) {
ReplayCompareConfig replayCompareConfig = comparisonSummaryService.getReplayComparisonConfig(
appId);
return ResponseUtils.successResponse(replayCompareConfig);
}

}
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
package com.arextest.web.api.service.controller.config;

import com.arextest.common.model.response.Response;
import com.arextest.common.utils.ResponseUtils;
import com.arextest.web.core.business.ConfigLoadService;
import com.arextest.web.core.repository.SystemConfigRepository;
import com.arextest.web.model.contract.contracts.config.SaveSystemConfigRequestType;
import com.arextest.web.model.contract.contracts.config.SystemConfig;
import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.arextest.common.model.response.Response;
import com.arextest.common.utils.ResponseUtils;
import com.arextest.web.core.repository.SystemConfigRepository;
import com.arextest.web.model.contract.contracts.config.SaveSystemConfigRequestType;

/**
* @author wildeslam.
* @create 2023/9/26 11:25
*/
@Controller
@RequestMapping("/api/system/config")
@Slf4j
public class SystemConfigController {
@Resource
private SystemConfigRepository systemConfigRepository;

@PostMapping("/save")
@ResponseBody
public Response saveSystemConfig(@RequestBody SaveSystemConfigRequestType request) {
return ResponseUtils.successResponse(systemConfigRepository.saveConfig(request.getSystemConfig()));
}
@Resource
private SystemConfigRepository systemConfigRepository;

@Resource
private ConfigLoadService configLoadService;

@PostMapping("/save")
@ResponseBody
public Response saveSystemConfig(@RequestBody SaveSystemConfigRequestType request) {
return ResponseUtils.successResponse(
systemConfigRepository.saveConfig(request.getSystemConfig()));
}

@GetMapping("/list")
@ResponseBody
public Response listSystemConfig() {
return ResponseUtils.successResponse(systemConfigRepository.getLatestSystemConfig());
@GetMapping("/list")
@ResponseBody
public Response listSystemConfig() {
SystemConfig latestSystemConfig = systemConfigRepository.getLatestSystemConfig();
latestSystemConfig.setCompareNameToLower(
Boolean.valueOf(configLoadService.getCompareNameToLower("true")));
latestSystemConfig.setCompareNullEqualsEmpty(
Boolean.valueOf(configLoadService.getCompareNullEqualsEmpty("true")));
try {
Long ignoredTimePrecisionMillis = Long.valueOf(
configLoadService.getCompareIgnoredTimePrecisionMillis("2000"));
latestSystemConfig.setCompareIgnoreTimePrecisionMillis(ignoredTimePrecisionMillis);
} catch (RuntimeException e) {
LOGGER.error("getCompareIgnoredTimePrecisionMillis error", e);
}
}
return ResponseUtils.successResponse(latestSystemConfig);
}
}
2 changes: 1 addition & 1 deletion arex-web-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
<parent>
<artifactId>arex-web</artifactId>
<groupId>com.arextest</groupId>
<version>0.6.0.3</version>
<version>0.6.0.4</version>
</parent>
</project>
2 changes: 1 addition & 1 deletion arex-web-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@
<parent>
<artifactId>arex-web</artifactId>
<groupId>com.arextest</groupId>
<version>0.6.0.3</version>
<version>0.6.0.4</version>
</parent>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.arextest.web.core.business;

public interface ConfigLoadService {

String compareIgnoredTimePrecisionMillis = "arex.compare.ignoredTimePrecisionMillis";

String compareNameToLower = "arex.compare.nameToLower";

String compareNullEqualsEmpty = "arex.compare.nullEqualsEmpty";

Object getProperty(String key, Object defaultValue);

default String getCompareIgnoredTimePrecisionMillis(String defaultValue) {
return (String) getProperty(compareIgnoredTimePrecisionMillis, defaultValue);
}

default String getCompareNameToLower(String defaultValue) {
return (String) getProperty(compareNameToLower, defaultValue);
}

default String getCompareNullEqualsEmpty(String defaultValue) {
return (String) getProperty(compareNullEqualsEmpty, defaultValue);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.arextest.web.core.business.beans;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.arextest.config.model.dto.application.ApplicationServiceConfiguration;
import com.arextest.web.core.business.ConfigLoadService;
import com.arextest.web.core.business.config.ConfigurableHandler;
import com.arextest.web.core.business.config.replay.ComparisonEncryptionConfigurableHandler;
import com.arextest.web.core.business.config.replay.ComparisonExclusionsConfigurableHandler;
Expand All @@ -14,24 +11,36 @@
import com.arextest.web.core.business.config.replay.ComparisonReferenceConfigurableHandler;
import com.arextest.web.core.business.config.replay.ComparisonSummaryService;
import com.arextest.web.core.repository.AppContractRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class CustomServiceConfiguration {

@Bean
@ConditionalOnMissingBean(ComparisonSummaryService.class)
public ComparisonSummaryService comparisonSummaryService(
ComparisonExclusionsConfigurableHandler exclusionsConfigurableHandler,
ComparisonInclusionsConfigurableHandler inclusionsConfigurableHandler,
ComparisonEncryptionConfigurableHandler encryptionConfigurableHandler,
ComparisonReferenceConfigurableHandler referenceConfigurableHandler,
ComparisonListSortConfigurableHandler listSortConfigurableHandler,
ConfigurableHandler<ApplicationServiceConfiguration> applicationServiceConfigurationConfigurableHandler,
AppContractRepository appContractRepository,
ComparisonIgnoreCategoryConfigurableHandler ignoreCategoryConfigurableHandler) {
return new ComparisonSummaryService(exclusionsConfigurableHandler, inclusionsConfigurableHandler,
encryptionConfigurableHandler, referenceConfigurableHandler, listSortConfigurableHandler,
applicationServiceConfigurationConfigurableHandler, appContractRepository,
ignoreCategoryConfigurableHandler);
}
@Bean
@ConditionalOnMissingBean(ComparisonSummaryService.class)
public ComparisonSummaryService comparisonSummaryService(
ComparisonExclusionsConfigurableHandler exclusionsConfigurableHandler,
ComparisonInclusionsConfigurableHandler inclusionsConfigurableHandler,
ComparisonEncryptionConfigurableHandler encryptionConfigurableHandler,
ComparisonReferenceConfigurableHandler referenceConfigurableHandler,
ComparisonListSortConfigurableHandler listSortConfigurableHandler,
ConfigurableHandler<ApplicationServiceConfiguration> applicationServiceConfigurationConfigurableHandler,
AppContractRepository appContractRepository,
ComparisonIgnoreCategoryConfigurableHandler ignoreCategoryConfigurableHandler) {
return new ComparisonSummaryService(exclusionsConfigurableHandler,
inclusionsConfigurableHandler,
encryptionConfigurableHandler, referenceConfigurableHandler, listSortConfigurableHandler,
applicationServiceConfigurationConfigurableHandler, appContractRepository,
ignoreCategoryConfigurableHandler);
}

@Bean
@ConditionalOnMissingBean(ConfigLoadService.class)
public ConfigLoadService configLoadService(Environment environment) {
return new DefaultConfigLoadService(environment);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.arextest.web.core.business.beans;

import com.arextest.web.core.business.ConfigLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

public class DefaultConfigLoadService implements ConfigLoadService {

private Environment environment;

public DefaultConfigLoadService(@Autowired Environment environment) {
this.environment = environment;

}

@Override
public Object getProperty(String key, Object defaultValue) {
if (environment.getProperty(key) == null) {
return defaultValue;
}
return environment.getProperty(key);
}
}
Loading

0 comments on commit dd8e916

Please sign in to comment.