Skip to content

Commit

Permalink
query compare configuration by names
Browse files Browse the repository at this point in the history
  • Loading branch information
binyu1005 committed Dec 19, 2024
1 parent f211202 commit 321bd3b
Show file tree
Hide file tree
Showing 31 changed files with 339 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.arextest.web.core.business.config.replay.ComparisonExclusionsConfigurableHandler;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonExclusionsConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryExclusionRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -76,7 +77,7 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
public Response pageQueryComparisonConfig(@RequestBody PageQueryExclusionRequestType request) {
return ResponseUtils.successResponse(
exclusionsHandler.pageQueryComparisonConfig(request)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.arextest.web.core.business.config.ConfigurableHandler;
import com.arextest.web.core.business.config.replay.ComparisonIgnoreCategoryConfigurableHandler;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonIgnoreCategoryConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryCategoryRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import java.util.List;
Expand Down Expand Up @@ -64,7 +65,7 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
public Response pageQueryComparisonConfig(@RequestBody PageQueryCategoryRequestType request) {
return ResponseUtils.successResponse(
ignoreCategoryHandler.pageQueryComparisonConfig(request)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.arextest.web.core.business.config.replay.ComparisonListSortConfigurableHandler;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonListSortConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryListSortRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import jakarta.annotation.Resource;
import lombok.Getter;
Expand Down Expand Up @@ -71,7 +72,7 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
public Response pageQueryComparisonConfig(@RequestBody PageQueryListSortRequestType request) {
return ResponseUtils.successResponse(
comparisonListSortConfigurableHandler.pageQueryComparisonConfig(request)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.arextest.web.model.contract.contracts.config.replay.ComparisonRootTransformConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonTransformConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryTransformRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import com.arextest.web.model.mapper.ConfigComparisonTransformMapper;
import java.util.List;
Expand Down Expand Up @@ -72,7 +73,7 @@ public Response modify(@PathVariable ModifyType modifyType,

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
public Response pageQueryComparisonConfig(@RequestBody PageQueryTransformRequestType request) {
return ResponseUtils.successResponse(
comparisonTransformConfigurableHandler.pageQueryComparisonConfig(request)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.arextest.web.core.repository.AppContractRepository;
import com.arextest.web.model.contract.contracts.config.replay.AbstractComparisonDetailsConfiguration;
import com.arextest.web.model.dto.AppContractDto;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.enums.ContractTypeEnum;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -182,4 +183,26 @@ void addDependencyId(List<T> comparisonDetails) {
}
}
}

protected void queryIdsByKeywords(PageQueryComparisonDto dto,
ApplicationOperationConfigurationRepositoryImpl serviceOperationRepository) {
if (StringUtils.isNotBlank(dto.getKeyOfOperationName())) {
List<ApplicationOperationConfiguration> serviceOperations = serviceOperationRepository.queryLikeOperationName(
dto.getAppId(), dto.getKeyOfOperationName());
if (CollectionUtils.isNotEmpty(serviceOperations)) {
dto.setOperationIds(serviceOperations.stream().map(ApplicationOperationConfiguration::getId)
.collect(Collectors.toList()));
}
}

if (StringUtils.isNotBlank(dto.getKeyOfDependencyName())) {
List<AppContractDto> contractDtos = appContractRepository.queryLikeOperationName(
dto.getAppId(),
dto.getKeyOfDependencyName());
if (CollectionUtils.isNotEmpty(contractDtos)) {
dto.setDependencyIds(
contractDtos.stream().map(AppContractDto::getId).collect(Collectors.toList()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.arextest.web.model.contract.contracts.config.replay.ComparisonExclusionsConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonResponseType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryExclusionRequestType;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryComparisonResultDto;
import com.arextest.web.model.dto.config.PageQueryExclusionDto;
import com.arextest.web.model.dto.filesystem.FSInterfaceDto;
import com.arextest.web.model.mapper.PageQueryComparisonMapper;
import jakarta.annotation.Resource;
Expand Down Expand Up @@ -78,9 +80,10 @@ public List<ComparisonExclusionsConfiguration> queryByInterfaceId(String interfa
}

public PageQueryComparisonResponseType pageQueryComparisonConfig(
PageQueryComparisonRequestType requestType) {
PageQueryComparisonDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
PageQueryExclusionRequestType requestType) {
PageQueryExclusionDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
requestType);
queryIdsByKeywords(pageQueryComparisonDto, applicationOperationConfigurationRepository);
PageQueryComparisonResultDto<ComparisonExclusionsConfiguration> queryResult =
comparisonExclusionsConfigurationRepository.pageQueryComparisonConfig(
pageQueryComparisonDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.arextest.web.core.repository.mongo.ComparisonIgnoreCategoryConfigurationRepositoryImpl;
import com.arextest.web.model.contract.contracts.compare.CategoryDetail;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonIgnoreCategoryConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryCategoryRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonResponseType;
import com.arextest.web.model.dto.config.PageQueryCategoryDto;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryComparisonResultDto;
import com.arextest.web.model.dto.filesystem.FSInterfaceDto;
Expand Down Expand Up @@ -102,9 +104,10 @@ public boolean update(ComparisonIgnoreCategoryConfiguration configuration) {


public PageQueryComparisonResponseType pageQueryComparisonConfig(
PageQueryComparisonRequestType requestType) {
PageQueryComparisonDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
PageQueryCategoryRequestType requestType) {
PageQueryCategoryDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
requestType);
queryIdsByKeywords(pageQueryComparisonDto, applicationOperationConfigurationRepository);
PageQueryComparisonResultDto<ComparisonIgnoreCategoryConfiguration> queryResult =
ignoreCategoryConfigurationRepository.pageQueryComparisonConfig(
pageQueryComparisonDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import com.arextest.web.model.contract.contracts.config.replay.ComparisonListSortConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonResponseType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryListSortRequestType;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryComparisonResultDto;
import com.arextest.web.model.dto.config.PageQueryListSortDto;
import com.arextest.web.model.dto.filesystem.FSInterfaceDto;
import com.arextest.web.model.mapper.PageQueryComparisonMapper;
import jakarta.annotation.Resource;
Expand Down Expand Up @@ -77,9 +79,10 @@ public boolean insertList(List<ComparisonListSortConfiguration> configurationLis
}

public PageQueryComparisonResponseType pageQueryComparisonConfig(
PageQueryComparisonRequestType requestType) {
PageQueryComparisonDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
PageQueryListSortRequestType requestType) {
PageQueryListSortDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
requestType);
queryIdsByKeywords(pageQueryComparisonDto, applicationOperationConfigurationRepository);
PageQueryComparisonResultDto<ComparisonListSortConfiguration> queryResult =
listSortConfigurationRepository.pageQueryComparisonConfig(
pageQueryComparisonDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import com.arextest.web.model.contract.contracts.config.replay.ComparisonTransformConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonResponseType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryTransformRequestType;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryComparisonResultDto;
import com.arextest.web.model.dto.config.PageQueryTransformDto;
import com.arextest.web.model.dto.filesystem.FSInterfaceDto;
import com.arextest.web.model.mapper.PageQueryComparisonMapper;
import jakarta.annotation.Resource;
Expand Down Expand Up @@ -94,9 +96,10 @@ public List<String> getTransformMethodList() {
}

public PageQueryComparisonResponseType pageQueryComparisonConfig(
PageQueryComparisonRequestType requestType) {
PageQueryComparisonDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
PageQueryTransformRequestType requestType) {
PageQueryTransformDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
requestType);
queryIdsByKeywords(pageQueryComparisonDto, applicationOperationConfigurationRepository);
PageQueryComparisonResultDto<ComparisonTransformConfiguration> queryResult =
comparisonTransformConfigurationRepository.pageQueryComparisonConfig(
pageQueryComparisonDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ List<AppContractDto> queryDependencyWithAppId(String appId, String operationName
String operationType);

List<AppContractDto> queryAppContractsByIds(Collection<String> ids);

List<AppContractDto> queryLikeOperationName(String appId, String operationName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,17 @@ public List<AppContractDto> queryAppContractsByIds(Collection<String> ids) {
.stream().map(AppContractMapper.INSTANCE::dtoFromDao)
.collect(Collectors.toList());
}

@Override
public List<AppContractDto> queryLikeOperationName(String appId,
String operationName) {
if (StringUtils.isBlank(operationName)) {
return Collections.emptyList();
}
Query query = Query.query(Criteria.where(AppContractCollection.Fields.appId).is(appId)
.and(AppContractCollection.Fields.operationName).regex(".*?" + operationName + ".*", "i"));

return mongoTemplate.find(query, AppContractCollection.class)
.stream().map(AppContractMapper.INSTANCE::dtoFromDao).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import com.arextest.web.model.contract.contracts.common.enums.CompareConfigType;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonExclusionsConfiguration;
import com.arextest.web.model.dao.mongodb.ConfigComparisonExclusionsCollection;
import com.arextest.web.model.dao.mongodb.CountResult;
import com.arextest.web.model.dao.mongodb.entity.AbstractComparisonDetails;
import com.arextest.web.model.dao.mongodb.entity.AbstractComparisonDetails.Fields;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryComparisonResultDto;
import com.arextest.web.model.dto.config.PageQueryExclusionDto;
import com.arextest.web.model.mapper.ConfigComparisonExclusionsMapper;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
Expand All @@ -25,6 +26,11 @@
import org.springframework.data.mongodb.core.BulkOperations;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.data.mongodb.core.aggregation.StringOperators;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
Expand Down Expand Up @@ -235,37 +241,51 @@ public List<ComparisonExclusionsConfiguration> queryConfigOfCategory(
}

public PageQueryComparisonResultDto<ComparisonExclusionsConfiguration> pageQueryComparisonConfig(
PageQueryComparisonDto pageQueryComparisonDto) {
PageQueryExclusionDto pageQueryComparisonDto) {
PageQueryComparisonResultDto<ComparisonExclusionsConfiguration> resultDto
= new PageQueryComparisonResultDto<>();

Query query = new Query();
query.addCriteria(Criteria.where(Fields.appId).is(pageQueryComparisonDto.getAppId()));
query.addCriteria(Criteria.where(Fields.compareConfigType)
.is(CompareConfigType.REPLAY_MAIN.getCodeValue()));
List<String> operationIds = pageQueryComparisonDto.getOperationIds();
if (CollectionUtils.isNotEmpty(operationIds)) {
query.addCriteria(Criteria.where(Fields.operationId).in(operationIds));
AggregationOperation project = Aggregation.project(ComparisonExclusionsConfiguration.class).and(
ArrayOperators.Reduce.arrayOf(ConfigComparisonExclusionsCollection.Fields.exclusions)
.withInitialValue("").reduce(StringOperators.Concat.valueOf("$$value")
.concat("/").concatValueOf("$$this"))).as("exclusionPath");

Criteria criteria = Criteria.where(Fields.appId).is(pageQueryComparisonDto.getAppId());
criteria.and(Fields.compareConfigType)
.is(CompareConfigType.REPLAY_MAIN.getCodeValue());
if (CollectionUtils.isNotEmpty(pageQueryComparisonDto.getOperationIds())) {
criteria.and(Fields.operationId).in(pageQueryComparisonDto.getOperationIds());
}
if (CollectionUtils.isNotEmpty(pageQueryComparisonDto.getDependencyIds())) {
query.addCriteria(Criteria.where(Fields.dependencyId)
.in(pageQueryComparisonDto.getDependencyIds()));
criteria.and(Fields.dependencyId).in(pageQueryComparisonDto.getDependencyIds());
}
if (StringUtils.isNotEmpty(pageQueryComparisonDto.getKeyOfExclusionPath())) {
criteria.and("exclusionPath")
.regex(".*?" + pageQueryComparisonDto.getKeyOfExclusionPath() + ".*", "i");
}
AggregationOperation match = Aggregation.match(criteria);

if (Objects.equals(pageQueryComparisonDto.getNeedTotal(), true)) {
resultDto.setTotalCount(
mongoTemplate.count(query, ConfigComparisonExclusionsCollection.class)
);
AggregationOperation count = Aggregation.count().as(CountResult.Fields.total);
Aggregation aggCount = Aggregation.newAggregation(project, match, count);
AggregationResults<CountResult> countResults = mongoTemplate.aggregate(aggCount,
ConfigComparisonExclusionsCollection.class, CountResult.class);
resultDto.setTotalCount(countResults.getUniqueMappedResult() == null ? 0L
: countResults.getUniqueMappedResult().getTotal());
}
Integer pageSize = pageQueryComparisonDto.getPageSize();
Integer pageIndex = pageQueryComparisonDto.getPageIndex();
query.skip((long) (pageIndex - 1) * pageSize).limit(pageSize);
AggregationOperation skip = Aggregation.skip((long) (pageIndex - 1) * pageSize);
AggregationOperation limit = Aggregation.limit(pageSize);
AggregationOperation sort = Aggregation.sort(Sort.by(Sort.Direction.ASC, Fields.operationId)
.and(Sort.by(Sort.Direction.ASC, Fields.dependencyId)));

query.with(
Sort.by(Sort.Direction.ASC, Fields.operationId)
.and(Sort.by(Sort.Direction.ASC, Fields.dependencyId))
);
List<ComparisonExclusionsConfiguration> configs = mongoTemplate.find(query,
ConfigComparisonExclusionsCollection.class)
Aggregation agg = Aggregation.newAggregation(project, match, sort, skip, limit);
AggregationResults<ConfigComparisonExclusionsCollection> results = mongoTemplate.aggregate(agg,
ConfigComparisonExclusionsCollection.class,
ConfigComparisonExclusionsCollection.class);

List<ComparisonExclusionsConfiguration> configs = results.getMappedResults()
.stream()
.map(ConfigComparisonExclusionsMapper.INSTANCE::dtoFromDao)
.collect(Collectors.toList());
Expand Down
Loading

0 comments on commit 321bd3b

Please sign in to comment.