Skip to content

Commit

Permalink
feat: query compareConfig with operationName
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen9 committed Jun 28, 2024
1 parent 03a507b commit 0b38ba5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.arextest.web.core.business.config.application;

import com.arextest.config.model.dao.config.ServiceOperationCollection;
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.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;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
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 Expand Up @@ -68,4 +75,21 @@ public ApplicationOperationConfiguration useResultByOperationId(String operation
result.setDependencyList(dependencyList);
return result;
}

public List<ApplicationOperationConfiguration> queryOperationByName(String appId,
String operationName) {
Map<String, Object> queryConditions = new HashMap<>(2);
queryConditions.put(ServiceOperationCollection.Fields.appId, appId);
if (operationName != null) {
queryConditions.put(ServiceOperationCollection.Fields.operationName, operationName);
}
List<ApplicationOperationConfiguration> applicationOperationConfigurations =
applicationOperationConfigurationRepository.queryByMultiCondition(queryConditions);
if (CollectionUtils.isEmpty(applicationOperationConfigurations)) {
return Collections.emptyList();
}
return applicationOperationConfigurations;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.business.config.application.ApplicationOperationConfigurableHandler;
import com.arextest.web.core.repository.AppContractRepository;
import com.arextest.web.model.contract.contracts.common.enums.ExpirationType;
import com.arextest.web.model.contract.contracts.compare.CategoryDetail;
Expand Down Expand Up @@ -47,7 +48,6 @@
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -70,6 +70,9 @@ public class ComparisonSummaryService {
@Resource
ApplicationOperationConfigurationRepositoryImpl applicationOperationConfigurationRepositoryImpl;

@Resource
ApplicationOperationConfigurableHandler applicationOperationConfigurableHandler;

@Resource
ConfigLoadService configLoadService;

Expand Down Expand Up @@ -164,8 +167,8 @@ public ReplayCompareConfig getReplayComparisonConfig(String appId, String operat
Map<String, ReplayCompareConfig.ReplayComparisonItem> replayComparisonItemMap;

// build operation config and global config
AppOperationAndDependencyInfo appOperationAndDependencyInfo = this.getOperationInfos(appId);
this.filterOperationInfo(appOperationAndDependencyInfo, operationName);
AppOperationAndDependencyInfo appOperationAndDependencyInfo = this.getOperationInfos(appId,
operationName);

Map<String, ApplicationOperationConfiguration> operationInfoMap =
appOperationAndDependencyInfo.getOperationMap();
Expand Down Expand Up @@ -254,35 +257,6 @@ protected void getAdditionalComparisonConfiguration(String interfaceId,
}
// endregion

protected void filterOperationInfo(AppOperationAndDependencyInfo appOperationAndDependencyInfo,
String operationName) {
if (StringUtils.isEmpty(operationName)) {
return;
}

// filter operation info
Map<String, ApplicationOperationConfiguration> operationMap = appOperationAndDependencyInfo.getOperationMap();
Map<String, ApplicationOperationConfiguration> filteredOperationMap = new HashMap<>();
for (Map.Entry<String, ApplicationOperationConfiguration> entry : operationMap.entrySet()) {
if (Objects.equals(entry.getValue().getOperationName(), operationName)) {
filteredOperationMap.put(entry.getKey(), entry.getValue());
}
}
appOperationAndDependencyInfo.setOperationMap(filteredOperationMap);

// filter dependency info
Set<String> operationIds = filteredOperationMap.keySet();
Map<String, Map<String, AppContractDto>> appContractDtoMap = appOperationAndDependencyInfo.getAppContractDtoMap();
Map<String, Map<String, AppContractDto>> filteredAppContractDtoMap = new HashMap<>();
for (String operationId : operationIds) {
Map<String, AppContractDto> dependencyAppContract = appContractDtoMap.get(operationId);
if (dependencyAppContract != null) {
filteredAppContractDtoMap.put(operationId, dependencyAppContract);
}
}
appOperationAndDependencyInfo.setAppContractDtoMap(filteredAppContractDtoMap);
}

protected Map<String, ReplayCompareConfig.ReplayComparisonItem> buildMultiConfiguration(
String appId,
Map<String, ApplicationOperationConfiguration> operationInfoMap,
Expand Down Expand Up @@ -376,6 +350,7 @@ protected Map<String, ReplayCompareConfig.ReplayComparisonItem> buildMultiConfig
* @param appId appId
* @return Map<String, ApplicationOperationConfiguration>
*/
@Deprecated
protected AppOperationAndDependencyInfo getOperationInfos(String appId) {
AppOperationAndDependencyInfo appOperationAndDependencyInfo = new AppOperationAndDependencyInfo();

Expand Down Expand Up @@ -409,6 +384,31 @@ protected AppOperationAndDependencyInfo getOperationInfos(String appId) {
return appOperationAndDependencyInfo;
}

protected AppOperationAndDependencyInfo getOperationInfos(String appId, String operationName) {
AppOperationAndDependencyInfo appOperationAndDependencyInfo = new AppOperationAndDependencyInfo();

List<ApplicationOperationConfiguration> applicationOperationConfigurations =
applicationOperationConfigurableHandler.queryOperationByName(appId, operationName);
Map<String, ApplicationOperationConfiguration> operationMap = applicationOperationConfigurations.stream()
.collect(Collectors.toMap(ApplicationOperationConfiguration::getId, Function.identity()));

List<String> operationIdList = new ArrayList<>(operationMap.keySet());
// appContractDtoList filter the operation and group by operationId
List<AppContractDto> appContractDtos = appContractRepository.queryAppContractListByOpIds(
operationIdList,
Collections.singletonList(AppContractCollection.Fields.contract));
Map<String,
Map<String, AppContractDto>> appContractDtoMap = appContractDtos.stream()
.filter(
item -> Objects.equals(item.getContractType(), ContractTypeEnum.DEPENDENCY.getCode()))
.collect(Collectors.groupingBy(AppContractDto::getOperationId,
Collectors.toMap(AppContractDto::getId, Function.identity())));

appOperationAndDependencyInfo.setOperationMap(operationMap);
appOperationAndDependencyInfo.setAppContractDtoMap(appContractDtoMap);
return appOperationAndDependencyInfo;
}

protected <T extends AbstractComparisonDetailsConfiguration> void buildComparisonConfig(
Map<String, ReplayCompareConfig.ReplayComparisonItem> replayConfigurationMap,
List<T> configurations,
Expand Down

0 comments on commit 0b38ba5

Please sign in to comment.