Skip to content

Commit

Permalink
Merge pull request #81 from imsweb/year-based-metadata
Browse files Browse the repository at this point in the history
Year based metadata
  • Loading branch information
ctmay4 authored Jun 1, 2021
2 parents d5b8526 + 4ef1fce commit dcccca9
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ Download [the latest JAR][1] or grab via Maven:
<dependency>
<groupId>com.imsweb</groupId>
<artifactId>staging-client-java</artifactId>
<version>6.0.0</version>
<version>6.1.0</version>
</dependency>
```

or via Gradle:

```groovy
compile 'com.imsweb:staging-client-java:6.0.0'
compile 'com.imsweb:staging-client-java:6.1.0'
```

## Usage
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ plugins {
id 'signing'
id "io.codearte.nexus-staging" version "0.30.0" // logs into Sonotype OSS and does a "Close" and "Release"
id 'com.adarshr.test-logger' version '3.0.0'
id "com.github.ben-manes.versions" version "0.38.0"
id 'org.sonatype.gradle.plugins.scan' version '2.0.9'
id "com.github.ben-manes.versions" version "0.39.0"
id 'org.sonatype.gradle.plugins.scan' version '2.0.10'
}

group = 'com.imsweb'
version = '6.0.0'
version = '6.1.0'
description = 'Java client library for staging calculations'

// fail the build if there are compiler warnings
Expand Down Expand Up @@ -50,7 +50,7 @@ dependencies {
implementation 'org.ahocorasick:ahocorasick:0.4.0'

// split the seerapi-client-java dependency to an optional feature
updateSupportImplementation 'com.imsweb:seerapi-client-java:3.23'
updateSupportImplementation 'com.imsweb:seerapi-client-java:3.24'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.19.0'
Expand Down Expand Up @@ -193,6 +193,6 @@ nexusStaging {
}

wrapper {
gradleVersion = '7.0.1'
gradleVersion = '7.0.2'
distributionType = Wrapper.DistributionType.ALL
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/com/imsweb/staging/entities/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package com.imsweb.staging.entities;

import java.util.Set;
import java.util.List;

/**
* An input field in the definition
Expand Down Expand Up @@ -46,6 +46,6 @@ public interface Input {

Integer getDecimalPlaces();

Set<String> getMetadata();
List<? extends Metadata> getMetadata();

}
26 changes: 26 additions & 0 deletions src/main/java/com/imsweb/staging/entities/Metadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2021 Information Management Services, Inc.
*/
package com.imsweb.staging.entities;

public interface Metadata {

/**
* Name of metadata item
* @return String
*/
String getName();

/**
* Start year of metadata
* @return Integer representing year
*/
Integer getStart();

/**
* End year of metadata
* @return Integer representing year
*/
Integer getEnd();

}
4 changes: 2 additions & 2 deletions src/main/java/com/imsweb/staging/entities/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package com.imsweb.staging.entities;

import java.util.Set;
import java.util.List;

/**
* An output field in the definition
Expand Down Expand Up @@ -36,6 +36,6 @@ public interface Output {
*/
String getDefault();

Set<String> getMetadata();
List<? extends Metadata> getMetadata();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2021 Information Management Services, Inc.
*/
package com.imsweb.staging.entities.impl;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.imsweb.staging.entities.Metadata;

@JsonPropertyOrder({"name", "start", "end"})
@JsonDeserialize(using = StagingMetadataDeserializer.class)
public class StagingMetadata implements Metadata {

private String _name;
private Integer _start;
private Integer _end;

public StagingMetadata() {
}

public StagingMetadata(String name) {
_name = name;
}

public StagingMetadata(String name, Integer start) {
_name = name;
_start = start;
}

public StagingMetadata(String name, Integer start, Integer end) {
_name = name;
_start = start;
_end = end;
}

@JsonProperty("name")
@Override
public String getName() {
return _name;
}

public void setName(String name) {
_name = name;
}

@JsonProperty("start")
@Override
public Integer getStart() {
return _start;
}

public void setStart(Integer start) {
_start = start;
}

@JsonProperty("end")
@Override
public Integer getEnd() {
return _end;
}

public void setEnd(Integer end) {
_end = end;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

StagingMetadata that = (StagingMetadata)o;
return Objects.equals(_name, that._name) &&
Objects.equals(_start, that._start) &&
Objects.equals(_end, that._end);
}

@Override
public int hashCode() {
return Objects.hash(_name, _start, _end);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2021 Information Management Services, Inc.
*/
package com.imsweb.staging.entities.impl;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

public class StagingMetadataDeserializer extends StdDeserializer<StagingMetadata> {

public StagingMetadataDeserializer() {
this(null);
}

protected StagingMetadataDeserializer(Class<?> vc) {
super(vc);
}

@Override
public StagingMetadata deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);

if (node.isNull())
return null;

if (node.isObject()) {
StagingMetadata meta = new StagingMetadata();

if (node.get("name") != null)
meta.setName(node.get("name").asText());
if (node.get("start") != null)
meta.setStart(node.get("start").asInt());
if (node.get("end") != null)
meta.setEnd(node.get("end").asInt());

return meta;
}

return new StagingMetadata(node.asText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
*/
package com.imsweb.staging.entities.impl;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.imsweb.staging.entities.Input;

Expand All @@ -28,7 +26,7 @@ public class StagingSchemaInput implements Input {
private Boolean _usedForStaging;
private String _unit;
private Integer _decimalPlaces;
private Set<String> _metadata;
private List<StagingMetadata> _metadata;

/**
* Morphia requires a default constructor
Expand Down Expand Up @@ -64,7 +62,7 @@ public StagingSchemaInput(StagingSchemaInput other) {
setDefault(other.getDefault());
setTable(other.getTable());
if (other.getMetadata() != null)
setMetadata(new HashSet<>(other.getMetadata()));
setMetadata(new ArrayList<>(other.getMetadata()));
setUsedForStaging(other.getUsedForStaging());
setUnit(other.getUnit());
setDecimalPlaces(other.getDecimalPlaces());
Expand Down Expand Up @@ -172,12 +170,11 @@ public void setUnit(String unit) {

@Override
@JsonProperty("metadata")
public Set<String> getMetadata() {
public List<StagingMetadata> getMetadata() {
return _metadata;
}

@JsonDeserialize(as = LinkedHashSet.class)
public void setMetadata(Set<String> metadata) {
public void setMetadata(List<StagingMetadata> metadata) {
_metadata = metadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
*/
package com.imsweb.staging.entities.impl;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.imsweb.staging.entities.Output;

Expand All @@ -24,7 +22,7 @@ public class StagingSchemaOutput implements Output {
private String _naaccrXmlId;
private String _table;
private String _default;
private Set<String> _metadata;
private List<StagingMetadata> _metadata;

/**
* Morphia requires a default constructor
Expand Down Expand Up @@ -60,7 +58,7 @@ public StagingSchemaOutput(StagingSchemaOutput other) {
setTable(other.getTable());
setDefault(other.getDefault());
if (other.getMetadata() != null)
setMetadata(new HashSet<>(other.getMetadata()));
setMetadata(new ArrayList<>(other.getMetadata()));
}

@Override
Expand Down Expand Up @@ -135,12 +133,11 @@ public void setDefault(String aDefault) {

@Override
@JsonProperty("metadata")
public Set<String> getMetadata() {
public List<StagingMetadata> getMetadata() {
return _metadata;
}

@JsonDeserialize(as = LinkedHashSet.class)
public void setMetadata(Set<String> metadata) {
public void setMetadata(List<StagingMetadata> metadata) {
_metadata = metadata;
}

Expand Down
Loading

0 comments on commit dcccca9

Please sign in to comment.