Skip to content

Commit

Permalink
Merge pull request #62 from bchen-godaddy/master
Browse files Browse the repository at this point in the history
issues/54: Fix XML parsing of media types
  • Loading branch information
anewton1998 authored Jan 14, 2025
2 parents 5fc1110 + baf2090 commit b52c01c
Show file tree
Hide file tree
Showing 2 changed files with 2,114 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package org.icann.rdapconformance.validator.workflow.rdap.dataset.model;

import jakarta.xml.bind.Unmarshaller;
import jakarta.xml.bind.annotation.*;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toSet;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "registry", namespace = "http://www.iana.org/assignments")
public class MediaTypes implements RDAPDatasetModel, DatasetValidatorModel {

@XmlElementWrapper(name = "registry", namespace = "http://www.iana.org/assignments")
@XmlElement(name = "record", namespace = "http://www.iana.org/assignments")
private List<MediaTypesRecord> recordsObject;
@XmlElement(name = "registry", namespace = "http://www.iana.org/assignments")
private List<MediaTypesRegistry> registries;

private Set<String> records = new HashSet<>();

void afterUnmarshal(Unmarshaller u, Object parent) {
this.records = recordsObject.stream().map(MediaTypesRecord::getName).collect(toSet());
this.records = registries
.stream()
.flatMap(MediaTypesRegistry::getRecords)
.collect(toSet());
}

@Override
Expand All @@ -33,17 +42,28 @@ public Set<String> getRecords() {
}

@XmlAccessorType(XmlAccessType.FIELD)
static class MediaTypesRecord {
static class MediaTypesRegistry {
@XmlAttribute(name = "id")
private String id;

@XmlElement(name = "name", namespace = "http://www.iana.org/assignments")
private String name;
@XmlElement(name = "record", namespace = "http://www.iana.org/assignments")
private List<MediaTypesRecord> recordsObject = new ArrayList<>();

public String getName() {
return name;
public Stream<String> getRecords() {
return recordsObject.stream()
.map(MediaTypesRecord::getTemplate)
.filter(Objects::nonNull);
}
}

@XmlAccessorType(XmlAccessType.FIELD)
static class MediaTypesRecord {

@XmlElement(name = "file", namespace = "http://www.iana.org/assignments")
private String template;

public void setName(String name) {
this.name = name;
public String getTemplate() {
return template;
}
}
}
Loading

0 comments on commit b52c01c

Please sign in to comment.