MetadataCIP83Utils.java

1
package org.cardanofoundation.explorer.api.util;
2
3
import java.util.*;
4
5
import lombok.AccessLevel;
6
import lombok.NoArgsConstructor;
7
import lombok.extern.slf4j.Slf4j;
8
9
import com.fasterxml.jackson.core.type.TypeReference;
10
import com.fasterxml.jackson.databind.ObjectMapper;
11
12
import org.cardanofoundation.explorer.api.common.enumeration.FormatFieldType;
13
import org.cardanofoundation.explorer.api.common.enumeration.MetadataField;
14
import org.cardanofoundation.explorer.api.model.metadatastandard.BaseProperty;
15
16
@NoArgsConstructor(access = AccessLevel.PRIVATE)
17
@Slf4j
18
public class MetadataCIP83Utils {
19
20
  private static final String FIELD_REQUIRED_PROPERTIES = "requiredProperties";
21
  private static final String FIELD_VALID = "valid";
22
23
  @SuppressWarnings("unchecked")
24
  public static Map<String, Object> standard(String jsonMetadata) {
25
    Map<String, Object> metadataCIP = new HashMap<>();
26
    List<BaseProperty> requiredProperties = new ArrayList<>();
27
28
    try {
29
      ObjectMapper objectMapper = new ObjectMapper();
30
      Map<Object, Object> metadataMap =
31
          objectMapper.readValue(jsonMetadata, new TypeReference<>() {});
32
33
      var enc = metadataMap.get(MetadataField.ENC.getName());
34
      var msg = metadataMap.get(MetadataField.MSG.getName());
35
36
      requiredProperties.add(MetadataCIP20Utils.msg(msg, "1"));
37
      requiredProperties.add(enc(enc, "2"));
38
39
    } catch (Exception ex) {
40
      log.error("Error: structure incorrect, message=" + ex.getMessage());
41
      log.error("Check standard CIP-83 fail");
42
    }
43
44
    metadataCIP.put(FIELD_REQUIRED_PROPERTIES, requiredProperties);
45
    metadataCIP.put(FIELD_VALID, isCIPValid(requiredProperties));
46 1 1. standard : replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::standard → NO_COVERAGE
    return metadataCIP;
47
  }
48
49
  public static BaseProperty enc(Object enc, String index) {
50
    FormatFieldType formatFieldType = MetadataFieldUtils.getFormatTypeByObject(enc);
51
    boolean isValid =
52 1 1. enc : negated conditional → NO_COVERAGE
        FormatFieldType.STRING.equals(formatFieldType)
53 1 1. enc : negated conditional → NO_COVERAGE
            || FormatFieldType.STRING.equals(formatFieldType.getParentType());
54 1 1. enc : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::enc → NO_COVERAGE
    return BaseProperty.builder()
55
        .index(index)
56
        .property(MetadataField.ENC.getName())
57
        .format(FormatFieldType.STRING.getValue())
58
        .valid(isValid)
59 1 1. enc : negated conditional → NO_COVERAGE
        .valueFormat(isValid ? FormatFieldType.STRING.getValue() : formatFieldType.getValue())
60
        .value(enc)
61
        .build();
62
  }
63
64
  public static boolean isCIPValid(List<BaseProperty> baseProperties) {
65 1 1. isCIPValid : negated conditional → NO_COVERAGE
    if (baseProperties.isEmpty()) {
66 1 1. isCIPValid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::isCIPValid → NO_COVERAGE
      return false;
67
    }
68 2 1. isCIPValid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::isCIPValid → NO_COVERAGE
2. isCIPValid : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::isCIPValid → NO_COVERAGE
    return baseProperties.stream()
69 2 1. lambda$isCIPValid$0 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::lambda$isCIPValid$0 → NO_COVERAGE
2. lambda$isCIPValid$0 : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::lambda$isCIPValid$0 → NO_COVERAGE
        .allMatch(baseProperty -> baseProperty.getValid().equals(Boolean.TRUE));
70
  }
71
}

Mutations

46

1.1
Location : standard
Killed by : none
replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::standard → NO_COVERAGE

52

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

53

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

54

1.1
Location : enc
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::enc → NO_COVERAGE

59

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

65

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

66

1.1
Location : isCIPValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::isCIPValid → NO_COVERAGE

68

1.1
Location : isCIPValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::isCIPValid → NO_COVERAGE

2.2
Location : isCIPValid
Killed by : none
replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::isCIPValid → NO_COVERAGE

69

1.1
Location : lambda$isCIPValid$0
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::lambda$isCIPValid$0 → NO_COVERAGE

2.2
Location : lambda$isCIPValid$0
Killed by : none
replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP83Utils::lambda$isCIPValid$0 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2