-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rchen9
committed
Nov 13, 2024
1 parent
6fb456a
commit ef6aa37
Showing
8 changed files
with
521 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...om/arextest/web/api/service/controller/config/ComparisonScriptConfigurableController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.arextest.web.api.service.controller.config; | ||
|
||
import com.arextest.common.model.response.Response; | ||
import com.arextest.common.utils.ResponseUtils; | ||
import com.arextest.web.core.business.config.ConfigurableHandler; | ||
import com.arextest.web.core.business.config.replay.ComparisonScriptConfigurableHandler; | ||
import com.arextest.web.model.contract.contracts.config.replay.ComparisonScriptConfiguration; | ||
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 java.util.List; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Controller; | ||
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.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
@RequestMapping("/api/config/comparison/script") | ||
public class ComparisonScriptConfigurableController extends | ||
AbstractConfigurableController<ComparisonScriptConfiguration> { | ||
|
||
@Resource | ||
ComparisonScriptConfigurableHandler scriptConfigurableHandler; | ||
|
||
protected ComparisonScriptConfigurableController( | ||
ConfigurableHandler<ComparisonScriptConfiguration> configurableHandler) { | ||
super(configurableHandler); | ||
} | ||
|
||
/** | ||
* query config which is compareConfig =1 | ||
* | ||
* @param interfaceId | ||
* @return | ||
*/ | ||
@RequestMapping("/queryByInterfaceId") | ||
@ResponseBody | ||
public Response queryByInterfaceId(@RequestParam String interfaceId, | ||
@RequestParam(defaultValue = "false") Boolean filterExpired) { | ||
if (StringUtils.isEmpty(interfaceId)) { | ||
return InvalidResponse.REQUESTED_INTERFACE_ID_IS_EMPTY; | ||
} | ||
List<ComparisonScriptConfiguration> configs = scriptConfigurableHandler.queryByInterfaceId( | ||
interfaceId); | ||
scriptConfigurableHandler.removeDetailsExpired(configs, filterExpired); | ||
return ResponseUtils.successResponse(configs); | ||
} | ||
|
||
@PostMapping("/queryComparisonConfig") | ||
@ResponseBody | ||
public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType request) { | ||
List<ComparisonScriptConfiguration> configs = scriptConfigurableHandler.queryComparisonConfig( | ||
request.getAppId(), request.getOperationId(), request.getOperationType(), | ||
request.getOperationName()); | ||
scriptConfigurableHandler.removeDetailsExpired(configs, request.getFilterExpired()); | ||
return ResponseUtils.successResponse(configs); | ||
} | ||
|
||
@PostMapping("/pageQueryComparisonConfig") | ||
@ResponseBody | ||
public Response pageQueryComparisonConfig(@RequestBody PageQueryComparisonRequestType request) { | ||
return ResponseUtils.successResponse( | ||
scriptConfigurableHandler.pageQueryComparisonConfig(request) | ||
); | ||
} | ||
|
||
|
||
} |
110 changes: 110 additions & 0 deletions
110
...ava/com/arextest/web/core/business/config/replay/ComparisonScriptConfigurableHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
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.ComparisonScriptConfigurationRepositoryImpl; | ||
import com.arextest.web.model.contract.contracts.config.replay.ComparisonScriptConfiguration; | ||
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 com.arextest.web.model.mapper.PageQueryComparisonMapper; | ||
import jakarta.annotation.Resource; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class ComparisonScriptConfigurableHandler extends | ||
AbstractComparisonConfigurableHandler<ComparisonScriptConfiguration> { | ||
|
||
@Resource | ||
FSInterfaceRepository fsInterfaceRepository; | ||
|
||
@Resource | ||
ApplicationOperationConfigurableHandler applicationOperationConfigurableHandler; | ||
|
||
@Resource | ||
ComparisonScriptConfigurationRepositoryImpl comparisonScriptConfigurationRepository; | ||
|
||
@Resource | ||
ApplicationOperationConfigurationRepositoryImpl applicationOperationConfigurationRepository; | ||
|
||
@Resource | ||
AppContractRepository appContractRepository; | ||
|
||
protected ComparisonScriptConfigurableHandler( | ||
@Autowired ConfigRepositoryProvider<ComparisonScriptConfiguration> repositoryProvider, | ||
@Autowired AppContractRepository appContractRepository) { | ||
super(repositoryProvider, appContractRepository); | ||
} | ||
|
||
@Override | ||
public List<ComparisonScriptConfiguration> queryByInterfaceId(String interfaceId) { | ||
// get operationId | ||
FSInterfaceDto fsInterfaceDto = fsInterfaceRepository.queryInterface(interfaceId); | ||
String operationId = fsInterfaceDto == null ? null : fsInterfaceDto.getOperationId(); | ||
|
||
List<ComparisonScriptConfiguration> result = | ||
this.queryByOperationIdAndInterfaceId(interfaceId, operationId); | ||
if (StringUtils.isNotEmpty(operationId)) { | ||
ApplicationOperationConfiguration applicationOperationConfiguration = | ||
applicationOperationConfigurableHandler.useResultByOperationId(operationId); | ||
if (applicationOperationConfiguration != null) { | ||
List<ComparisonScriptConfiguration> globalConfig = | ||
this.useResultAsList(applicationOperationConfiguration.getAppId(), null); | ||
result.addAll(globalConfig); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public PageQueryComparisonResponseType pageQueryComparisonConfig( | ||
PageQueryComparisonRequestType requestType) { | ||
PageQueryComparisonDto pageQueryComparisonDto = PageQueryComparisonMapper.INSTANCE.dtoFromContract( | ||
requestType); | ||
PageQueryComparisonResultDto<ComparisonScriptConfiguration> queryResult = | ||
comparisonScriptConfigurationRepository.pageQueryComparisonConfig( | ||
pageQueryComparisonDto); | ||
|
||
// get the information of interface and dependency involved in the configuration | ||
List<ComparisonScriptConfiguration> 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.setScriptInfos(contractFromDto(configs, operationInfos, dependencyInfos)); | ||
return result; | ||
} | ||
|
||
private List<PageQueryComparisonResponseType.ScriptInfo> contractFromDto( | ||
List<ComparisonScriptConfiguration> dto, Map<String, String> operationInfo, | ||
Map<String, Dependency> dependencyInfo) { | ||
List<PageQueryComparisonResponseType.ScriptInfo> result = new ArrayList<>(); | ||
for (ComparisonScriptConfiguration 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; | ||
} | ||
|
||
} |
Oops, something went wrong.