diff --git a/arex-web-api/src/main/java/com/arextest/web/api/service/controller/ReportQueryController.java b/arex-web-api/src/main/java/com/arextest/web/api/service/controller/ReportQueryController.java index a579f6de..b6fa84ba 100644 --- a/arex-web-api/src/main/java/com/arextest/web/api/service/controller/ReportQueryController.java +++ b/arex-web-api/src/main/java/com/arextest/web/api/service/controller/ReportQueryController.java @@ -454,6 +454,12 @@ public Response queryContract(@Valid @RequestBody QueryContractRequestType reque return ResponseUtils.successResponse(schemaInferService.queryContract(requestType)); } + @PostMapping("/queryAllContracts") + @ResponseBody + public Response queryAllContracts(@Valid @RequestBody QueryContractRequestType requestType) { + return ResponseUtils.successResponse(schemaInferService.queryAllContracts(requestType)); + } + @PostMapping("/queryFlatContract") @ResponseBody public Response queryFlatContract(@Valid @RequestBody QueryContractRequestType requestType) { diff --git a/arex-web-core/src/main/java/com/arextest/web/core/business/SchemaInferService.java b/arex-web-core/src/main/java/com/arextest/web/core/business/SchemaInferService.java index 43dd3351..3acb63fe 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/business/SchemaInferService.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/business/SchemaInferService.java @@ -2,6 +2,7 @@ import com.arextest.config.model.dto.application.ApplicationOperationConfiguration; import com.arextest.config.repository.impl.ApplicationOperationConfigurationRepositoryImpl; +import com.arextest.model.mock.MockCategoryType; import com.arextest.web.common.LogUtils; import com.arextest.web.core.business.util.SchemaUtils; import com.arextest.web.core.repository.AppContractRepository; @@ -26,9 +27,19 @@ import com.google.common.collect.Lists; import com.saasquatch.jsonschemainferrer.JsonSchemaInferrer; import com.saasquatch.jsonschemainferrer.SpecVersion; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -36,13 +47,6 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.springframework.stereotype.Component; @Slf4j @Component @@ -62,6 +66,10 @@ public class SchemaInferService { private static final ObjectMapper CONTRACT_OBJ_MAPPER = new ObjectMapper(); private static final JsonSchemaInferrer INFERRER = JsonSchemaInferrer.newBuilder().setSpecVersion(SpecVersion.DRAFT_06).build(); + private static final Set EXCLUDE_OPERATION_TYPE = new HashSet<>(Arrays.asList( + MockCategoryType.REDIS.getName(), + MockCategoryType.DATABASE.getName())); + @Resource private ReplayCompareResultRepository replayCompareResultRepository; @Resource @@ -128,6 +136,21 @@ public AppContractDto queryContract(QueryContractRequestType requestType) { return null; } + public List queryAllContracts(QueryContractRequestType requestType) { + List appContractList = new ArrayList<>(); + if (requestType.getAppId() != null && requestType.getOperationId() != null) { + List appContractDtos = appContractRepository.queryAppContracts(requestType.getAppId(), + requestType.getOperationId()) + .stream() + .filter(appContractDto -> !EXCLUDE_OPERATION_TYPE.contains(appContractDto.getOperationType())) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(appContractDtos)) { + appContractList.addAll(appContractDtos); + } + } + return appContractList; + } + public Set queryFlatContract(QueryContractRequestType requestType) { AppContractDto appContractDto = queryContract(requestType); return SchemaUtils.getFlatContract(appContractDto.getContract()); @@ -201,6 +224,8 @@ public SyncResponseContractResponseType syncResponseContract( entryPointApplication.setContract(perceiveContract(latestNEntryCompareResults)); entryPointApplication.setAppId(applicationOperationConfiguration.getAppId()); entryPointApplication.setContractType(ContractTypeEnum.ENTRY.getCode()); + entryPointApplication.setOperationType(applicationOperationConfiguration.getOperationType()); + entryPointApplication.setOperationName(applicationOperationConfiguration.getOperationName()); upserts.add(entryPointApplication); dependencyMap.values().forEach(list -> { diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/AppContractRepository.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/AppContractRepository.java index 6b2d00c8..9e72012c 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/AppContractRepository.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/AppContractRepository.java @@ -22,6 +22,8 @@ List queryAppContractListByOpIds(List operationList, AppContractDto queryDependency(String operationId, String operationType, String operationName); + List queryAppContracts(String appId, String operationId); + List queryDependencyWithAppId(String appId, String operationName, String operationType); } diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java index 2babbfb3..8d8e9a79 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java @@ -180,6 +180,15 @@ public AppContractDto queryDependency(String operationId, String operationType, return AppContractMapper.INSTANCE.dtoFromDao(dao); } + @Override + public List queryAppContracts(String appId, String operationId) { + Query query = Query.query( + Criteria.where(AppContractCollection.Fields.operationId).is(operationId) + .and(AppContractCollection.Fields.appId).is(appId)); + List daos = mongoTemplate.find(query, AppContractCollection.class); + return daos.stream().map(AppContractMapper.INSTANCE::dtoFromDao).collect(Collectors.toList()); + } + @Override public List queryDependencyWithAppId(String appId, String operationName, String operationType) {