Skip to content

Commit

Permalink
feat: query compareconfig by category
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen9 committed Dec 7, 2023
1 parent fedaa31 commit 5bec638
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void addInterceptors(InterceptorRegistry registry) {
defaultPatterns.add("/api/report/removeErrorMsg");
defaultPatterns.add("/api/desensitization/listJar");
defaultPatterns.add("/api/system/config/list");
defaultPatterns.add("/api/config/comparison/summary/queryConfigOfCategory");

// exclude configuration services
defaultPatterns.add("/api/config/**");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
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.QueryConfigOfCategoryRequestType;
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;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
Expand Down Expand Up @@ -43,4 +46,13 @@ public Response queryConfigByAppId(@PathVariable String appId) {
appId);
return ResponseUtils.successResponse(replayCompareConfig);
}

@PostMapping("/queryConfigOfCategory")
@ResponseBody
public Response queryConfigOfCategory(@RequestBody QueryConfigOfCategoryRequestType request) {
return ResponseUtils.successResponse(
comparisonSummaryService.queryConfigOfCategory(request)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;

/**
* Created by rchen9 on 2022/9/16.
Expand All @@ -35,9 +34,10 @@ protected ComparisonExclusionsConfigurableHandler(
super(repositoryProvider, appContractRepository);
}

public List<ComparisonExclusionsConfiguration> queryByMultiConditionsWithGlobal(Map<String, Object> conditions, String appId, boolean withGLobal) {
List<ComparisonExclusionsConfiguration> configs = comparisonExclusionsConfigurationRepository.queryByMultiConditionsWithGlobal(
conditions, appId, withGLobal);
public List<ComparisonExclusionsConfiguration> queryConfigOfCategory(String appId,
String operationId, List<String> dependencyIds) {
List<ComparisonExclusionsConfiguration> configs = comparisonExclusionsConfigurationRepository.queryConfigOfCategory(
appId, operationId, dependencyIds);
configs.removeIf(this::removeDetailsExpired);
return configs;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.arextest.web.core.business.config.replay;

import com.arextest.config.model.dao.config.ServiceOperationCollection;
import com.arextest.config.model.dto.application.ApplicationOperationConfiguration;
import com.arextest.config.model.dto.application.ApplicationServiceConfiguration;
import com.arextest.config.repository.impl.ApplicationOperationConfigurationRepositoryImpl;
import com.arextest.web.common.LogUtils;
import com.arextest.web.core.business.ConfigLoadService;
import com.arextest.web.core.business.config.ConfigurableHandler;
import com.arextest.web.core.repository.AppContractRepository;
import com.arextest.web.model.contract.contracts.common.enums.ExpirationType;
Expand All @@ -14,6 +17,8 @@
import com.arextest.web.model.contract.contracts.config.replay.ComparisonListSortConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonReferenceConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonSummaryConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.QueryConfigOfCategoryRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryConfigOfCategoryResponseType;
import com.arextest.web.model.contract.contracts.config.replay.ReplayCompareConfig;
import com.arextest.web.model.contract.contracts.config.replay.ReplayCompareConfig.DependencyComparisonItem;
import com.arextest.web.model.contract.contracts.config.replay.ReplayCompareConfig.ReplayComparisonItem;
Expand All @@ -35,6 +40,7 @@
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
Expand All @@ -56,6 +62,12 @@ public class ComparisonSummaryService {
protected ConfigurableHandler<ApplicationServiceConfiguration> applicationServiceConfigurationConfigurableHandler;
protected AppContractRepository appContractRepository;

@Resource
ApplicationOperationConfigurationRepositoryImpl applicationOperationConfigurationRepositoryImpl;

@Resource
ConfigLoadService configLoadService;

public ComparisonSummaryService(
@Autowired ComparisonExclusionsConfigurableHandler exclusionsConfigurableHandler,
@Autowired ComparisonInclusionsConfigurableHandler inclusionsConfigurableHandler,
Expand Down Expand Up @@ -122,6 +134,55 @@ public ReplayCompareConfig getReplayComparisonConfig(String appId) {
return result;
}

public QueryConfigOfCategoryResponseType queryConfigOfCategory(
QueryConfigOfCategoryRequestType requestType) {
QueryConfigOfCategoryResponseType responseType = new QueryConfigOfCategoryResponseType();

String appId = requestType.getAppId();
String operationName = requestType.getOperationName();
String categoryName = requestType.getCategoryName();
Boolean entryPoint = requestType.getEntryPoint();

// query operationId
String operationId = null;
List<String> dependencyIds = null;
if (Objects.equals(requestType.getEntryPoint(), true)) {
Map<String, Object> queryConditions = new HashMap<>(2);
queryConditions.put(ServiceOperationCollection.Fields.appId, appId);
queryConditions.put(ServiceOperationCollection.Fields.operationName, operationName);
List<ApplicationOperationConfiguration> applicationOperationConfigurations =
applicationOperationConfigurationRepositoryImpl.queryByMultiCondition(queryConditions);
if (CollectionUtils.isNotEmpty(applicationOperationConfigurations)) {
operationId = applicationOperationConfigurations.get(0).getId();
}
} else {
List<AppContractDto> appContractDtos = appContractRepository.queryDependencyWithAppId(appId,
operationName, categoryName);
if (CollectionUtils.isNotEmpty(appContractDtos)) {
dependencyIds = appContractDtos.stream().map(AppContractDto::getId)
.collect(Collectors.toList());
}
}

// set ignore node set
Set<String> ignoreNodeSet = configLoadService.getIgnoreNodeSet(null);
responseType.setIgnoreNodeSet(ignoreNodeSet);

if (operationId == null && entryPoint) {
return responseType;
}

Set<List<String>> result = new HashSet<>();
List<ComparisonExclusionsConfiguration> comparisonExclusionsConfigurations =
exclusionsConfigurableHandler.queryConfigOfCategory(appId, operationId, dependencyIds);
comparisonExclusionsConfigurations.forEach(item -> {
result.add(item.getExclusions());
});
responseType.setExclusionList(result);
return responseType;
}


protected void getComparisonExclusionsConfiguration(String interfaceId,
ComparisonSummaryConfiguration comparisonSummaryConfiguration) {
Set<List<String>> exclusionSet = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ List<AppContractDto> queryAppContractListByOpIds(List<String> operationList,
AppContractDto findAndModifyAppContract(AppContractDto appContractDto);

AppContractDto queryDependency(String operationId, String operationType, String operationName);
AppContractDto queryDependencyWithAppId(String appId, String operationName, String operationType);

List<AppContractDto> queryDependencyWithAppId(String appId, String operationName,
String operationType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ public AppContractDto queryDependency(String operationId, String operationType,
}

@Override
public AppContractDto queryDependencyWithAppId(String appId, String operationName,
public List<AppContractDto> queryDependencyWithAppId(String appId, String operationName,
String operationType) {
Query query = Query.query(Criteria.where(AppContractCollection.Fields.appId).is(appId)
.and(AppContractCollection.Fields.operationName).is(operationName)
.and(AppContractCollection.Fields.operationType).is(operationType));
AppContractCollection dao = mongoTemplate.findOne(query, AppContractCollection.class);
return AppContractMapper.INSTANCE.dtoFromDao(dao);
List<AppContractCollection> daos = mongoTemplate.find(query, AppContractCollection.class);
return daos.stream().map(AppContractMapper.INSTANCE::dtoFromDao).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
import com.arextest.web.model.mapper.ConfigComparisonExclusionsMapper;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -190,44 +187,43 @@ public ComparisonExclusionsConfiguration queryById(String id) {
return ConfigComparisonExclusionsMapper.INSTANCE.dtoFromDao(dao);
}

public List<ComparisonExclusionsConfiguration> queryByMultiConditionsWithGlobal(
Map<String, Object> conditions, String appId, boolean orGlobal) {
public List<ComparisonExclusionsConfiguration> queryConfigOfCategory(
String appId, String operationId, List<String> dependencyIds) {
Query query = new Query();

List<Criteria> criteriaList = new ArrayList<>();
for (Map.Entry<String, Object> entry : conditions.entrySet()) {
if (entry.getValue() == null) {
continue;
}
criteriaList.add(Criteria.where(entry.getKey()).is(entry.getValue()));
}
List<Criteria> globalCriteriaList = Arrays.asList(
Criteria.where(Fields.appId).is(appId),
Criteria.where(Fields.compareConfigType).is(CompareConfigType.REPLAY_MAIN.getCodeValue()),
Criteria.where(Fields.operationId).is(null)
);

List<Criteria> globalCriteriaList = null;
if (orGlobal) {
globalCriteriaList = Arrays.asList(
List<Criteria> criteriaList = null;
if (operationId != null) {
criteriaList = Arrays.asList(
Criteria.where(Fields.appId).is(appId),
Criteria.where(Fields.operationId).is(null),
Criteria.where(Fields.compareConfigType).is(CompareConfigType.REPLAY_MAIN.getCodeValue())

Criteria.where(Fields.compareConfigType).is(CompareConfigType.REPLAY_MAIN.getCodeValue()),
Criteria.where(Fields.operationId).is(operationId),
Criteria.where(Fields.dependencyId).is(null)
);
} else {
if (CollectionUtils.isNotEmpty(dependencyIds)) {
criteriaList = Arrays.asList(
Criteria.where(Fields.appId).is(appId),
Criteria.where(Fields.compareConfigType)
.is(CompareConfigType.REPLAY_MAIN.getCodeValue()),
Criteria.where(Fields.dependencyId).in(dependencyIds)
);
}
}

if (CollectionUtils.isEmpty(criteriaList) && CollectionUtils.isEmpty(globalCriteriaList)) {
return Collections.emptyList();
} else if (CollectionUtils.isNotEmpty(criteriaList) && CollectionUtils.isNotEmpty(
globalCriteriaList)) {
query.addCriteria(
new Criteria().orOperator(
new Criteria().andOperator(criteriaList),
new Criteria().andOperator(globalCriteriaList)
)
);
} else if (CollectionUtils.isNotEmpty(criteriaList)) {
query.addCriteria(new Criteria().andOperator(criteriaList));
if (criteriaList != null) {
query.addCriteria(new Criteria().orOperator(
new Criteria().andOperator(globalCriteriaList),
new Criteria().andOperator(criteriaList)
));
} else {
query.addCriteria(new Criteria().andOperator(globalCriteriaList));
}

List<ConfigComparisonExclusionsCollection> daos =
mongoTemplate.find(query, ConfigComparisonExclusionsCollection.class);
return daos.stream().map(ConfigComparisonExclusionsMapper.INSTANCE::dtoFromDao)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.arextest.web.model.contract.contracts.config.replay;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import lombok.Data;

@Data
public class QueryConfigOfCategoryRequestType {
@NotBlank(message = "appId can not be blank")
private String appId;

private String operationName;

private String categoryName;

@NotEmpty(message = "entryPoint can not be empty")
private Boolean entryPoint;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arextest.web.model.contract.contracts.config.replay;

import java.util.Set;
import lombok.Data;

@Data
public class QueryConfigOfCategoryResponseType extends ComparisonSummaryConfiguration {
private Set<String> ignoreNodeSet;
}

0 comments on commit 5bec638

Please sign in to comment.