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: improve compare config #454

Merged
merged 2 commits into from
Nov 12, 2024
Merged
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 @@ -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 Down Expand Up @@ -114,6 +117,42 @@ public boolean removeByAppId(String appId) {
return repositoryProvider.listBy(appId).isEmpty() || repositoryProvider.removeByAppId(appId);
}


protected Map<String, String> getOperationInfos(
List<T> configs,
ApplicationOperationConfigurationRepositoryImpl applicationOperationConfigurationRepository) {
Map<String, String> operationInfos = new HashMap<>();
for (T item : configs) {
operationInfos.put(item.getOperationId(), null);
}
List<ApplicationOperationConfiguration> operationConfigurations =
applicationOperationConfigurationRepository.queryByOperationIdList(operationInfos.keySet());
for (ApplicationOperationConfiguration operationConfiguration : operationConfigurations) {
operationInfos.put(operationConfiguration.getId(), operationConfiguration.getOperationName());
}
return operationInfos;
}

protected Map<String, Dependency> getDependencyInfos(
List<T> configs,
AppContractRepository appContractRepository) {
Map<String, Dependency> dependencyInfos = new HashMap<>();
for (T item : configs) {
dependencyInfos.put(item.getDependencyId(), null);
}
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 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,15 +1,24 @@
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -27,6 +36,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 +76,42 @@ 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();
Map<String, String> operationInfos = getOperationInfos(configs,
applicationOperationConfigurationRepository);
Map<String, Dependency> dependencyInfos = getDependencyInfos(configs, appContractRepository);

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
Loading