Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add queryAllContracts interface #337

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,23 +27,26 @@
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;
import java.util.Objects;
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
Expand All @@ -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<String> EXCLUDE_OPERATION_TYPE = new HashSet<>(Arrays.asList(
MockCategoryType.REDIS.getName(),
MockCategoryType.DATABASE.getName()));

@Resource
private ReplayCompareResultRepository replayCompareResultRepository;
@Resource
Expand Down Expand Up @@ -128,6 +136,21 @@ public AppContractDto queryContract(QueryContractRequestType requestType) {
return null;
}

public List<AppContractDto> queryAllContracts(QueryContractRequestType requestType) {
List<AppContractDto> appContractList = new ArrayList<>();
if (requestType.getAppId() != null && requestType.getOperationId() != null) {
List<AppContractDto> 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<String> queryFlatContract(QueryContractRequestType requestType) {
AppContractDto appContractDto = queryContract(requestType);
return SchemaUtils.getFlatContract(appContractDto.getContract());
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ List<AppContractDto> queryAppContractListByOpIds(List<String> operationList,

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

List<AppContractDto> queryAppContracts(String appId, String operationId);

List<AppContractDto> queryDependencyWithAppId(String appId, String operationName,
String operationType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ public AppContractDto queryDependency(String operationId, String operationType,
return AppContractMapper.INSTANCE.dtoFromDao(dao);
}

@Override
public List<AppContractDto> queryAppContracts(String appId, String operationId) {
Query query = Query.query(
Criteria.where(AppContractCollection.Fields.operationId).is(operationId)
.and(AppContractCollection.Fields.appId).is(appId));
List<AppContractCollection> daos = mongoTemplate.find(query, AppContractCollection.class);
return daos.stream().map(AppContractMapper.INSTANCE::dtoFromDao).collect(Collectors.toList());
}

@Override
public List<AppContractDto> queryDependencyWithAppId(String appId, String operationName,
String operationType) {
Expand Down