-
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
Jun 27, 2024
1 parent
ff49de6
commit 9d3dc97
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...ava/com/arextest/web/api/service/controller/config/ComparisonRootTransformController.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,81 @@ | ||
package com.arextest.web.api.service.controller.config; | ||
|
||
import com.arextest.common.annotation.AppAuth; | ||
import com.arextest.common.model.response.Response; | ||
import com.arextest.common.utils.ResponseUtils; | ||
import com.arextest.config.model.dto.ModifyType; | ||
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.QueryComparisonRequestType; | ||
import com.arextest.web.model.mapper.ConfigComparisonTransformMapper; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Resource; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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 | ||
@RequestMapping("/api/config/comparison/rootTransform") | ||
public class ComparisonRootTransformController { | ||
|
||
@Resource | ||
ComparisonTransformConfigurableHandler comparisonTransformConfigurableHandler; | ||
|
||
|
||
@PostMapping("/queryComparisonConfig") | ||
@ResponseBody | ||
public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType request) { | ||
List<ComparisonTransformConfiguration> configs = comparisonTransformConfigurableHandler. | ||
queryComparisonConfig(request.getAppId(), request.getOperationId(), | ||
request.getOperationType(), request.getOperationName()); | ||
if (Boolean.TRUE.equals(request.getFilterExpired()) && CollectionUtils.isNotEmpty(configs)) { | ||
configs.removeIf( | ||
config -> comparisonTransformConfigurableHandler.removeDetailsExpired(config)); | ||
} | ||
List<ComparisonRootTransformConfiguration> rootTransformConfigurations = configs.stream() | ||
.map(ConfigComparisonTransformMapper.INSTANCE::requestTypeFromDto).filter(item -> { | ||
if (item.getTransformMethodName() != null) { | ||
return true; | ||
} | ||
return false; | ||
}).collect(Collectors.toList()); | ||
return ResponseUtils.successResponse(rootTransformConfigurations); | ||
} | ||
|
||
|
||
@PostMapping("/modify/{modifyType}") | ||
@ResponseBody | ||
@AppAuth | ||
public Response modify(@PathVariable ModifyType modifyType, | ||
@RequestBody ComparisonRootTransformConfiguration configuration) | ||
throws Exception { | ||
if (modifyType == ModifyType.INSERT) { | ||
configuration.validParameters(); | ||
ComparisonTransformConfiguration transformConfiguration = | ||
ConfigComparisonTransformMapper.INSTANCE.dotFromRequestType(configuration); | ||
return ResponseUtils.successResponse( | ||
comparisonTransformConfigurableHandler.insert(transformConfiguration)); | ||
} | ||
if (modifyType == ModifyType.UPDATE) { | ||
ComparisonTransformConfiguration transformConfiguration = | ||
ConfigComparisonTransformMapper.INSTANCE.dotFromRequestType(configuration); | ||
return ResponseUtils.successResponse( | ||
comparisonTransformConfigurableHandler.update(transformConfiguration)); | ||
} | ||
if (modifyType == ModifyType.REMOVE) { | ||
ComparisonTransformConfiguration transformConfiguration = | ||
ConfigComparisonTransformMapper.INSTANCE.dotFromRequestType(configuration); | ||
return ResponseUtils.successResponse( | ||
comparisonTransformConfigurableHandler.remove(transformConfiguration)); | ||
} | ||
return ResponseUtils.resourceNotFoundResponse(); | ||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...test/web/model/contract/contracts/config/replay/ComparisonRootTransformConfiguration.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,25 @@ | ||
package com.arextest.web.model.contract.contracts.config.replay; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
public class ComparisonRootTransformConfiguration extends AbstractComparisonDetailsConfiguration { | ||
|
||
private String transformMethodName; | ||
|
||
@Override | ||
public void validParameters() throws Exception { | ||
super.validParameters(); | ||
if (StringUtils.isEmpty(transformMethodName)) { | ||
throw new Exception("transformMethodName cannot be empty"); | ||
} | ||
} | ||
|
||
} |
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