Skip to content

Commit

Permalink
feat: improve compare config
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen9 committed Nov 11, 2024
1 parent a98f29f commit 35b0a87
Show file tree
Hide file tree
Showing 31 changed files with 1,008 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Deprecated
@Controller
@RequestMapping("/api/config/comparison/encryption")
public class ComparisonEncryptionController extends
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.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.QueryComparisonRequestType;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -73,4 +74,13 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re
return ResponseUtils.successResponse(configs);
}

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
return ResponseUtils.successResponse(
exclusionsHandler.pageQueryComparisonConfig(request)
);
}


}
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.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -60,4 +61,13 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re
ignoreCategoryHandler.removeDetailsExpired(configs, request.getFilterExpired());
return ResponseUtils.successResponse(configs);
}

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
return ResponseUtils.successResponse(
ignoreCategoryHandler.pageQueryComparisonConfig(request)
);
}

}
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.ComparisonInclusionsConfigurableHandler;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonInclusionsConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import jakarta.annotation.Resource;
import lombok.Getter;
Expand Down Expand Up @@ -64,4 +65,12 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re
request.getOperationName()));
}

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
return ResponseUtils.successResponse(
comparisonInclusionsConfigurableHandler.pageQueryComparisonConfig(request)
);
}

}
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.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.QueryComparisonRequestType;
import jakarta.annotation.Resource;
import lombok.Getter;
Expand Down Expand Up @@ -67,4 +68,12 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re
request.getAppId(), request.getOperationId(), request.getOperationType(),
request.getOperationName()));
}

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
return ResponseUtils.successResponse(
comparisonListSortConfigurableHandler.pageQueryComparisonConfig(request)
);
}
}
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.ComparisonReferenceConfigurableHandler;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonReferenceConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.QueryComparisonRequestType;
import jakarta.annotation.Resource;
import lombok.Getter;
Expand Down Expand Up @@ -68,4 +69,12 @@ public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType re
request.getOperationName()));
}

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
return ResponseUtils.successResponse(
comparisonReferenceConfigurableHandler.pageQueryComparisonConfig(request)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.arextest.web.core.business.config.replay.ComparisonTransformConfigurableHandler;
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.QueryComparisonRequestType;
import com.arextest.web.model.mapper.ConfigComparisonTransformMapper;
import java.util.List;
Expand All @@ -16,6 +17,7 @@
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 org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -68,5 +70,13 @@ public Response modify(@PathVariable ModifyType modifyType,
return ResponseUtils.resourceNotFoundResponse();
}

@PostMapping("/pageQueryComparisonConfig")
@ResponseBody
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) {
return ResponseUtils.successResponse(
comparisonTransformConfigurableHandler.pageQueryComparisonConfig(request)
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.arextest.config.repository.impl.ApplicationOperationConfigurationRepositoryImpl;
import com.arextest.web.core.business.config.AbstractConfigurableHandler;
import com.arextest.web.core.repository.AppContractRepository;
import com.arextest.web.model.dao.mongodb.AppContractCollection;
import com.arextest.web.model.dao.mongodb.AppContractCollection.Fields;
import com.arextest.web.model.dto.AppContractDto;
import com.arextest.web.model.enums.ContractTypeEnum;
import java.util.ArrayList;
Expand All @@ -22,7 +20,6 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import software.amazon.awssdk.services.sso.endpoints.internal.Value.Str;

/**
* @author jmo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.arextest.web.core.business.config.replay;

import com.arextest.config.model.dto.application.ApplicationOperationConfiguration;
import com.arextest.config.model.dto.application.Dependency;
import com.arextest.config.repository.ConfigRepositoryProvider;
import com.arextest.config.repository.impl.ApplicationOperationConfigurationRepositoryImpl;
import com.arextest.web.core.business.config.AbstractConfigurableHandler;
import com.arextest.web.core.repository.AppContractRepository;
import com.arextest.web.model.contract.contracts.config.replay.AbstractComparisonDetailsConfiguration;
Expand All @@ -17,6 +20,7 @@
import java.util.stream.Stream;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

/**
* @author jmo
Expand Down Expand Up @@ -114,6 +118,34 @@ public boolean removeByAppId(String appId) {
return repositoryProvider.listBy(appId).isEmpty() || repositoryProvider.removeByAppId(appId);
}

protected Pair<Map<String, String>, Map<String, Dependency>> getOperationAndDependencyInfos(
List<T> configs,
ApplicationOperationConfigurationRepositoryImpl applicationOperationConfigurationRepository,
AppContractRepository appContractRepository) {
Map<String, String> operationInfos = new HashMap<>();
Map<String, Dependency> dependencyInfos = new HashMap<>();
for (T item : configs) {
operationInfos.put(item.getOperationId(), null);
dependencyInfos.put(item.getDependencyId(), null);
}
List<ApplicationOperationConfiguration> operationConfigurations =
applicationOperationConfigurationRepository.queryByOperationIdList(operationInfos.keySet());
for (ApplicationOperationConfiguration operationConfiguration : operationConfigurations) {
operationInfos.put(operationConfiguration.getId(), operationConfiguration.getOperationName());
}

List<AppContractDto> appContractDtos = appContractRepository.queryAppContractsByIds(
dependencyInfos.keySet());
for (AppContractDto appContractDto : appContractDtos) {
Dependency dependency = new Dependency();
dependency.setDependencyId(appContractDto.getId());
dependency.setOperationType(appContractDto.getOperationType());
dependency.setOperationName(appContractDto.getOperationName());
dependencyInfos.put(appContractDto.getId(), dependency);
}
return Pair.of(operationInfos, dependencyInfos);
}

void addDependencyId(List<T> comparisonDetails) {
Map<AppContractDto, String> notFoundAppContractMap = new HashMap<>();
for (T comparisonDetail : comparisonDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Deprecated
@Component
public class ComparisonEncryptionConfigurableHandler
extends AbstractComparisonConfigurableHandler<ComparisonEncryptionConfiguration> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package com.arextest.web.core.business.config.replay;

import com.arextest.config.model.dto.application.ApplicationOperationConfiguration;
import com.arextest.config.model.dto.application.Dependency;
import com.arextest.config.repository.ConfigRepositoryProvider;
import com.arextest.config.repository.impl.ApplicationOperationConfigurationRepositoryImpl;
import com.arextest.web.core.business.config.application.ApplicationOperationConfigurableHandler;
import com.arextest.web.core.repository.AppContractRepository;
import com.arextest.web.core.repository.FSInterfaceRepository;
import com.arextest.web.core.repository.mongo.ComparisonExclusionsConfigurationRepositoryImpl;
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.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryComparisonResultDto;
import com.arextest.web.model.dto.filesystem.FSInterfaceDto;
import java.util.List;
import com.arextest.web.model.mapper.PageQueryComparisonMapper;
import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -27,6 +37,10 @@ public class ComparisonExclusionsConfigurableHandler
ApplicationOperationConfigurableHandler applicationOperationConfigurableHandler;
@Resource
ComparisonExclusionsConfigurationRepositoryImpl comparisonExclusionsConfigurationRepository;
@Resource
ApplicationOperationConfigurationRepositoryImpl applicationOperationConfigurationRepository;
@Resource
AppContractRepository appContractRepository;

protected ComparisonExclusionsConfigurableHandler(
@Autowired ConfigRepositoryProvider<ComparisonExclusionsConfiguration> repositoryProvider,
Expand Down Expand Up @@ -63,4 +77,43 @@ public List<ComparisonExclusionsConfiguration> queryByInterfaceId(String interfa
}
return result;
}

public PageQueryComparisonResponseType pageQueryComparisonConfig(
PageQueryComparisonRequestType requestType) {
PageQueryComparisonDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract(
requestType);
PageQueryComparisonResultDto<ComparisonExclusionsConfiguration> queryResult =
comparisonExclusionsConfigurationRepository.pageQueryComparisonConfig(
pageQueryComparisonDto);

// get the information of interface and dependency involved in the configuration
List<ComparisonExclusionsConfiguration> configs = queryResult.getConfigs();
Pair<Map<String, String>, Map<String, Dependency>> operationAndDependencyInfos =
getOperationAndDependencyInfos(configs, applicationOperationConfigurationRepository,
appContractRepository);
Map<String, String> operationInfos = operationAndDependencyInfos.getLeft();
Map<String, Dependency> dependencyInfos = operationAndDependencyInfos.getRight();
PageQueryComparisonResponseType result = new PageQueryComparisonResponseType();
result.setTotalCount(queryResult.getTotalCount());
result.setExclusions(contractFromDto(configs, operationInfos, dependencyInfos));
return result;
}

private List<PageQueryComparisonResponseType.ExclusionInfo> contractFromDto(
List<ComparisonExclusionsConfiguration> dto, Map<String, String> operationInfo,
Map<String, Dependency> dependencyInfo) {
List<PageQueryComparisonResponseType.ExclusionInfo> result = new ArrayList<>();
for (ComparisonExclusionsConfiguration item : dto) {
if (item.getOperationId() != null && operationInfo.get(item.getOperationId()) == null) {
continue;
}
if (item.getDependencyId() != null && dependencyInfo.get(item.getDependencyId()) == null) {
continue;
}
result.add(
PageQueryComparisonMapper.INSTANCE.contractFromDto(item, operationInfo, dependencyInfo));
}
return result;
}

}
Loading

0 comments on commit 35b0a87

Please sign in to comment.