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

com.arextest.web.model.mapper.PageQueryComparisonMapper Maven / Gradle / Ivy

The newest version!
package com.arextest.web.model.mapper;

import com.arextest.config.model.dto.application.Dependency;
import com.arextest.web.model.contract.contracts.compare.TransformDetail;
import com.arextest.web.model.contract.contracts.config.replay.AbstractComparisonDetailsConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonExclusionsConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonIgnoreCategoryConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonInclusionsConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonListSortConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonReferenceConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonScriptConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.ComparisonTransformConfiguration;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryCategoryRequestType;
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.contract.contracts.config.replay.PageQueryExclusionRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryListSortRequestType;
import com.arextest.web.model.contract.contracts.config.replay.PageQueryTransformRequestType;
import com.arextest.web.model.dto.config.PageQueryCategoryDto;
import com.arextest.web.model.dto.config.PageQueryComparisonDto;
import com.arextest.web.model.dto.config.PageQueryExclusionDto;
import com.arextest.web.model.dto.config.PageQueryListSortDto;
import com.arextest.web.model.dto.config.PageQueryTransformDto;
import java.util.Map;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

@Mapper
public interface PageQueryComparisonMapper {


  PageQueryComparisonMapper INSTANCE = Mappers.getMapper(PageQueryComparisonMapper.class);

  PageQueryComparisonDto dtoFromContract(PageQueryComparisonRequestType contract);
  PageQueryExclusionDto dtoFromContract(PageQueryExclusionRequestType contract);
  PageQueryListSortDto dtoFromContract(PageQueryListSortRequestType contract);
  PageQueryCategoryDto dtoFromContract(PageQueryCategoryRequestType contract);
  PageQueryTransformDto dtoFromContract(PageQueryTransformRequestType contract);

  @Mappings({
      @Mapping(target = "exclusionPath", source = "dto.exclusions"),
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.ExclusionInfo contractFromDto(
      ComparisonExclusionsConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);

  @Mappings({
      @Mapping(target = "inclusionPath", source = "dto.inclusions"),
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.InclusionInfo contractFromDto(
      ComparisonInclusionsConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);


  @Mappings({
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.IgnoreCategoryInfo contractFromDto(
      ComparisonIgnoreCategoryConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);

  @Mappings({
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.ListSortInfo contractFromDto(
      ComparisonListSortConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);

  @Mappings({
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.ReferenceInfo contractFromDto(
      ComparisonReferenceConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);

  @Mappings({
      @Mapping(target = "transformMethodName", source = "dto.transformDetail", qualifiedByName = "toTransformMethodName"),
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.RootTransformInfo contractFromDto(
      ComparisonTransformConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);

  @Mappings({
      @Mapping(target = "operationName", source = "dto", qualifiedByName = "getOperationName"),
      @Mapping(target = "dependencyName", source = "dto", qualifiedByName = "getDependencyName"),
      @Mapping(target = "dependencyType", source = "dto", qualifiedByName = "getDependencyType"),
      @Mapping(target = "expirationDate", expression = "java(dto.getExpirationDate() != null ? dto.getExpirationDate().getTime() : null)"),
  })
  PageQueryComparisonResponseType.ScriptInfo contractFromDto(
      ComparisonScriptConfiguration dto, @Context Map operationInfo,
      @Context Map dependencyInfo);



  @Named("getOperationName")
  default  String getOperationName(T dto,
      @Context Map operationInfo) {
    return operationInfo.get(dto.getOperationId());
  }

  @Named("getDependencyName")
  default  String getDependencyName(T dto,
      @Context Map dependencyInfo) {
    String dependencyId = dto.getDependencyId();
    if (dependencyId == null) {
      return null;
    }
    Dependency dependency = dependencyInfo.get(dependencyId);
    if (dependency == null) {
      return null;
    }
    return dependency.getOperationName();
  }

  @Named("getDependencyType")
  default  String getDependencyType(T dto,
      @Context Map dependencyInfo) {
    String dependencyId = dto.getDependencyId();
    if (dependencyId == null) {
      return null;
    }
    Dependency dependency = dependencyInfo.get(dependencyId);
    if (dependency == null) {
      return null;
    }
    return dependency.getOperationType();
  }

  @Named("toTransformMethodName")
  default String toTransformMethodName(TransformDetail transformDetail) {
    return transformDetail.getTransformMethods().get(0).getMethodName();
  }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy