AssetMetadataMapper.java

1
package org.cardanofoundation.explorer.api.mapper;
2
3
import java.util.Objects;
4
5
import org.springframework.beans.factory.annotation.Value;
6
7
import org.apache.commons.lang3.StringUtils;
8
import org.mapstruct.Mapper;
9
import org.mapstruct.Mapping;
10
import org.mapstruct.Named;
11
12
import org.cardanofoundation.explorer.api.model.response.token.TokenFilterResponse;
13
import org.cardanofoundation.explorer.api.model.response.token.TokenMetadataResponse;
14
import org.cardanofoundation.explorer.api.projection.TokenProjection;
15
import org.cardanofoundation.explorer.common.entity.ledgersync.AssetMetadata;
16
17
@Mapper(componentModel = "spring")
18
public abstract class AssetMetadataMapper {
19
20
  @Value("${application.token-logo-endpoint}")
21
  protected String tokenLogoEndpoint;
22
23
  @Mapping(target = "createdOn", source = "time")
24
  @Mapping(
25
      target = "displayName",
26
      expression =
27
          "java(getDisplayName(tokenProjection.getNameView(), tokenProjection.getFingerprint()))")
28
  @Mapping(target = "metadata", expression = "java(getMetadata(tokenProjection))")
29
  public abstract TokenFilterResponse fromTokenProjectionToTokenFilterResponse(
30
      TokenProjection tokenProjection);
31
32
  @Mapping(target = "displayName", source = "nameView")
33
  @Mapping(target = "createdOn", source = "time")
34
  @Mapping(target = "metadata", expression = "java(getMetadata(tokenProjection))")
35
  public abstract TokenFilterResponse fromTokenProjectionToFilterResponse(
36
      TokenProjection tokenProjection);
37
38
  @Mapping(target = "logo", source = "logo", qualifiedByName = "getTokenLogoURL")
39
  public abstract TokenMetadataResponse fromAssetMetadata(AssetMetadata metadata);
40
41
  @Named("getTokenLogoURL")
42
  String getTokenLogoEndpoint(String logo) {
43 2 1. getTokenLogoEndpoint : negated conditional → NO_COVERAGE
2. getTokenLogoEndpoint : replaced return value with "" for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getTokenLogoEndpoint → NO_COVERAGE
    return Objects.isNull(logo) ? null : (tokenLogoEndpoint + logo);
44
  }
45
46
  TokenMetadataResponse getMetadata(TokenProjection tokenProjection) {
47 1 1. getMetadata : negated conditional → SURVIVED
    if (StringUtils.isEmpty(tokenProjection.getSubject())) {
48
      return null;
49
    }
50
    TokenMetadataResponse tokenMetadataResponse = new TokenMetadataResponse();
51 1 1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setUrl → NO_COVERAGE
    tokenMetadataResponse.setUrl(tokenProjection.getUrl());
52 1 1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setTicker → NO_COVERAGE
    tokenMetadataResponse.setTicker(tokenProjection.getTicker());
53 1 1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setLogo → NO_COVERAGE
    tokenMetadataResponse.setLogo(getTokenLogoEndpoint(tokenProjection.getLogo()));
54 1 1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setDecimals → NO_COVERAGE
    tokenMetadataResponse.setDecimals(tokenProjection.getDecimals());
55 1 1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setDescription → NO_COVERAGE
    tokenMetadataResponse.setDescription(tokenProjection.getDescription());
56 1 1. getMetadata : replaced return value with null for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getMetadata → NO_COVERAGE
    return tokenMetadataResponse;
57
  }
58
59
  String getDisplayName(String nameView, String fingerprint) {
60 1 1. getDisplayName : negated conditional → NO_COVERAGE
    if (!StringUtils.isEmpty(nameView)) {
61 1 1. getDisplayName : replaced return value with "" for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getDisplayName → NO_COVERAGE
      return nameView;
62
    } else {
63 1 1. getDisplayName : replaced return value with "" for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getDisplayName → NO_COVERAGE
      return fingerprint;
64
    }
65
  }
66
}

Mutations

43

1.1
Location : getTokenLogoEndpoint
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getTokenLogoEndpoint
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getTokenLogoEndpoint → NO_COVERAGE

47

1.1
Location : getMetadata
Killed by : none
negated conditional → SURVIVED

51

1.1
Location : getMetadata
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setUrl → NO_COVERAGE

52

1.1
Location : getMetadata
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setTicker → NO_COVERAGE

53

1.1
Location : getMetadata
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setLogo → NO_COVERAGE

54

1.1
Location : getMetadata
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setDecimals → NO_COVERAGE

55

1.1
Location : getMetadata
Killed by : none
removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setDescription → NO_COVERAGE

56

1.1
Location : getMetadata
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getMetadata → NO_COVERAGE

60

1.1
Location : getDisplayName
Killed by : none
negated conditional → NO_COVERAGE

61

1.1
Location : getDisplayName
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getDisplayName → NO_COVERAGE

63

1.1
Location : getDisplayName
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/mapper/AssetMetadataMapper::getDisplayName → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2