All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.web.api.service.controller.config.ComparisonRootTransformController Maven / Gradle / Ivy

The newest version!
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.PageQueryComparisonRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryTransformRequestType;
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 jakarta.annotation.Resource;
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")
  public Response queryComparisonConfig(@RequestBody QueryComparisonRequestType request) {
    List configs = comparisonTransformConfigurableHandler.
        queryComparisonConfig(request.getAppId(), request.getOperationId(),
            request.getOperationType(), request.getOperationName());
    comparisonTransformConfigurableHandler.removeDetailsExpired(configs,
        request.getFilterExpired());
    List rootTransformConfigurations = configs.stream()
        .map(ConfigComparisonTransformMapper.INSTANCE::requestTypeFromDto)
        .filter(item -> item.getTransformMethodName() != null)
        .collect(Collectors.toList());
    return ResponseUtils.successResponse(rootTransformConfigurations);
  }


  @PostMapping("/modify/{modifyType}")
  @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();
  }

  @PostMapping("/pageQueryComparisonConfig")
  @ResponseBody
  public Response pageQueryComparisonConfig(@RequestBody PageQueryTransformRequestType request) {
    return ResponseUtils.successResponse(
        comparisonTransformConfigurableHandler.pageQueryComparisonConfig(request)
    );
  }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy