1 | package org.cardanofoundation.explorer.api.util; | |
2 | ||
3 | import java.util.*; | |
4 | import java.util.Map.Entry; | |
5 | ||
6 | import lombok.AccessLevel; | |
7 | import lombok.NoArgsConstructor; | |
8 | import lombok.extern.slf4j.Slf4j; | |
9 | ||
10 | import com.fasterxml.jackson.core.type.TypeReference; | |
11 | import com.fasterxml.jackson.databind.ObjectMapper; | |
12 | ||
13 | import org.cardanofoundation.explorer.api.common.enumeration.FormatFieldType; | |
14 | import org.cardanofoundation.explorer.api.common.enumeration.MetadataField; | |
15 | import org.cardanofoundation.explorer.api.model.metadatastandard.BaseProperty; | |
16 | import org.cardanofoundation.explorer.api.model.metadatastandard.cip.MetadataCIP; | |
17 | import org.cardanofoundation.explorer.api.model.metadatastandard.cip.TokenCIP; | |
18 | ||
19 | @NoArgsConstructor(access = AccessLevel.PRIVATE) | |
20 | @Slf4j | |
21 | public class MetadataCIP25Utils { | |
22 | ||
23 | public static String splitJsonMetadataByAssetName(String jsonMetadata, String assetName) { | |
24 | try { | |
25 | ObjectMapper objectMapper = new ObjectMapper(); | |
26 | Map<Object, Object> metadataMap = | |
27 | objectMapper.readValue(jsonMetadata, new TypeReference<>() {}); | |
28 | Map<Object, Object> finalMap = new HashMap<>(); | |
29 | boolean isAsset = false; | |
30 | for (Map.Entry<Object, Object> metadataEntry : metadataMap.entrySet()) { | |
31 | Object key = metadataEntry.getKey(); | |
32 | Object val = metadataEntry.getValue(); | |
33 |
1
1. splitJsonMetadataByAssetName : negated conditional → SURVIVED |
if (val instanceof HashMap<?, ?> assetMap) { |
34 | for (Entry<?, ?> assetEntry : assetMap.entrySet()) { | |
35 | Object assetKey = assetEntry.getKey(); | |
36 |
1
1. splitJsonMetadataByAssetName : negated conditional → SURVIVED |
if (assetKey instanceof String assetKeyStr |
37 |
1
1. splitJsonMetadataByAssetName : negated conditional → SURVIVED |
&& (assetKeyStr.replaceAll("\\s+", "").equals(assetName.replaceAll("\\s+", "")) |
38 |
1
1. splitJsonMetadataByAssetName : negated conditional → NO_COVERAGE |
|| (assetKeyStr.startsWith("0x") |
39 |
1
1. splitJsonMetadataByAssetName : negated conditional → NO_COVERAGE |
&& assetKeyStr.replace("0x", "").equals(assetName)))) { |
40 | isAsset = true; | |
41 | Map<Object, Object> subMap = new HashMap<>(); | |
42 | subMap.put(assetKey, assetEntry.getValue()); | |
43 | finalMap.put(key, subMap); | |
44 | } | |
45 | } | |
46 | } else { | |
47 | finalMap.put(key, val); | |
48 | } | |
49 | } | |
50 |
2
1. splitJsonMetadataByAssetName : negated conditional → SURVIVED 2. splitJsonMetadataByAssetName : replaced return value with "" for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::splitJsonMetadataByAssetName → KILLED |
return isAsset ? objectMapper.writeValueAsString(finalMap) : jsonMetadata; |
51 | } catch (Exception ex) { | |
52 | log.error("Error: structure incorrect, message=" + ex.getMessage()); | |
53 | log.error("Split Json metadata fail"); | |
54 | } | |
55 |
1
1. splitJsonMetadataByAssetName : replaced return value with "" for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::splitJsonMetadataByAssetName → KILLED |
return jsonMetadata; |
56 | } | |
57 | ||
58 | @SuppressWarnings("unchecked") | |
59 | public static MetadataCIP standard(String jsonMetadata) { | |
60 | MetadataCIP metadataCIP = new MetadataCIP(); | |
61 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/MetadataCIP::setValid → SURVIVED |
metadataCIP.setValid(false); |
62 | Map<Object, TokenCIP> tokenMap = new HashMap<>(); | |
63 | try { | |
64 | ObjectMapper objectMapper = new ObjectMapper(); | |
65 | Map<Object, Object> metadataMap = | |
66 | objectMapper.readValue(jsonMetadata, new TypeReference<>() {}); | |
67 | int version = detectVersion(metadataMap.get(MetadataField.VERSION.getName())); | |
68 | for (Map.Entry<Object, Object> metadataEntry : metadataMap.entrySet()) { | |
69 |
1
1. standard : negated conditional → SURVIVED |
if (metadataEntry.getValue() instanceof HashMap<?, ?> assetMap) { |
70 | Object policyId = metadataEntry.getKey(); | |
71 | for (Entry<?, ?> assetEntry : assetMap.entrySet()) { | |
72 | TokenCIP token = new TokenCIP(); | |
73 | Map<Object, Object> assetValMap = (Map<Object, Object>) assetEntry.getValue(); | |
74 | List<BaseProperty> requireProperties = new ArrayList<>(); | |
75 | requireProperties.add(policy(policyId, version)); | |
76 | requireProperties.add(assetName(assetEntry.getKey(), version)); | |
77 | requireProperties.add(name(assetValMap.get(MetadataField.NAME.getName()), version)); | |
78 | requireProperties.add(image(assetValMap.get(MetadataField.IMAGE.getName()), version)); | |
79 |
1
1. standard : removed call to java/util/List::sort → SURVIVED |
requireProperties.sort(Comparator.comparing(BaseProperty::getIndex)); |
80 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/TokenCIP::setRequireProperties → SURVIVED |
token.setRequireProperties(requireProperties); |
81 | List<BaseProperty> optionalProperties = new ArrayList<>(); | |
82 | Object desc = assetValMap.get(MetadataField.DESCRIPTION.getName()); | |
83 | int index = 1; | |
84 |
1
1. standard : negated conditional → SURVIVED |
if (Objects.nonNull(desc)) { |
85 | optionalProperties.add(description(desc, String.valueOf(index), version)); | |
86 |
1
1. standard : Changed increment from 1 to -1 → NO_COVERAGE |
index++; |
87 | } | |
88 | Object mediaType = assetValMap.get(MetadataField.MEDIA_TYPE.getName()); | |
89 |
1
1. standard : negated conditional → SURVIVED |
if (Objects.nonNull(mediaType)) { |
90 | optionalProperties.add(mediaType(mediaType, String.valueOf(index), version)); | |
91 |
1
1. standard : Changed increment from 1 to -1 → SURVIVED |
index++; |
92 | } | |
93 | index = | |
94 | files( | |
95 | assetValMap.get(MetadataField.FILES.getName()), | |
96 | optionalProperties, | |
97 | index, | |
98 | version); | |
99 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::version → SURVIVED |
version( |
100 | metadataMap.get(MetadataField.VERSION.getName()), | |
101 | String.valueOf(index), | |
102 | optionalProperties); | |
103 |
1
1. standard : removed call to java/util/List::sort → SURVIVED |
optionalProperties.sort(Comparator.comparing(BaseProperty::getIndex)); |
104 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/TokenCIP::setOptionalProperties → SURVIVED |
token.setOptionalProperties(optionalProperties); |
105 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/TokenCIP::setTokenName → SURVIVED |
token.setTokenName(assetEntry.getKey()); |
106 | tokenMap.put(assetEntry.getKey(), token); | |
107 | } | |
108 | } | |
109 | } | |
110 |
1
1. standard : negated conditional → SURVIVED |
if (tokenMap.isEmpty()) { |
111 | tokenMap = getDefaultTokenMap(version); | |
112 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/MetadataCIP::setValid → NO_COVERAGE |
metadataCIP.setValid(false); |
113 | } else { | |
114 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/MetadataCIP::setValid → SURVIVED |
metadataCIP.setValid(valid(tokenMap, version)); |
115 | } | |
116 | } catch (Exception ex) { | |
117 | log.error("Error: structure incorrect, message=" + ex.getMessage()); | |
118 | log.error("Check standard CIP-25 fail"); | |
119 | } | |
120 |
1
1. standard : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/MetadataCIP::setTokenMap → SURVIVED |
metadataCIP.setTokenMap(tokenMap); |
121 |
1
1. standard : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::standard → SURVIVED |
return metadataCIP; |
122 | } | |
123 | ||
124 | public static void version(Object version, String index, List<BaseProperty> optionalProperties) { | |
125 |
1
1. version : negated conditional → SURVIVED |
if (Objects.isNull(version)) { |
126 | return; | |
127 | } | |
128 |
3
1. version : negated conditional → SURVIVED 2. version : negated conditional → NO_COVERAGE 3. version : negated conditional → NO_COVERAGE |
boolean isValid = version instanceof Integer versionInt && (versionInt == 1 || versionInt == 2); |
129 | ||
130 | optionalProperties.add( | |
131 | BaseProperty.builder() | |
132 | .value(version) | |
133 | .format(FormatFieldType.VERSION_1_OR_2.getValue()) | |
134 | .property(MetadataField.VERSION.getName()) | |
135 | .index(index) | |
136 | .valid(isValid) | |
137 | .valueFormat( | |
138 |
1
1. version : negated conditional → SURVIVED |
isValid ? version.toString() : FormatFieldType.NEITHER_VERSION_1_OR_2.getValue()) |
139 | .build()); | |
140 | } | |
141 | ||
142 | public static int detectVersion(Object version) { | |
143 |
3
1. detectVersion : negated conditional → SURVIVED 2. detectVersion : negated conditional → NO_COVERAGE 3. detectVersion : negated conditional → SURVIVED |
if (Objects.isNull(version) || (version instanceof Integer versionInt && versionInt == 1)) { |
144 |
1
1. detectVersion : replaced int return with 0 for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::detectVersion → SURVIVED |
return 1; |
145 |
2
1. detectVersion : negated conditional → NO_COVERAGE 2. detectVersion : negated conditional → SURVIVED |
} else if (version instanceof Integer versionInt && versionInt == 2) { |
146 |
1
1. detectVersion : replaced int return with 0 for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::detectVersion → NO_COVERAGE |
return 2; |
147 | } else { | |
148 | return 0; | |
149 | } | |
150 | } | |
151 | ||
152 | public static BaseProperty policy(Object policyId, int version) { | |
153 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(policyId); | |
154 | BaseProperty baseProperty = | |
155 | BaseProperty.builder() | |
156 | .value(policyId) | |
157 | .format(FormatFieldType.STRING_OR_RAW_BYTES.getValue()) | |
158 | .index("1") | |
159 | .property(MetadataField.POLICY_ID.getName()) | |
160 | .valueFormat(format.getValue()) | |
161 | .valid(false) | |
162 | .build(); | |
163 | switch (version) { | |
164 | case 0 -> { | |
165 |
1
1. policy : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
baseProperty.setValid(null); |
166 |
1
1. policy : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
baseProperty.setFormat(null); |
167 |
1
1. policy : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
baseProperty.setValueFormat(null); |
168 | } | |
169 |
1
1. policy : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
case 1 -> baseProperty.setValid(format.equals(FormatFieldType.STRING)); |
170 |
1
1. policy : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → NO_COVERAGE |
case 2 -> baseProperty.setValid(format.equals(FormatFieldType.RAW_BYTES)); |
171 | default -> log.warn("version is not define"); | |
172 | } | |
173 |
1
1. policy : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::policy → SURVIVED |
return baseProperty; |
174 | } | |
175 | ||
176 | public static BaseProperty assetName(Object assetName, int version) { | |
177 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(assetName); | |
178 | BaseProperty baseProperty = | |
179 | BaseProperty.builder() | |
180 | .value(assetName) | |
181 | .format(FormatFieldType.STRING_OR_RAW_BYTES.getValue()) | |
182 | .index("2") | |
183 | .property(MetadataField.ASSET_NAME.getName()) | |
184 | .valueFormat(format.getValue()) | |
185 | .valid(false) | |
186 | .build(); | |
187 | switch (version) { | |
188 | case 0 -> { | |
189 |
1
1. assetName : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
baseProperty.setValid(null); |
190 |
1
1. assetName : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
baseProperty.setFormat(null); |
191 |
1
1. assetName : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
baseProperty.setValueFormat(null); |
192 | } | |
193 |
1
1. assetName : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
case 1 -> baseProperty.setValid(format.equals(FormatFieldType.STRING)); |
194 |
1
1. assetName : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → NO_COVERAGE |
case 2 -> baseProperty.setValid(format.equals(FormatFieldType.RAW_BYTES)); |
195 | default -> log.warn("version is not define"); | |
196 | } | |
197 |
1
1. assetName : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::assetName → SURVIVED |
return baseProperty; |
198 | } | |
199 | ||
200 | public static BaseProperty name(Object name, int version) { | |
201 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(name); | |
202 | BaseProperty baseProperty = | |
203 | BaseProperty.builder() | |
204 | .value(name) | |
205 | .format(FormatFieldType.STRING.getValue()) | |
206 | .property(MetadataField.NAME.getName()) | |
207 | .index("3") | |
208 | .valid(format.equals(FormatFieldType.STRING)) | |
209 | .valueFormat(format.getValue()) | |
210 | .build(); | |
211 |
1
1. name : negated conditional → SURVIVED |
if (version == 0) { |
212 |
1
1. name : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
baseProperty.setValid(null); |
213 |
1
1. name : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
baseProperty.setFormat(null); |
214 |
1
1. name : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
baseProperty.setValueFormat(null); |
215 | } | |
216 |
1
1. name : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::name → SURVIVED |
return baseProperty; |
217 | } | |
218 | ||
219 | public static BaseProperty nameFile(Object name, int version) { | |
220 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(name); | |
221 | BaseProperty baseProperty = | |
222 | BaseProperty.builder() | |
223 | .value(name) | |
224 | .format(FormatFieldType.STRING.getValue()) | |
225 | .property(MetadataField.NAME.getName()) | |
226 | .valid(format.equals(FormatFieldType.STRING)) | |
227 | .valueFormat(format.getValue()) | |
228 | .build(); | |
229 |
1
1. nameFile : negated conditional → SURVIVED |
if (version == 0) { |
230 |
1
1. nameFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
baseProperty.setValid(null); |
231 |
1
1. nameFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
baseProperty.setFormat(null); |
232 |
1
1. nameFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
baseProperty.setValueFormat(null); |
233 | } | |
234 |
1
1. nameFile : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::nameFile → SURVIVED |
return baseProperty; |
235 | } | |
236 | ||
237 | public static BaseProperty image(Object image, int version) { | |
238 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(image); | |
239 | BaseProperty checkImage = | |
240 | BaseProperty.builder() | |
241 | .value(image) | |
242 | .format(FormatFieldType.URI_OR_ARRAY.getValue()) | |
243 | .index("4") | |
244 | .valueFormat(format.getValue()) | |
245 | .valid( | |
246 |
1
1. image : negated conditional → SURVIVED |
format.equals(FormatFieldType.URI) |
247 |
1
1. image : negated conditional → NO_COVERAGE |
|| format.equals(FormatFieldType.URI_ARRAY_PARTS)) |
248 | .property(MetadataField.IMAGE.getName()) | |
249 | .build(); | |
250 | ||
251 |
1
1. image : negated conditional → SURVIVED |
if (version == 0) { |
252 |
1
1. image : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
checkImage.setValid(null); |
253 |
1
1. image : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
checkImage.setFormat(null); |
254 |
1
1. image : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
checkImage.setValueFormat(null); |
255 | } | |
256 |
1
1. image : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::image → SURVIVED |
return checkImage; |
257 | } | |
258 | ||
259 | public static BaseProperty srcFile(Object src, int version) { | |
260 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(src); | |
261 | BaseProperty checkSrc = | |
262 | BaseProperty.builder() | |
263 | .value(src) | |
264 | .format(FormatFieldType.URI_OR_ARRAY.getValue()) | |
265 | .property(MetadataField.SRC.getName()) | |
266 | .valueFormat(format.getValue()) | |
267 | .valid( | |
268 |
1
1. srcFile : negated conditional → SURVIVED |
format.equals(FormatFieldType.URI) |
269 |
1
1. srcFile : negated conditional → NO_COVERAGE |
|| format.equals(FormatFieldType.URI_ARRAY_PARTS)) |
270 | .build(); | |
271 | ||
272 |
1
1. srcFile : negated conditional → SURVIVED |
if (version == 0) { |
273 |
1
1. srcFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
checkSrc.setValid(null); |
274 |
1
1. srcFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
checkSrc.setFormat(null); |
275 |
1
1. srcFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
checkSrc.setValueFormat(null); |
276 | } | |
277 |
1
1. srcFile : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::srcFile → SURVIVED |
return checkSrc; |
278 | } | |
279 | ||
280 | public static BaseProperty mediaType(Object mediaType, String index, int version) { | |
281 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(mediaType); | |
282 | boolean isValid = format.equals(FormatFieldType.IMAGE_SLASH_MIME_SUB_TYPE); | |
283 | BaseProperty baseProperty = | |
284 | BaseProperty.builder() | |
285 | .value(mediaType) | |
286 | .format(FormatFieldType.IMAGE_SLASH_MIME_SUB_TYPE.getValue()) | |
287 | .property(MetadataField.MEDIA_TYPE.getName()) | |
288 | .index(index) | |
289 |
1
1. mediaType : negated conditional → SURVIVED |
.valueFormat(isValid ? mediaType.toString() : format.getValue()) |
290 | .valid(isValid) | |
291 | .build(); | |
292 | ||
293 |
1
1. mediaType : negated conditional → SURVIVED |
if (version == 0) { |
294 |
1
1. mediaType : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
baseProperty.setValid(null); |
295 |
1
1. mediaType : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
baseProperty.setFormat(null); |
296 |
1
1. mediaType : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
baseProperty.setValueFormat(null); |
297 | } | |
298 |
1
1. mediaType : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::mediaType → SURVIVED |
return baseProperty; |
299 | } | |
300 | ||
301 | public static BaseProperty mediaTypeFile(Object mediaType, int version) { | |
302 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(mediaType); | |
303 | boolean isValid = | |
304 |
1
1. mediaTypeFile : negated conditional → SURVIVED |
format.equals(FormatFieldType.IMAGE_SLASH_MIME_SUB_TYPE) |
305 |
1
1. mediaTypeFile : negated conditional → SURVIVED |
|| format.equals(FormatFieldType.MIME_TYPE); |
306 | BaseProperty baseProperty = | |
307 | BaseProperty.builder() | |
308 | .value(mediaType) | |
309 | .format(FormatFieldType.MIME_TYPE.getValue()) | |
310 | .property(MetadataField.MEDIA_TYPE.getName()) | |
311 |
1
1. mediaTypeFile : negated conditional → SURVIVED |
.valueFormat(isValid ? mediaType.toString() : format.getValue()) |
312 | .valid(isValid) | |
313 | .build(); | |
314 |
1
1. mediaTypeFile : negated conditional → SURVIVED |
if (version == 0) { |
315 |
1
1. mediaTypeFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
baseProperty.setValid(null); |
316 |
1
1. mediaTypeFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
baseProperty.setFormat(null); |
317 |
1
1. mediaTypeFile : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → SURVIVED |
baseProperty.setValueFormat(null); |
318 | } | |
319 |
1
1. mediaTypeFile : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::mediaTypeFile → SURVIVED |
return baseProperty; |
320 | } | |
321 | ||
322 | public static BaseProperty description(Object desc, String index, int version) { | |
323 | FormatFieldType format = MetadataFieldUtils.getFormatTypeByObject(desc); | |
324 | BaseProperty baseProperty = | |
325 | BaseProperty.builder() | |
326 | .value(desc) | |
327 | .format(FormatFieldType.STRING_OR_ARRAY_STRING.getValue()) | |
328 | .property(MetadataField.DESCRIPTION.getName()) | |
329 | .index(index) | |
330 | .valueFormat(format.getValue()) | |
331 | .valid( | |
332 |
1
1. description : negated conditional → NO_COVERAGE |
format.equals(FormatFieldType.STRING) |
333 |
1
1. description : negated conditional → NO_COVERAGE |
|| format.equals(FormatFieldType.ARRAY_STRING)) |
334 | .build(); | |
335 |
1
1. description : negated conditional → NO_COVERAGE |
if (version == 0) { |
336 |
1
1. description : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → NO_COVERAGE |
baseProperty.setValid(null); |
337 |
1
1. description : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → NO_COVERAGE |
baseProperty.setFormat(null); |
338 |
1
1. description : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValueFormat → NO_COVERAGE |
baseProperty.setValueFormat(null); |
339 | } | |
340 |
1
1. description : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::description → NO_COVERAGE |
return baseProperty; |
341 | } | |
342 | ||
343 | public static int files( | |
344 | Object files, List<BaseProperty> optionalProperties, int indexOfFile, int version) { | |
345 |
3
1. files : negated conditional → SURVIVED 2. files : negated conditional → SURVIVED 3. files : negated conditional → SURVIVED |
if (Objects.nonNull(files) && files instanceof ArrayList<?> fileList && !fileList.isEmpty()) { |
346 | BaseProperty filesProperty = | |
347 | BaseProperty.builder() | |
348 | .valid(false) | |
349 | .property(MetadataField.FILES.getName()) | |
350 | .valid(true) | |
351 | .format(FormatFieldType.ARRAY.getValue()) | |
352 | .build(); | |
353 | List<BaseProperty> optionalPropertiesInFile = new ArrayList<>(); | |
354 | int indexInFile = 1; | |
355 | for (Object file : fileList) { | |
356 |
1
1. files : negated conditional → SURVIVED |
if (file instanceof HashMap<?, ?> fileMap) { |
357 | String index = indexOfFile + "." + indexInFile; | |
358 | BaseProperty nameFile = nameFile(fileMap.get(MetadataField.NAME.getName()), version); | |
359 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setIndex → SURVIVED |
nameFile.setIndex(index + ".1"); |
360 | optionalPropertiesInFile.add(nameFile); | |
361 | BaseProperty srcFile = srcFile(fileMap.get(MetadataField.SRC.getName()), version); | |
362 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setIndex → SURVIVED |
srcFile.setIndex(index + ".2"); |
363 | optionalPropertiesInFile.add(srcFile); | |
364 | BaseProperty mediaTypeFile = | |
365 | mediaTypeFile(fileMap.get(MetadataField.MEDIA_TYPE.getName()), version); | |
366 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setIndex → SURVIVED |
mediaTypeFile.setIndex(index + ".3"); |
367 | optionalPropertiesInFile.add(mediaTypeFile); | |
368 |
1
1. files : Changed increment from 1 to -1 → SURVIVED |
indexInFile++; |
369 | } | |
370 | } | |
371 |
1
1. files : negated conditional → SURVIVED |
if (version == 0) { |
372 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
filesProperty.setValid(null); |
373 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setFormat → SURVIVED |
filesProperty.setFormat(null); |
374 | } else { | |
375 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setValid → SURVIVED |
filesProperty.setValid( |
376 |
1
1. files : negated conditional → SURVIVED |
!optionalPropertiesInFile.isEmpty() |
377 | && optionalPropertiesInFile.stream() | |
378 | // The validation of "name" property won't affect the validation of "files" | |
379 | // optional property | |
380 | .filter( | |
381 | baseProperty -> | |
382 |
2
1. lambda$files$0 : negated conditional → SURVIVED 2. lambda$files$0 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$files$0 → SURVIVED |
Objects.nonNull(baseProperty) |
383 |
1
1. lambda$files$0 : negated conditional → SURVIVED |
&& !baseProperty.getProperty().equals(MetadataField.NAME.getName())) |
384 |
3
1. lambda$files$1 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$files$1 → SURVIVED 2. lambda$files$1 : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$files$1 → SURVIVED 3. files : negated conditional → SURVIVED |
.allMatch(baseProperty -> baseProperty.getValid().equals(true))); |
385 | } | |
386 |
1
1. files : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/BaseProperty::setIndex → SURVIVED |
filesProperty.setIndex(String.valueOf(indexOfFile)); |
387 | optionalProperties.add(filesProperty); | |
388 | optionalProperties.addAll(optionalPropertiesInFile); | |
389 |
1
1. files : Changed increment from 1 to -1 → SURVIVED |
indexOfFile++; |
390 | } | |
391 |
1
1. files : replaced int return with 0 for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::files → SURVIVED |
return indexOfFile; |
392 | } | |
393 | ||
394 | public static Boolean valid(Map<Object, TokenCIP> tokenMap, int version) { | |
395 |
1
1. valid : negated conditional → SURVIVED |
if (version == 0) { |
396 |
1
1. valid : replaced Boolean return with True for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::valid → SURVIVED |
return false; |
397 | } | |
398 | List<Boolean> fields = new ArrayList<>(); | |
399 | for (Map.Entry<Object, TokenCIP> tokenEntry : tokenMap.entrySet()) { | |
400 | List<BaseProperty> optionalProperties = tokenEntry.getValue().getOptionalProperties(); | |
401 | ||
402 | // Find the index of the highest level "files" property (since "files" is an optional property | |
403 | // this can be an empty optional) | |
404 | Optional<String> filesIndex = | |
405 | optionalProperties.stream() | |
406 | .filter( | |
407 | baseProperty -> { | |
408 | String index = baseProperty.getIndex(); | |
409 |
2
1. lambda$valid$2 : negated conditional → SURVIVED 2. lambda$valid$2 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$2 → SURVIVED |
return index.matches("^[\\d]+") |
410 |
1
1. lambda$valid$2 : negated conditional → SURVIVED |
&& baseProperty.getProperty().equals(MetadataField.FILES.getName()); |
411 | }) | |
412 | .findFirst() | |
413 | .map(BaseProperty::getIndex); | |
414 | ||
415 | // The validation of files[<index>]."name" property of a token won't affect the validation of | |
416 | // the tokens | |
417 |
1
1. valid : negated conditional → SURVIVED |
if (filesIndex.isPresent()) { |
418 | optionalProperties = | |
419 | optionalProperties.stream() | |
420 | .filter( | |
421 | baseProperty -> | |
422 |
2
1. lambda$valid$3 : negated conditional → SURVIVED 2. lambda$valid$3 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$3 → SURVIVED |
Objects.nonNull(baseProperty) |
423 |
1
1. lambda$valid$3 : negated conditional → SURVIVED |
&& !(baseProperty.getProperty().equals(MetadataField.NAME.getName()) |
424 | && baseProperty | |
425 | .getIndex() | |
426 |
1
1. lambda$valid$3 : negated conditional → SURVIVED |
.matches(filesIndex.get() + "\\.\\d+\\.1"))) |
427 | .toList(); | |
428 | } | |
429 | ||
430 | fields.add( | |
431 | optionalProperties.stream() | |
432 | .map(BaseProperty::getValid) | |
433 |
2
1. lambda$valid$4 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$4 → SURVIVED 2. lambda$valid$4 : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$4 → SURVIVED |
.allMatch(isValid -> isValid.equals(true))); |
434 | fields.add( | |
435 | tokenEntry.getValue().getRequireProperties().stream() | |
436 | .map(BaseProperty::getValid) | |
437 |
2
1. lambda$valid$5 : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$5 → SURVIVED 2. lambda$valid$5 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$5 → SURVIVED |
.allMatch(isValid -> isValid.equals(true))); |
438 | } | |
439 |
5
1. valid : replaced Boolean return with True for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::valid → SURVIVED 2. valid : negated conditional → SURVIVED 3. lambda$valid$6 : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$6 → SURVIVED 4. lambda$valid$6 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::lambda$valid$6 → SURVIVED 5. valid : negated conditional → SURVIVED |
return !fields.isEmpty() && fields.stream().allMatch(field -> field.equals(true)); |
440 | } | |
441 | ||
442 | private static Map<Object, TokenCIP> getDefaultTokenMap(int version) { | |
443 | Map<Object, TokenCIP> tokenMap = new HashMap<>(); | |
444 | TokenCIP token = new TokenCIP(); | |
445 | List<BaseProperty> requireProperties = new ArrayList<>(); | |
446 | requireProperties.add(policy(null, version)); | |
447 | requireProperties.add(assetName(null, version)); | |
448 | requireProperties.add(name(null, version)); | |
449 | requireProperties.add(image(null, version)); | |
450 |
1
1. getDefaultTokenMap : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/TokenCIP::setRequireProperties → NO_COVERAGE |
token.setRequireProperties(requireProperties); |
451 |
1
1. getDefaultTokenMap : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/TokenCIP::setOptionalProperties → NO_COVERAGE |
token.setOptionalProperties(new ArrayList<>()); |
452 |
1
1. getDefaultTokenMap : removed call to org/cardanofoundation/explorer/api/model/metadatastandard/cip/TokenCIP::setTokenName → NO_COVERAGE |
token.setTokenName(""); |
453 | ||
454 | tokenMap.put("", token); | |
455 |
1
1. getDefaultTokenMap : replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/util/MetadataCIP25Utils::getDefaultTokenMap → NO_COVERAGE |
return tokenMap; |
456 | } | |
457 | } | |
Mutations | ||
33 |
1.1 |
|
36 |
1.1 |
|
37 |
1.1 |
|
38 |
1.1 |
|
39 |
1.1 |
|
50 |
1.1 2.2 |
|
55 |
1.1 |
|
61 |
1.1 |
|
69 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
84 |
1.1 |
|
86 |
1.1 |
|
89 |
1.1 |
|
91 |
1.1 |
|
99 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
110 |
1.1 |
|
112 |
1.1 |
|
114 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
125 |
1.1 |
|
128 |
1.1 2.2 3.3 |
|
138 |
1.1 |
|
143 |
1.1 2.2 3.3 |
|
144 |
1.1 |
|
145 |
1.1 2.2 |
|
146 |
1.1 |
|
165 |
1.1 |
|
166 |
1.1 |
|
167 |
1.1 |
|
169 |
1.1 |
|
170 |
1.1 |
|
173 |
1.1 |
|
189 |
1.1 |
|
190 |
1.1 |
|
191 |
1.1 |
|
193 |
1.1 |
|
194 |
1.1 |
|
197 |
1.1 |
|
211 |
1.1 |
|
212 |
1.1 |
|
213 |
1.1 |
|
214 |
1.1 |
|
216 |
1.1 |
|
229 |
1.1 |
|
230 |
1.1 |
|
231 |
1.1 |
|
232 |
1.1 |
|
234 |
1.1 |
|
246 |
1.1 |
|
247 |
1.1 |
|
251 |
1.1 |
|
252 |
1.1 |
|
253 |
1.1 |
|
254 |
1.1 |
|
256 |
1.1 |
|
268 |
1.1 |
|
269 |
1.1 |
|
272 |
1.1 |
|
273 |
1.1 |
|
274 |
1.1 |
|
275 |
1.1 |
|
277 |
1.1 |
|
289 |
1.1 |
|
293 |
1.1 |
|
294 |
1.1 |
|
295 |
1.1 |
|
296 |
1.1 |
|
298 |
1.1 |
|
304 |
1.1 |
|
305 |
1.1 |
|
311 |
1.1 |
|
314 |
1.1 |
|
315 |
1.1 |
|
316 |
1.1 |
|
317 |
1.1 |
|
319 |
1.1 |
|
332 |
1.1 |
|
333 |
1.1 |
|
335 |
1.1 |
|
336 |
1.1 |
|
337 |
1.1 |
|
338 |
1.1 |
|
340 |
1.1 |
|
345 |
1.1 2.2 3.3 |
|
356 |
1.1 |
|
359 |
1.1 |
|
362 |
1.1 |
|
366 |
1.1 |
|
368 |
1.1 |
|
371 |
1.1 |
|
372 |
1.1 |
|
373 |
1.1 |
|
375 |
1.1 |
|
376 |
1.1 |
|
382 |
1.1 2.2 |
|
383 |
1.1 |
|
384 |
1.1 2.2 3.3 |
|
386 |
1.1 |
|
389 |
1.1 |
|
391 |
1.1 |
|
395 |
1.1 |
|
396 |
1.1 |
|
409 |
1.1 2.2 |
|
410 |
1.1 |
|
417 |
1.1 |
|
422 |
1.1 2.2 |
|
423 |
1.1 |
|
426 |
1.1 |
|
433 |
1.1 2.2 |
|
437 |
1.1 2.2 |
|
439 |
1.1 2.2 3.3 4.4 5.5 |
|
450 |
1.1 |
|
451 |
1.1 |
|
452 |
1.1 |
|
455 |
1.1 |