Skip to content

Commit

Permalink
Add id element to the KlassResource (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornandre authored Feb 29, 2024
1 parent 7adc920 commit 5bdfd51
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import no.ssb.klass.api.controllers.ClassificationController;

@JacksonXmlRootElement(localName = "classificationFamily")
@JsonPropertyOrder({"name", "classifications", "links"})
@JsonPropertyOrder({"name", "id", "classifications", "links"})
public class ClassificationFamilyResource extends KlassResource {
private final String name;
private final List<ClassificationSummaryResource> classifications;

public ClassificationFamilyResource(ClassificationFamily classificationFamily, Language language, String ssbSection,
ClassificationType classificationType) {
super(classificationFamily.getId());
this.name = classificationFamily.getName(language);
List<ClassificationSeries> classifications = classificationFamily
.getClassificationSeriesBySectionAndClassificationType(ssbSection, classificationType, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import no.ssb.klass.api.controllers.ClassificationController;

@Relation(collectionRelation = "classificationFamilies")
@JsonPropertyOrder({"name", "numberOfClassifications", "links"})
@JsonPropertyOrder({"name", "id", "numberOfClassifications", "links"})
public class ClassificationFamilySummaryResource extends KlassResource {
private String name;
private int numberOfClassifications;

public ClassificationFamilySummaryResource(ClassificationFamilySummary summary, Language language) {
super(summary.getId());
this.name = summary.getClassificationFamilyName(language);
this.numberOfClassifications = summary.getNumberOfClassifications();
addLink(createSelfLink(summary.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;

@JacksonXmlRootElement(localName = "classification")
@JsonPropertyOrder({"name", "classificationType", "lastModified", "description", "primaryLanguage","copyrighted",
@JsonPropertyOrder({"name", "id", "classificationType", "lastModified", "description", "primaryLanguage","copyrighted",
"includeShortName", "includeNotes", "contactPerson", "owningSection", "statisticalUnits", "versions",
"links"})
public class ClassificationResource extends ClassificationSummaryResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import no.ssb.klass.api.controllers.ClassificationController;

@Relation(collectionRelation = "classifications")
@JsonPropertyOrder({"name", "classificationType", "lastModified", "links"})
@JsonPropertyOrder({"name", "id", "classificationType", "lastModified", "links"})
public class ClassificationSummaryResource extends KlassResource {
private final String name;
private final String classificationType;
private final Date lastModified;

protected ClassificationSummaryResource(Language language, ClassificationSeries classification) {
super(classification.getId());
this.name = classification.getName(language);
this.classificationType = classification.getClassificationType().getDisplayName(language);
this.lastModified = classification.getLastModified();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import no.ssb.klass.api.util.CustomLocalDateSerializer;

@JacksonXmlRootElement(localName = "classificationVariant")
@JsonPropertyOrder({"name", "contactPerson", "owningSection", "lastModified", "published", "validFrom", "validTo",
@JsonPropertyOrder({"name", "id", "contactPerson", "owningSection", "lastModified", "published", "validFrom", "validTo",
"introduction", "contactPerson", "owningSection", "correspondenceTables", "changelogs", "levels",
"classificationItems", "links"})
public class ClassificationVariantResource extends ClassificationVariantSummaryResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import no.ssb.klass.core.model.Language;
import no.ssb.klass.api.controllers.ClassificationController;

@JsonPropertyOrder({"name", "contactPerson", "owningSection", "lastModified", "published", "links"})
@JsonPropertyOrder({"name", "id", "contactPerson", "owningSection", "lastModified", "published", "links"})
public class ClassificationVariantSummaryResource extends KlassResource {
private final String name;
private final ContactPersonResource contactPerson;
Expand All @@ -28,6 +28,7 @@ public class ClassificationVariantSummaryResource extends KlassResource {
private final List<String> published;

protected ClassificationVariantSummaryResource(ClassificationVariant variant, Language language) {
super(variant.getId());
this.name = variant.getFullName(language);
this.lastModified = variant.getLastModified();
this.contactPerson = new ContactPersonResource(variant.getContactPerson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import no.ssb.klass.core.util.AlphaNumericalComparator;

@JacksonXmlRootElement(localName = "classificationVersion")
@JsonPropertyOrder({"name", "validFrom", "validTo", "lastModified", "published", "introduction", "contactPerson",
@JsonPropertyOrder({"name", "id", "validFrom", "validTo", "lastModified", "published", "introduction", "contactPerson",
"owningSection", "legalBase", "publications", "derivedFrom", "correspondenceTables", "classificationVariants",
"changelogs", "levels", "classificationItems", "links"})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static java.util.stream.Collectors.*;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

@JsonPropertyOrder({"name", "validFrom", "validTo", "lastModified", "published", "links"})
@JsonPropertyOrder({"name", "id", "validFrom", "validTo", "lastModified", "published", "links"})
public class ClassificationVersionSummaryResource extends KlassResource {
private final String name;
private final LocalDate validFrom;
Expand All @@ -30,6 +30,7 @@ public class ClassificationVersionSummaryResource extends KlassResource {
private final List<String> published;

protected ClassificationVersionSummaryResource(ClassificationVersion version, Language language, Boolean includeFuture) {
super(version.getId());
this.name = version.getName(language);
this.validFrom = version.getDateRange().getFrom();
LocalDate to = version.getDateRange().getTo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import no.ssb.klass.core.model.Language;

@JacksonXmlRootElement(localName = "correspondenceTable")
@JsonPropertyOrder({"name", "contactPerson", "owningSection", "source", "sourceId", "target", "targetId", "changeTable",
@JsonPropertyOrder({"name", "id", "contactPerson", "owningSection", "source", "sourceId", "target", "targetId", "changeTable",
"lastModified", "published", "sourceLevel", "targetLevel", "description", "changelogs", "correspondenceMaps",
"links"})
public class CorrespondenceTableResource extends CorrespondenceTableSummaryResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import no.ssb.klass.core.model.Language;
import no.ssb.klass.api.controllers.ClassificationController;

@JsonPropertyOrder({"name", "contactPerson", "owningSection", "source", "sourceId", "target", "targetId", "changeTable",
@JsonPropertyOrder({"name", "id", "contactPerson", "owningSection", "source", "sourceId", "target", "targetId", "changeTable",
"lastModified", "published", "sourceLevel", "targetLevel", "links"})
public class CorrespondenceTableSummaryResource extends KlassResource {
private final String name;
Expand All @@ -37,6 +37,7 @@ public class CorrespondenceTableSummaryResource extends KlassResource {
private final LevelResource targetLevel;

protected CorrespondenceTableSummaryResource(CorrespondenceTable correspondenceTable, Language language) {
super(correspondenceTable.getId());
this.name = correspondenceTable.getName(language);
this.contactPerson = new ContactPersonResource(correspondenceTable.getContactPerson());
this.owningSection = correspondenceTable.getContactPerson().getSection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
import org.springframework.lang.Nullable;

public abstract class KlassResource extends PagedModel<RepresentationModel<?>> {

@JsonProperty("id")
private final Long id;

public KlassResource(Long id) {
this.id = id;
}

protected void addLink(Link link) {
super.add(link);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import no.ssb.klass.api.controllers.ClassificationController;

@Relation(collectionRelation = "searchResults")
@JsonPropertyOrder({"name", "snippet", "searchScore", "links"})
@JsonPropertyOrder({"name", "id", "snippet", "searchScore", "links"})
public class SearchResultResource extends KlassResource {

private String name;
private String snippet;
private Double searchScore;

public SearchResultResource(SolrSearchResult searchResult, List<HighlightEntry.Highlight> highlights) {
super(searchResult.getItemid());
this.name = searchResult.getTitle();
this.snippet = searchResult.getDescription();
this.searchScore = searchResult.getScore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class SsbSectionResource extends KlassResource {
private final String name;

public SsbSectionResource(String name) {
super(null);
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void restServiceListClassificationsJSON() {
@Test
public void restServiceListClassificationsIncludeCodelistsJSON() {
given().port(port).accept(ContentType.JSON).param("includeCodelists", "true").get(REQUEST)
// .prettyPeek()
.prettyPeek()
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON)
Expand Down Expand Up @@ -129,7 +129,7 @@ public void restServiceListClassificationsXML() {
@Test
public void restServiceListClassificationsIncludeCodelistXML() {
given().port(port).accept(ContentType.XML).param("includeCodelists", "true").get(REQUEST)
// .prettyPeek()
.prettyPeek()
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.XML)
Expand Down

0 comments on commit 5bdfd51

Please sign in to comment.