getParameters() {
return new LinkedHashMap<>(parameters);
}
- public String getCharset() {
- return charset;
+ public String getInstanceCharset() {
+ return instanceCharset;
}
/**
* For the purposes of cwms-data-api content-type equals we only care about the following
- * fields matching:
- *
+ * fields matching.
+ *
+ *
* - the mimetype itself
* - the version parameter
- *
+ *
+ *
* For us everything else is informational or used indirectly
*/
@Override
@@ -67,7 +78,7 @@ public boolean equals(Object other) {
return false;
}
- /** We loop through instead of using contains key.
+ /* We loop through instead of using contains key.
* Content-type parameter names are not case sensitive.
*/
for (Map.Entry entry : parameters.entrySet()) {
@@ -116,7 +127,7 @@ public String toString() {
/**
* Used for quick comparisons where we don't further need the content type
* so we can streamline the code a little.
- *
+ *
* @param a first content type to check
* @param b second content type to check
* @return whether they are equivalent
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/ContentTypeAliasMap.java b/cwms-data-api/src/main/java/cwms/cda/formatters/ContentTypeAliasMap.java
index 85faf26828..ec1ae7bc7d 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/ContentTypeAliasMap.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/ContentTypeAliasMap.java
@@ -9,17 +9,15 @@
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.formatters.annotations.FormattableWith;
-import org.jetbrains.annotations.NotNull;
-
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.jetbrains.annotations.NotNull;
final class ContentTypeAliasMap {
private final Map contentTypeMap = new ConcurrentHashMap<>();
private static final Map, ContentTypeAliasMap> ALIAS_MAP = new ConcurrentHashMap<>();
- private ContentTypeAliasMap()
- {
+ private ContentTypeAliasMap() {
}
private ContentTypeAliasMap(Class extends CwmsDTOBase> dtoClass) {
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/Formats.java b/cwms-data-api/src/main/java/cwms/cda/formatters/Formats.java
index 121911bac5..1073721637 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/Formats.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/Formats.java
@@ -24,11 +24,9 @@
package cwms.cda.formatters;
+import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.formatters.annotations.FormattableWith;
-
-import java.util.SortedSet;
-import java.util.TreeSet;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
@@ -36,7 +34,8 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import com.google.common.flogger.FluentLogger;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
@@ -96,13 +95,19 @@ public class Formats {
}
- private final Map, OutputFormatter>> formatters = new LinkedHashMap<>();
+ private final Map, OutputFormatter>> formatters =
+ new LinkedHashMap<>();
private static final Formats formats = new Formats();
private Formats() {
}
+ /**
+ * Given the provided content type, get the appropriate legacy content-type.
+ * @param contentType given ContentType
+ * @return a previously configured contenttype value, or the value of {@link JSON_LEGACY}
+ */
public static String getLegacyTypeFromContentType(ContentType contentType) {
return typeMap.entrySet()
.stream()
@@ -172,8 +177,8 @@ private T parseContentFromType(ContentType type, InputSt
}
}
- private List parseContentListFromType(ContentType type, String content, Class rootType)
- throws FormattingException {
+ private List parseContentListFromType(ContentType type, String content,
+ Class rootType) throws FormattingException {
OutputFormatter outputFormatter = getOutputFormatterInternal(type, rootType);
if (outputFormatter != null) {
List retval = outputFormatter.parseContentList(content, rootType);
@@ -218,29 +223,78 @@ private OutputFormatter getOutputFormatterInternal(ContentType type,
return outputFormatter;
}
+ /**
+ * Retrieve the appropriate OutputFormatter for the given ContentType and DTO Class.
+ * @param ct ContentType desired
+ * @param klass CwmsDto
+ * @return Appropriate formatter for the given ContentType and klass
+ */
public static OutputFormatter getOutputFormatter(ContentType ct, Class extends CwmsDTOBase> klass) {
- return formats.getOutputFormatterInternal(ct, klass);
+ return formats.getOutputFormatterInternal(ct, klass);
}
+ /**
+ * Retrieve the formatted output for the given ContentType and DTO Instance.
+ * @param type ContentType Desired
+ * @param toFormat Instance to format
+ * @return String containing text of the DTO in the appropriate format
+ * @throws FormattingException issues with Formatter lookup or formatting.
+ */
public static String format(ContentType type, CwmsDTOBase toFormat) throws FormattingException {
return formats.getFormatted(type, toFormat);
}
- public static String format(ContentType type, List extends CwmsDTOBase> toFormat, Class
- extends CwmsDTOBase> rootType) throws FormattingException {
+ /**
+ * Retrieve the formatted output for the given ContentType and DTO Instances and a DTO Type.
+ * @param type content type desired
+ * @param toFormat list of objects to format
+ * @param rootType DTO type of the list members
+ * @return Formatted String
+ * @throws FormattingException if the list of objects could not be converted.
+ */
+ public static String format(ContentType type, List extends CwmsDTOBase> toFormat,
+ Class extends CwmsDTOBase> rootType) throws FormattingException {
return formats.getFormatted(type, toFormat, rootType);
}
+ /**
+ * Given a ContentType, text, and a given DTO type, parse the text and return an Object instance of the DTO type.
+ * @param DTO Type
+ * @param type ContentType of the input
+ * @param content data to parase
+ * @param rootType expected DTO type
+ * @return an instance of that DTO with the provided data.
+ * @throws FormattingException any issues with lookup of parser or parsing.
+ */
public static T parseContent(ContentType type, String content, Class rootType)
throws FormattingException {
return formats.parseContentFromType(type, content, rootType);
}
+ /**
+ * Given a ContentType, text, and a given DTO type, parse the text and return an Object instance of the DTO type.
+ * @param DTO Type
+ * @param type ContentType of the input.
+ * @param inputStream source of data to parse.
+ * @param rootType expected DTO type.
+ * @return an instance of that DTO with the provided data.
+ * @throws FormattingException any issues with lookup of parser or parsing.
+ */
public static T parseContent(ContentType type, InputStream inputStream, Class rootType)
throws FormattingException {
return formats.parseContentFromType(type, inputStream, rootType);
}
+ /**
+ * Given a ContentType, text, and a given DTO type, parse the text and return a list of Object instance of the DTO
+ * type.
+ * @param DTO Type
+ * @param type ContentType of the input
+ * @param content data to parase
+ * @param rootType expected DTO type
+ * @return an instance of that DTO with the provided data.
+ * @throws FormattingException any issues with lookup of parser or parsing.
+ */
public static List parseContentList(ContentType type, String content, Class rootType)
throws FormattingException {
return formats.parseContentListFromType(type, content, rootType);
@@ -258,6 +312,7 @@ public static List parseContentList(ContentType type,
* FormattableWith annotations.
* @return an appropriate standard mimetype for lookup
* @throws FormattingException if neither header nor queryParam can be parsed into a supported content type
+ * @throws UnsupportedFormatException if preconditions aren't met or format is not supported.
*/
public static ContentType parseHeaderAndQueryParm(String header, String queryParam, Class extends CwmsDTOBase> klass) {
// If a query parameter is provided, it overrides the header.
@@ -284,7 +339,8 @@ public static ContentType parseHeaderAndQueryParm(String header, String queryPar
* @return ContentType appropriate to the given selection.
* @throws UnsupportedFormatException if there is no matching content type for the given class
*/
- public static ContentType parseQueryOrHeaderParam(String headerParam, String queryParam, Class extends CwmsDTOBase> klass) {
+ public static ContentType parseQueryOrHeaderParam(String headerParam, String queryParam,
+ Class extends CwmsDTOBase> klass) {
ContentType ct = null;
if (!(queryParam == null || queryParam.isEmpty())) {
ct = parseQueryParam(queryParam, klass);
@@ -294,27 +350,30 @@ public static ContentType parseQueryOrHeaderParam(String headerParam, String que
ct = parseHeader(DEFAULT, klass);
}
if (ct == null) {
- throw new UnsupportedFormatException("Content-Type " + (headerParam == null ? queryParam : headerParam) + " is not available.");
+ throw new UnsupportedFormatException("Content-Type " + (headerParam == null ? queryParam : headerParam)
+ + " is not available.");
}
return ct;
}
- public static ContentType parseQueryParam(String queryParam, Class extends CwmsDTOBase> klass)
- {
+ /**
+ * Given the ContentType provided in a queryParameter extract and convert to a ContentType issue.
+ * @param queryParam value of the "format" query parameter.
+ * @param klass type of DTO expected.
+ * @return instance of ContentType
+ */
+ public static ContentType parseQueryParam(String queryParam, Class extends CwmsDTOBase> klass) {
ContentTypeAliasMap aliasMap = ContentTypeAliasMap.empty();
if (klass != null) {
aliasMap = ContentTypeAliasMap.forDtoClass(klass);
}
ContentType retVal = null;
- if (queryParam != null && !queryParam.isEmpty())
- {
+ if (queryParam != null && !queryParam.isEmpty()) {
String val = typeMap.get(queryParam);
- if (val != null)
- {
+ if (val != null) {
retVal = aliasMap.getContentType(val);
- if (retVal == null)
- {
+ if (retVal == null) {
retVal = new ContentType(val);
}
}
@@ -331,6 +390,7 @@ public static ContentType parseQueryParam(String queryParam, Class extends Cwm
* {@link cwms.cda.formatters.annotations.FormattableWith} annotations.
* @return an appropriate standard mimetype for lookup
* @throws FormattingException if the header can't be identified as a mimetype
+ * @throws UnsupportedFormatException if header is invalid or for a format that is not supported.
*/
public static @NotNull ContentType parseHeader(@Nullable String header,
@NotNull Class extends CwmsDTOBase> klass) {
@@ -338,7 +398,7 @@ public static ContentType parseQueryParam(String queryParam, Class extends Cwm
ContentTypeAliasMap aliasMap = ContentTypeAliasMap.forDtoClass(klass);
//Swap out null content type with */* for flexibility.
//This routine will match DTO's when the DEFAULT alias specified by the format annotations.
- if(header == null || header.trim().isEmpty()) {
+ if (header == null || header.trim().isEmpty()) {
header = DEFAULT;
}
//TreeSet will sort based on prioritized content type
@@ -357,7 +417,7 @@ public static ContentType parseQueryParam(String queryParam, Class extends Cwm
//Only use the ContentType classes initialized in contentTypeList rather than
//the client headers itself
ContentType type = new ContentType(ct);
- if(contentTypeList.contains(type)) {
+ if (contentTypeList.contains(type)) {
contentTypes.add(type);
}
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/FormattingException.java b/cwms-data-api/src/main/java/cwms/cda/formatters/FormattingException.java
index abbee2e2af..a7c413b01f 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/FormattingException.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/FormattingException.java
@@ -14,6 +14,11 @@ public FormattingException(String message) {
HttpServletResponse.SC_NOT_ACCEPTABLE, LOG_LEVEL, new HashMap<>(), null);
}
+ /**
+ * Formatting Exception with Message and Cause.
+ * @param message Additional message details.
+ * @param err specific cause of this exception.
+ */
public FormattingException(String message, Throwable err) {
super(message, PARSER_SOURCE, "Formatting error:" + message,
((err instanceof IOException)
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/LocationCategoryFormatV1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/LocationCategoryFormatV1.java
index 4090cb9894..8d8c86a8cb 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/LocationCategoryFormatV1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/LocationCategoryFormatV1.java
@@ -1,20 +1,17 @@
package cwms.cda.formatters;
-import java.util.List;
import cwms.cda.data.dto.LocationCategory;
+import java.util.List;
-public class LocationCategoryFormatV1
-{
- private final List locationCategories;
+public class LocationCategoryFormatV1 {
+ private final List locationCategories;
- public LocationCategoryFormatV1(List cats)
- {
- this.locationCategories = cats;
- }
+ public LocationCategoryFormatV1(List cats) {
+ this.locationCategories = cats;
+ }
- public List getLocationCategories()
- {
- return locationCategories;
- }
+ public List getLocationCategories() {
+ return locationCategories;
+ }
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/LocationGroupFormatV1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/LocationGroupFormatV1.java
index ed8ded99be..8b661dd056 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/LocationGroupFormatV1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/LocationGroupFormatV1.java
@@ -1,25 +1,21 @@
package cwms.cda.formatters;
+import cwms.cda.data.dto.LocationGroup;
import java.util.List;
-import cwms.cda.data.dto.LocationGroup;
-public class LocationGroupFormatV1
-{
- private List locationGroups;
+public class LocationGroupFormatV1 {
+ private List locationGroups;
- public LocationGroupFormatV1(List locationGroups)
- {
- this.locationGroups = locationGroups;
- }
+ public LocationGroupFormatV1(List locationGroups) {
+ this.locationGroups = locationGroups;
+ }
- public List getLocationGroups()
- {
- return locationGroups;
- }
+ public List getLocationGroups() {
+ return locationGroups;
+ }
- public void setLocationGroups(List locationGroups)
- {
- this.locationGroups = locationGroups;
- }
+ public void setLocationGroups(List locationGroups) {
+ this.locationGroups = locationGroups;
+ }
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/OfficeFormatV1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/OfficeFormatV1.java
index 7d9f311209..95aa981c7e 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/OfficeFormatV1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/OfficeFormatV1.java
@@ -4,12 +4,12 @@
import java.util.List;
public class OfficeFormatV1 {
- public static class OfficesFMT {
+ public static class OfficesFmt {
public List offices;
}
- public OfficesFMT offices = new OfficesFMT();
+ public final OfficesFmt offices = new OfficesFmt();
public OfficeFormatV1(List offices) {
this.offices.offices = offices;
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/OutputFormatter.java b/cwms-data-api/src/main/java/cwms/cda/formatters/OutputFormatter.java
index 9ce99c521f..8039229b87 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/OutputFormatter.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/OutputFormatter.java
@@ -1,23 +1,30 @@
package cwms.cda.formatters;
+import cwms.cda.data.dto.CwmsDTOBase;
import java.io.InputStream;
import java.util.List;
-import cwms.cda.data.dto.CwmsDTOBase;
public interface OutputFormatter {
String DESERIALIZE_CONTENT_MESSAGE = "Could not deserialize: %s of type: %s";
String UNSUPPORTED_MESSAGE = "Unable to process your request. Deserialization of %s not yet supported.";
+
String getContentType();
+
String format(CwmsDTOBase dto);
+
String format(List extends CwmsDTOBase> dtoList);
+
default T parseContent(String content, Class type) {
throw new UnsupportedOperationException(String.format(UNSUPPORTED_MESSAGE, getContentType()));
}
- default List parseContentList(String content, Class type) {
+
+ default T parseContent(InputStream content, Class type) {
throw new UnsupportedOperationException(String.format(UNSUPPORTED_MESSAGE, getContentType()));
}
- default T parseContent(InputStream content, Class type) {
+
+ default List parseContentList(String content, Class type) {
throw new UnsupportedOperationException(String.format(UNSUPPORTED_MESSAGE, getContentType()));
}
+
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/FormattableWith.java b/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/FormattableWith.java
index 80733b23cd..f3a7d4e7ec 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/FormattableWith.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/FormattableWith.java
@@ -1,12 +1,12 @@
package cwms.cda.formatters.annotations;
+import cwms.cda.formatters.OutputFormatter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import cwms.cda.formatters.OutputFormatter;
/**
* Inform the system of valid which Accept headers
@@ -16,7 +16,19 @@
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Formattables.class)
public @interface FormattableWith {
+ /**
+ * Content Type (MIME Type) string that maps to the given Formatter.
+ * @return the configured content type.
+ */
public String contentType();
+ /**
+ * Which Formatter Class to use for the given ContentType.
+ * @return the formatter Class instance.
+ */
public Class extends OutputFormatter> formatter();
+ /**
+ * Additional Content Type values, if any.
+ * @return List of aliases, or zero length array.
+ */
String[] aliases() default {};
}
\ No newline at end of file
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/Formattables.java b/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/Formattables.java
index d03a8b4b08..786de1028f 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/Formattables.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/annotations/Formattables.java
@@ -8,5 +8,9 @@
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Formattables {
+ /**
+ * List of Formats that work with this data type.
+ * @return list of appropriate formatters
+ */
public FormattableWith[] value();
}
\ No newline at end of file
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1.java
index 06d556679c..408afcc1ea 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1.java
@@ -30,7 +30,8 @@ public String format(CwmsDTOBase dto) {
} else if (dto instanceof CwmsCsvDTO) {
return format((CwmsCsvDTO>) dto, new CsvConfiguration.Builder().build());
} else {
- throw new FormattingException(dto.getClass().getName() + " is not currently supported for CSV formatting.");
+ throw new FormattingException(dto.getClass().getName()
+ + " is not currently supported for CSV formatting.");
}
} catch (Exception e) {
throw new FormattingException("Could not serialize:" + dto.getClass().getName(), e);
@@ -56,7 +57,8 @@ public String format(List extends CwmsDTOBase> dtoList) {
} else if (dto instanceof LocationGroup) {
return new CsvV1LocationGroup().format(dtoList);
} else {
- throw new FormattingException(dto.getClass().getName() + " is not currently supported for CSV formatting.");
+ throw new FormattingException(dto.getClass().getName()
+ + " is not currently supported for CSV formatting.");
}
}
return null;
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1LocationGroup.java b/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1LocationGroup.java
index e9b49641c8..1dc2a8a390 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1LocationGroup.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1LocationGroup.java
@@ -1,7 +1,5 @@
package cwms.cda.formatters.csv;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -10,6 +8,7 @@
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
+import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dto.AssignedLocation;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.LocationCategory;
@@ -17,20 +16,21 @@
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.OutputFormatter;
import io.swagger.v3.oas.annotations.media.Schema;
-
+import java.util.List;
@Schema(
name = "LocationGroup_CSV",
description = "Single LocationGroup or List of LocationGroups in comma separated format",
example =
- "#LocationGroup Id, OfficeId, Description, CategoryId, CategoryOfficeId, SharedLocAliasId, SharedRefLocationId, LocGroupAttribute\r\n"+
- "CERL,Construction Engineering Research Laboratory,Field Operating Activity ERD\r\n"+
- "CHL,Coastal and Hydraulics Laboratory,Field Operating Activity ERD\r\n" +
- "NAB,Baltimore District,District,NAD\r\n"+
- "NAD,North Atlantic Division,Division Headquarters,HQ"
+ "#LocationGroup Id, OfficeId, Description, CategoryId, CategoryOfficeId, SharedLocAliasId, SharedRefLocationId,"
+ + "LocGroupAttribute\r\n"
+ + "CERL,Construction Engineering Research Laboratory,Field Operating Activity\tERD\r\n"
+ + "CHL,Coastal and Hydraulics Laboratory,Field Operating Activity\tERD\r\n"
+ + "NAB,Baltimore District,District,NAD\r\n"
+ + "NAD,North Atlantic Division,Division Headquarters,HQ"
)
public class CsvV1LocationGroup implements OutputFormatter {
-
+ private static final FluentLogger LOGGER = FluentLogger.forEnclosingClass();
@Schema(hidden = true)
@Override
@@ -46,26 +46,13 @@ public String format(CwmsDTOBase dto) {
try {
String s = writer.writeValueAsString(locationGroup);
return "#LocationGroup " + s;
- } catch(JsonProcessingException e) {
- e.printStackTrace();
+ } catch (JsonProcessingException e) {
+ LOGGER.atFine().withCause(e).log("Unable to format location group.");
}
return null;
}
- private ObjectWriter buildWriter() {
- CsvMapper mapper = new CsvMapper();
- mapper.addMixInAnnotations(LocationGroup.class, LocationGroupFormat.class);
- mapper.addMixInAnnotations(LocationCategory.class, LocationCategoryFormat.class);
- CsvSchema schema = mapper.schemaFor(LocationGroup.class)
- .withLineSeparator("\n")
- .withHeader();
-
- ObjectWriter writer = mapper.writer(schema);
-
- return writer;
- }
-
@Override
@SuppressWarnings("unchecked") // for the daoList conversion
public String format(List extends CwmsDTOBase> dtoList) {
@@ -74,21 +61,34 @@ public String format(List extends CwmsDTOBase> dtoList) {
try {
String s = writer.writeValueAsString(locationGroups);
return "#LocationGroup " + s;
- } catch(JsonProcessingException e) {
- e.printStackTrace();
+ } catch (JsonProcessingException e) {
+ LOGGER.atFine().withCause(e).log("Unable to format location group.");
}
return null;
}
+ private ObjectWriter buildWriter() {
+ CsvMapper mapper = new CsvMapper();
+ mapper.addMixInAnnotations(LocationGroup.class, LocationGroupFormat.class);
+ mapper.addMixInAnnotations(LocationCategory.class, LocationCategoryFormat.class);
+ CsvSchema schema = mapper.schemaFor(LocationGroup.class)
+ .withLineSeparator("\n")
+ .withHeader();
+
+ ObjectWriter writer = mapper.writer(schema);
+
+ return writer;
+ }
// Mixin for LocationGroup
// This class doesn't have to be related to LocationGroup, it just has to look like it.
// We can add the annotations we want here and when LocationGroup is serialized it will
// serialize like LocationGroupFormat
- @JsonPropertyOrder({"id", "officeId", "description", "locationCategory",
- "sharedLocAliasId", "sharedRefLocationId", "locGroupAttribute" })
- private static abstract class LocationGroupFormat {
+ @JsonPropertyOrder({
+ "id", "officeId", "description", "locationCategory",
+ "sharedLocAliasId", "sharedRefLocationId", "locGroupAttribute" })
+ private abstract static class LocationGroupFormat {
@JsonProperty("Id")
abstract String getId();
@@ -117,7 +117,7 @@ private static abstract class LocationGroupFormat {
}
// Mixin for LocationCategory
- private static abstract class LocationCategoryFormat {
+ private abstract static class LocationCategoryFormat {
@JsonProperty("CategoryOfficeId")
abstract String getOfficeId();
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1Office.java b/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1Office.java
index 55ae0f664b..3ab8fd29ea 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1Office.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/csv/CsvV1Office.java
@@ -1,26 +1,25 @@
package cwms.cda.formatters.csv;
-import java.util.List;
-
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.Office;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.OutputFormatter;
import io.swagger.v3.oas.annotations.media.Schema;
+import java.util.List;
@Schema(
name = "Office_CSV",
description = "Single Office or List of Offices in comma separated format",
example =
- "#Office Name,Long Name,Office Type,Reports To Office\r\n"+
- "CERL,Construction Engineering Research Laboratory,Field Operating Activity ERD\r\n"+
- "CHL,Coastal and Hydraulics Laboratory,Field Operating Activity ERD\r\n" +
- "NAB,Baltimore District,District,NAD\r\n"+
- "NAD,North Atlantic Division,Division Headquarters,HQ"
+ "#Office Name,Long Name,Office Type,Reports To Office\r\n"
+ + "CERL,Construction Engineering Research Laboratory,Field Operating Activity ERD\r\n"
+ + "CHL,Coastal and Hydraulics Laboratory,Field Operating Activity ERD\r\n"
+ + "NAB,Baltimore District,District,NAD\r\n"
+ + "NAD,North Atlantic Division,Division Headquarters,HQ"
)
public class CsvV1Office implements OutputFormatter {
- public String Office;
+ public String office;
public String longName;
public String officeType;
public String reportsToOffice;
@@ -47,7 +46,7 @@ public String format(List extends CwmsDTOBase> dtoList) {
List offices = (List)dtoList;
StringBuilder builder = new StringBuilder();
builder.append(getOfficeTabHeader()).append("\r\n");
- for( Office office: offices){
+ for (Office office: offices) {
builder.append(officeRow(office)).append("\r\n");
}
return builder.toString();
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV1.java
index 4c23982432..9cd1c631ac 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV1.java
@@ -38,10 +38,18 @@ public JsonV1() {
this(OBJECT_MAPPER);
}
+ /**
+ * Create a V1 instance using the project ObjectMapper.
+ * @param om ObjectMapper with its own settings.
+ */
public JsonV1(ObjectMapper om) {
this.om = om;
}
+ /**
+ * Build an ObjectMapper with appropriate default settings for V1 JSON.
+ * @return ObjectMapper Instance.
+ */
@NotNull
public static ObjectMapper buildObjectMapper() {
ObjectMapper retVal = new ObjectMapper();
@@ -132,24 +140,11 @@ private Object buildFormatting(CwmsDTOBase dto) {
}
throw new BadRequestResponse(
String.format("Format %s not implemented for data of class:%s",
- getContentType(), klassName));
+ getContentType(), klassName));
}
return retVal;
}
- private boolean isFormattableWith(Class> klass) {
- FormattableWith[] formats = klass.getAnnotationsByType(FormattableWith.class);
- for (FormattableWith format : formats) {
- /*
- * Compare against the actual formatter not the name
- */
- if (format.formatter().equals(JsonV1.class)) {
- return true;
- }
- }
- return false;
- }
-
private Object buildFormatting(List extends CwmsDTOBase> daoList) {
Object retVal = null;
@@ -182,4 +177,16 @@ private Object buildFormatting(List extends CwmsDTOBase> daoList) {
return retVal;
}
+ private boolean isFormattableWith(Class> klass) {
+ FormattableWith[] formats = klass.getAnnotationsByType(FormattableWith.class);
+ for (FormattableWith format : formats) {
+ /*
+ * Compare against the actual formatter not the name
+ */
+ if (format.formatter().equals(JsonV1.class)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV2.java b/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV2.java
index 97c74a2599..c8ccf2ff5a 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV2.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/json/JsonV2.java
@@ -38,12 +38,11 @@
import cwms.cda.formatters.FormattingException;
import cwms.cda.formatters.OutputFormatter;
import cwms.cda.formatters.json.adapters.ZoneIdDeserializer;
-import org.jetbrains.annotations.NotNull;
-
import java.io.IOException;
import java.io.InputStream;
import java.time.ZoneId;
import java.util.List;
+import org.jetbrains.annotations.NotNull;
/**
* Formatter for CDA generated JSON.
@@ -61,6 +60,10 @@ public JsonV2(ObjectMapper om) {
this.om = om;
}
+ /**
+ * Create ObjectMapper instance with system expected default settings.
+ * @return ObjectMapper instance.
+ */
@NotNull
public static ObjectMapper buildObjectMapper() {
ObjectMapper retVal = new ObjectMapper();
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/json/NamedPgJsonFormatter.java b/cwms-data-api/src/main/java/cwms/cda/formatters/json/NamedPgJsonFormatter.java
index da38a06fc0..c3b3ca71d3 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/json/NamedPgJsonFormatter.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/json/NamedPgJsonFormatter.java
@@ -1,5 +1,7 @@
package cwms.cda.formatters.json;
+import static cwms.cda.formatters.Formats.NAMED_PGJSON;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import cwms.cda.api.graph.Graph;
@@ -8,19 +10,15 @@
import cwms.cda.api.graph.pg.dto.PgGraphData;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.basinconnectivity.Basin;
-import cwms.cda.formatters.Formats;
import cwms.cda.formatters.FormattingException;
import cwms.cda.formatters.OutputFormatter;
-
import java.util.ArrayList;
import java.util.List;
-import static cwms.cda.formatters.Formats.NAMED_PGJSON;
-
public class NamedPgJsonFormatter implements OutputFormatter {
private final ObjectMapper om;
- public NamedPgJsonFormatter() {
+ public NamedPgJsonFormatter() {
om = new ObjectMapper();
}
@@ -39,7 +37,9 @@ public String format(CwmsDTOBase dto) {
String name = basin.getBasinName();
retVal = formatNamedGraph(name, graph);
} else {
- throw new FormattingException(dto.getClass().getSimpleName() + " is not currently supported for Named-PG-JSON format.");
+ throw new FormattingException(
+ dto.getClass().getSimpleName()
+ + " is not currently supported for Named-PG-JSON format.");
}
} catch (JsonProcessingException e) {
throw new FormattingException(e.getMessage());
@@ -50,7 +50,7 @@ public String format(CwmsDTOBase dto) {
@Override
public String format(List extends CwmsDTOBase> dtoList) {
StringBuilder retVal = new StringBuilder();
- for(CwmsDTOBase dto : dtoList) {
+ for (CwmsDTOBase dto : dtoList) {
retVal.append(format(dto));
}
return retVal.toString();
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/json/PgJsonFormatter.java b/cwms-data-api/src/main/java/cwms/cda/formatters/json/PgJsonFormatter.java
index 583acf3ee2..adff2e19d3 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/json/PgJsonFormatter.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/json/PgJsonFormatter.java
@@ -2,7 +2,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import cwms.cda.api.graph.Edge;
import cwms.cda.api.graph.Graph;
import cwms.cda.api.graph.Node;
@@ -10,7 +9,9 @@
import cwms.cda.api.graph.basinconnectivity.edges.ReachEdge;
import cwms.cda.api.graph.basinconnectivity.edges.StreamEdge;
import cwms.cda.api.graph.basinconnectivity.nodes.BasinConnectivityNode;
-import cwms.cda.api.graph.pg.dto.*;
+import cwms.cda.api.graph.pg.dto.PgEdgeData;
+import cwms.cda.api.graph.pg.dto.PgGraphData;
+import cwms.cda.api.graph.pg.dto.PgNodeData;
import cwms.cda.api.graph.pg.properties.PgProperties;
import cwms.cda.api.graph.pg.properties.basinconnectivity.PgReachEdgeProperties;
import cwms.cda.api.graph.pg.properties.basinconnectivity.PgStreamEdgeProperties;
@@ -20,8 +21,8 @@
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.FormattingException;
import cwms.cda.formatters.OutputFormatter;
-
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
public final class PgJsonFormatter implements OutputFormatter {
@@ -32,13 +33,18 @@ public PgJsonFormatter() {
}
private String formatGraph(Graph graph) throws JsonProcessingException {
- String retVal = getDefaultPGJSON();
+ String retVal = getDefaultPgJson();
if (!graph.isEmpty()) {
retVal = om.writeValueAsString(getFormattedGraph(graph));
}
return retVal;
}
+ /**
+ * Return the provide Graph data is a PgGraphData node.
+ * @param graph CWMS Graph Representation
+ * @return PgGraphdata represenetation
+ */
public PgGraphData getFormattedGraph(Graph graph) {
List formattedNodes = formatNodes(graph.getNodes());
List formattedEdges = formatEdges(graph.getEdges());
@@ -53,12 +59,20 @@ private List formatEdges(List edges) {
StreamEdge streamEdge = (StreamEdge) edge;
PgProperties properties = new PgStreamEdgeProperties(streamEdge.getStreamId());
String[] labels = new String[]{streamEdge.getLabel()};
- edgeData = new PgEdgeData(streamEdge.getSource().getId(), streamEdge.getTarget().getId(), labels, false, properties);
- } else if(edge instanceof ReachEdge) {
+ edgeData = new PgEdgeData(streamEdge.getSource().getId(),
+ streamEdge.getTarget().getId(),
+ labels,
+ false,
+ properties);
+ } else if (edge instanceof ReachEdge) {
ReachEdge reachEdge = (ReachEdge) edge;
PgProperties properties = new PgReachEdgeProperties(reachEdge.getStreamId(), reachEdge.getId());
String[] labels = new String[]{reachEdge.getLabel()};
- edgeData = new PgEdgeData(reachEdge.getSource().getId(), reachEdge.getTarget().getId(), labels, false, properties);
+ edgeData = new PgEdgeData(reachEdge.getSource().getId(),
+ reachEdge.getTarget().getId(),
+ labels,
+ false,
+ properties);
} else {
throw new IllegalArgumentException("PG-JSON format does not currently support this Edge type");
}
@@ -74,7 +88,9 @@ private List formatNodes(List nodes) {
String nodeId = node.getId();
BasinConnectivityNode basinConnNode = (BasinConnectivityNode) node;
String[] labels = new String[]{basinConnNode.getLabel()};
- PgProperties properties = new PgStreamNodeProperties(basinConnNode.getStreamId(), basinConnNode.getStation(), basinConnNode.getBank());
+ PgProperties properties = new PgStreamNodeProperties(
+ basinConnNode.getStreamId(), basinConnNode.getStation(), basinConnNode.getBank()
+ );
retVal.add(new PgNodeData(nodeId, labels, properties));
} else {
throw new IllegalArgumentException("PG-JSON format does not currently support this Node type");
@@ -83,7 +99,7 @@ private List formatNodes(List nodes) {
return retVal;
}
- private String getDefaultPGJSON() throws JsonProcessingException {
+ private String getDefaultPgJson() throws JsonProcessingException {
return om.writeValueAsString(new PgGraphData(new ArrayList<>(), new ArrayList<>()));
}
@@ -100,7 +116,8 @@ public String format(CwmsDTOBase dto) {
Basin basin = (Basin) dto;
graph = new BasinConnectivityGraph.Builder(basin).build();
} else {
- throw new FormattingException(dto.getClass().getSimpleName() + " is not currently supported for PG-JSON format.");
+ throw new FormattingException(dto.getClass().getSimpleName()
+ + " is not currently supported for PG-JSON format.");
}
try {
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/TimeSeriesRecordSerializer.java b/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/TimeSeriesRecordSerializer.java
index 2091c3cf78..38f7e93f42 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/TimeSeriesRecordSerializer.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/TimeSeriesRecordSerializer.java
@@ -67,8 +67,8 @@ public void serialize(TimeSeries.Record recordValue, JsonGenerator gen, Serializ
gen.writeNumber(recordValue.getValue());
}
gen.writeNumber(recordValue.getQualityCode());
- // Used to include the dataEntryDate in the serialized output if requested. Modifies length of the output array.
- // If the dataEntryDate is requested, it will always be non-null
+ // Used to include the dataEntryDate in the serialized output if requested. Modifies length of
+ // the output array. If the dataEntryDate is requested, it will always be non-null
// Without the dataEntryDate, the array will have 3 elements: [dateTime, value, qualityCode]
if (recordValue.getDataEntryDate() != null) {
gen.writeNumber(recordValue.getDataEntryDate().getTime());
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/ZonedDateTimeJsonDeserializer.java b/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/ZonedDateTimeJsonDeserializer.java
index 96b84bff9b..74bc7ebabe 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/ZonedDateTimeJsonDeserializer.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/json/adapters/ZonedDateTimeJsonDeserializer.java
@@ -1,14 +1,12 @@
package cwms.cda.formatters.json.adapters;
-import java.io.IOException;
-import java.time.ZonedDateTime;
-
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-
import cwms.cda.helpers.DateUtils;
+import java.io.IOException;
+import java.time.ZonedDateTime;
public class ZonedDateTimeJsonDeserializer extends StdDeserializer {
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1.java
index 26fe164b08..4b186cd9fd 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1.java
@@ -1,12 +1,11 @@
package cwms.cda.formatters.tab;
-import java.io.InputStream;
-import java.util.List;
-
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.Office;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.OutputFormatter;
+import java.io.InputStream;
+import java.util.List;
public class TabV1 implements OutputFormatter {
@@ -17,7 +16,7 @@ public String getContentType() {
@Override
public String format(CwmsDTOBase dto) {
- if (dto instanceof Office ) {
+ if (dto instanceof Office) {
return new TabV1Office().format(dto);
} else {
return null;
@@ -26,7 +25,7 @@ public String format(CwmsDTOBase dto) {
@Override
public String format(List extends CwmsDTOBase> dtoList) {
- if (!dtoList.isEmpty() && dtoList.get(0) instanceof Office ) {
+ if (!dtoList.isEmpty() && dtoList.get(0) instanceof Office) {
return new TabV1Office().format(dtoList);
} else {
return null;
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1Office.java b/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1Office.java
index b3553dcd93..66124daa15 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1Office.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/tab/TabV1Office.java
@@ -1,25 +1,25 @@
package cwms.cda.formatters.tab;
-import java.util.List;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.Office;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.OutputFormatter;
import io.swagger.v3.oas.annotations.media.Schema;
+import java.util.List;
@Schema(
name = "Office_Tabulation",
description = "Single Office or List of Offices in tab separated format",
example =
- "#Office NameLong NameOffice TypeReports To Office\r\n"+
- "CERL Construction Engineering Research Laboratory Field Operating Activity ERD\r\n"+
- "CHL Coastal and Hydraulics Laboratory Field Operating Activity ERD\r\nNAB Baltimore District District NAD"+
- "NAD North Atlantic Division Division Headquarters HQ"
+ "#Office NameLong NameOffice TypeReports To Office\r\n"
+ + "CERL\tConstruction Engineering Research Laboratory\tField Operating Activity\tERD\r\n"
+ + "CHL\tCoastal and Hydraulics Laboratory\tField Operating Activity\tERD\r\nNAB\tBaltimore District\tDistrict\tNAD"
+ + "NAD\tNorth Atlantic Division\tDivision Headquarters\tHQ"
)
public class TabV1Office implements OutputFormatter {
- public String Office;
+ public String office;
public String longName;
public String officeType;
public String reportsToOffice;
@@ -53,10 +53,10 @@ public String format(List extends CwmsDTOBase> dtoList) {
}
private String getOfficeTabHeader() {
- return "#Office Name Long Name Office Type Reports To Office";
+ return "#Office Name\tLong Name\tOffice Type\tReports To Office";
}
- private String officeRow(Office office){
+ private String officeRow(Office office) {
StringBuilder builder = new StringBuilder();
builder.append(office.getName()).append("\t")
.append(office.getLongName()).append("\t")
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/TimeSeriesXmlMixin.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/TimeSeriesXmlMixin.java
index 95ab09b8fd..6228b8d2bd 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/TimeSeriesXmlMixin.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/TimeSeriesXmlMixin.java
@@ -27,12 +27,11 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import cwms.cda.data.dto.TimeSeries;
-
import java.util.List;
@JsonIgnoreProperties({"interval-minutes"})
abstract class TimeSeriesXmlMixin {
//XML serialization doesn't optimize the same as JSON and needs to list the element names
- @JsonFormat(shape=JsonFormat.Shape.OBJECT)
+ @JsonFormat(shape = JsonFormat.Shape.OBJECT)
abstract List getValues();
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/VerticalDatumInfoMixin.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/VerticalDatumInfoMixin.java
index 1e56f0d1f0..d9b8b4b259 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/VerticalDatumInfoMixin.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/VerticalDatumInfoMixin.java
@@ -32,15 +32,16 @@
import cwms.cda.data.dto.VerticalDatumInfo;
/**
- *
+ * Handles Vertical Datum Info that may be embedded within another DTO.
*/
abstract class VerticalDatumInfoMixin {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "offset")
@JsonProperty("offset")
abstract VerticalDatumInfo.Offset[] getOffsets();
+
@JsonPOJOBuilder
- public static abstract class Builder {
+ public abstract static class Builder {
@JsonSetter("offset")
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "offset")
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1.java
index 675fbb79a6..4838c7c397 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1.java
@@ -7,6 +7,7 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.Office;
import cwms.cda.data.dto.VerticalDatumInfo;
@@ -15,15 +16,13 @@
import cwms.cda.formatters.OutputFormatter;
import cwms.cda.formatters.json.adapters.ZoneIdDeserializer;
import io.javalin.http.InternalServerErrorResponse;
-import java.util.Set;
-import org.jetbrains.annotations.NotNull;
-
import java.io.IOException;
import java.io.InputStream;
import java.time.ZoneId;
import java.util.Collections;
import java.util.List;
-import com.google.common.flogger.FluentLogger;
+import java.util.Set;
+import org.jetbrains.annotations.NotNull;
public class XMLv1 implements OutputFormatter {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@@ -48,7 +47,6 @@ public String getContentType() {
@Override
public String format(CwmsDTOBase dto) {
try {
-
if (dto instanceof Office) {
return om.writeValueAsString(new XMLv1Office(Collections.singletonList((Office)dto)));
}
@@ -68,7 +66,6 @@ public String format(CwmsDTOBase dto) {
@SuppressWarnings("unchecked") // we're ALWAYS checking before conversion in this function
public String format(List extends CwmsDTOBase> dtoList) {
try {
-
if (!dtoList.isEmpty() && dtoList.get(0) instanceof Office) {
return om.writeValueAsString(new XMLv1Office((List) dtoList));
}
@@ -97,6 +94,10 @@ public T parseContent(InputStream content, Class type
}
}
+ /**
+ * Create instance of XmlMapper with default settings for XML Version 1 Data.
+ * @return XmlMapper instance
+ */
public static @NotNull XmlMapper buildObjectMapper() {
XmlMapper retval = new XmlMapper();
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1Office.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1Office.java
index 516dc3d83c..c731b2d0b5 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1Office.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv1Office.java
@@ -1,12 +1,10 @@
package cwms.cda.formatters.xml;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-
import cwms.cda.data.dto.Office;
+import java.util.List;
@JsonRootName("offices")
@JacksonXmlRootElement(localName = "offices")
@@ -14,10 +12,11 @@ public class XMLv1Office {
@JacksonXmlProperty(localName = "offices")
List offices;
+ public XMLv1Office() {
+ /* default constructor */
+ }
- public XMLv1Office(){}
-
- public XMLv1Office(List offices){
+ public XMLv1Office(List offices) {
this.offices = offices;
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2.java
index 5d8716772c..7b10d8f9db 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2.java
@@ -8,6 +8,7 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.TimeSeries;
import cwms.cda.formatters.Formats;
@@ -15,13 +16,11 @@
import cwms.cda.formatters.OutputFormatter;
import cwms.cda.formatters.json.adapters.ZoneIdDeserializer;
import io.javalin.http.InternalServerErrorResponse;
-import org.jetbrains.annotations.NotNull;
-
import java.io.IOException;
import java.io.InputStream;
import java.time.ZoneId;
import java.util.List;
-import com.google.common.flogger.FluentLogger;
+import org.jetbrains.annotations.NotNull;
public class XMLv2 implements OutputFormatter {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@@ -90,6 +89,10 @@ public T parseContent(InputStream content, Class type
}
}
+ /**
+ * Default instance of XmlMapper with suitable configuration of XML Version 2 Data.
+ * @return XmlMapper instance.
+ */
public static @NotNull XmlMapper buildXmlMapper() {
XmlMapper retval = new XmlMapper();
retval.findAndRegisterModules();
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2Office.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2Office.java
index 92f3cedd6f..862a1080a6 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2Office.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/XMLv2Office.java
@@ -8,22 +8,20 @@
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.google.common.flogger.FluentLogger;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.Office;
import cwms.cda.data.dto.TimeSeries;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.OutputFormatter;
import io.javalin.http.InternalServerErrorResponse;
-import org.jetbrains.annotations.NotNull;
-
import java.io.InputStream;
import java.io.StringWriter;
import java.util.List;
-import com.google.common.flogger.FluentLogger;
-
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+import org.jetbrains.annotations.NotNull;
/**
* An entire day was spent trying to get FasterXML to behave correctly
@@ -76,18 +74,18 @@ public String format(List extends CwmsDTOBase> dtoList) {
for (CwmsDTOBase dto: dtoList) {
Office office = (Office)dto;
writer.writeStartElement("office");
- writer.writeStartElement("name");
- writer.writeCharacters(office.getName());
- writer.writeEndElement();
- writer.writeStartElement("long-name");
- writer.writeCharacters(office.getLongName());
- writer.writeEndElement();
- writer.writeStartElement("type");
- writer.writeCharacters(office.getType());
- writer.writeEndElement();
- writer.writeStartElement("reports-to");
- writer.writeCharacters(office.getReportsTo());
- writer.writeEndElement();
+ writer.writeStartElement("name");
+ writer.writeCharacters(office.getName());
+ writer.writeEndElement();
+ writer.writeStartElement("long-name");
+ writer.writeCharacters(office.getLongName());
+ writer.writeEndElement();
+ writer.writeStartElement("type");
+ writer.writeCharacters(office.getType());
+ writer.writeEndElement();
+ writer.writeStartElement("reports-to");
+ writer.writeCharacters(office.getReportsTo());
+ writer.writeEndElement();
writer.writeEndElement();
}
writer.writeEndElement();
@@ -95,10 +93,9 @@ public String format(List extends CwmsDTOBase> dtoList) {
return out.toString();
} catch (XMLStreamException ex) {
- String msg = dtoList != null ?
- "Error rendering '" + dtoList + "' to XML"
- :
- "Null element passed to formatter";
+ String msg = dtoList != null
+ ? "Error rendering '" + dtoList + "' to XML"
+ : "Null element passed to formatter";
logger.atWarning().withCause(ex).log(msg);
throw new InternalServerErrorResponse("Invalid Parameters");
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/DurationAdapter.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/DurationAdapter.java
index 0a090afd4e..b5f7ab2bf7 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/DurationAdapter.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/DurationAdapter.java
@@ -1,7 +1,6 @@
package cwms.cda.formatters.xml.adapters;
import java.time.Duration;
-
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class DurationAdapter extends XmlAdapter {
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/TimestampAdapter.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/TimestampAdapter.java
index 62e06ae49e..b958f4b3f5 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/TimestampAdapter.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/TimestampAdapter.java
@@ -2,10 +2,6 @@
import java.sql.Timestamp;
import java.time.Instant;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class TimestampAdapter extends XmlAdapter {
diff --git a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/ZonedDateTimeAdapter.java b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/ZonedDateTimeAdapter.java
index 4bcecd72d1..dcb3954511 100644
--- a/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/ZonedDateTimeAdapter.java
+++ b/cwms-data-api/src/main/java/cwms/cda/formatters/xml/adapters/ZonedDateTimeAdapter.java
@@ -2,7 +2,6 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
-
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class ZonedDateTimeAdapter extends XmlAdapter {
diff --git a/cwms-data-api/src/main/java/cwms/cda/helpers/DatabaseHelpers.java b/cwms-data-api/src/main/java/cwms/cda/helpers/DatabaseHelpers.java
index b1a1cd526a..5cd60f43b7 100644
--- a/cwms-data-api/src/main/java/cwms/cda/helpers/DatabaseHelpers.java
+++ b/cwms-data-api/src/main/java/cwms/cda/helpers/DatabaseHelpers.java
@@ -14,8 +14,7 @@ public enum SCHEMA_VERSION {
private final int numeric;
private final String text;
- SCHEMA_VERSION(int numeric, String text)
- {
+ SCHEMA_VERSION(int numeric, String text) {
this.numeric = numeric;
this.text = text;
}
@@ -28,12 +27,15 @@ public String text() {
return this.text;
}
- public static SCHEMA_VERSION fromNumeric(int value)
- {
- for(var tmp: SCHEMA_VERSION.values())
- {
- if (tmp.numeric == value)
- {
+ /**
+ * Return Schema enum constant from provided database version integer.
+ * @param value the integer representation of the database schema version.
+ * @return the appropriate Enum
+ * @throws IllegalArgumentException if the value cannot be mapped.
+ */
+ public static SCHEMA_VERSION fromNumeric(int value) {
+ for (var tmp: SCHEMA_VERSION.values()) {
+ if (tmp.numeric == value) {
return tmp;
}
}
diff --git a/cwms-data-api/src/main/java/cwms/cda/helpers/DateUtils.java b/cwms-data-api/src/main/java/cwms/cda/helpers/DateUtils.java
index deb1d09022..72402cfb15 100644
--- a/cwms-data-api/src/main/java/cwms/cda/helpers/DateUtils.java
+++ b/cwms-data-api/src/main/java/cwms/cda/helpers/DateUtils.java
@@ -1,8 +1,6 @@
package cwms.cda.helpers;
import com.google.common.flogger.FluentLogger;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;
@@ -17,6 +15,8 @@
import java.time.temporal.TemporalAccessor;
import java.util.Optional;
import java.util.regex.Pattern;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
public class DateUtils {
@@ -60,15 +60,29 @@ public static ZonedDateTime parseUserDate(@NotNull String text, @NotNull String
return parseUserDate(text, tz, ZonedDateTime.now(tz));
}
+ /**
+ * Parse a string into a ZonedDateTime. Automatically determined if input provided was
+ * an ISO8061 Date/Time, Period, or Duration string. "now" (time of executation) is used
+ * as the relative starting point by default.
+ * @param text provided date/time string
+ * @param tz desired time zone for the output instance.
+ * @return a valid ZonedDateTime instance
+ */
@NotNull
- public static ZonedDateTime parseUserDate(@NotNull String text, @NotNull ZoneId tz){
+ public static ZonedDateTime parseUserDate(@NotNull String text, @NotNull ZoneId tz) {
return parseUserDate(text, tz, ZonedDateTime.now(tz));
}
-
+ /**
+ * Parse a string into a ZonedDateTime. Automatically determined if input provided was
+ * an ISO8061 Date/Time, Period, or Duration string.
+ * @param text provided date/time string
+ * @param tz desired time zone for the output instance.
+ * @param now starting point for Duration and Period.
+ * @return a valid ZonedDateTime instance
+ */
@NotNull
public static ZonedDateTime parseUserDate(@NotNull String text, @NotNull ZoneId tz, @NotNull ZonedDateTime now) {
-
if (text.startsWith("PT")) {
return parseUserDuration(text, now);
} else if (text.startsWith("P")) {
@@ -78,6 +92,13 @@ public static ZonedDateTime parseUserDate(@NotNull String text, @NotNull ZoneId
}
}
+ /**
+ * Parse the given date/time text and return a ZonedDateTime in the provided timezone.
+ *
+ * @param text date/time string.
+ * @param tz desired Time Zone
+ * @return a valid ZonedDateTime instance
+ */
@NotNull
private static ZonedDateTime parseFullDate(@NotNull String text, @NotNull ZoneId tz) {
@@ -117,7 +138,13 @@ public static boolean hasZone(@NotNull String text) {
return WITH_TZ_INFO.matcher(text).matches();
}
-
+ /**
+ * Parse the given date string wit the default ZonedDateTime.parse, if that fails,
+ * attempt parse with yyyy-MM-dd'T'HH:mm:ssZ
+ * @param text provied date time string
+ * @return A ZonedDateTime instance
+ * @throws DateTimeParseException if the date could not be processed.
+ */
@NotNull
private static ZonedDateTime parseZonedDateTime(@NotNull String text) {
ZonedDateTime zdt;
@@ -129,7 +156,7 @@ private static ZonedDateTime parseZonedDateTime(@NotNull String text) {
// To match 2022-01-19T20:52:53+0000[UTC]
String[] possibleDateFormats = { "yyyy-MM-dd'T'HH:mm:ssZ"}; // Can add formats as needed
Optional parsed = firstMatch(text, possibleDateFormats);
- if(parsed.isPresent()) {
+ if (parsed.isPresent()) {
zdt = parsed.get();
} else {
throw e;
@@ -139,6 +166,12 @@ private static ZonedDateTime parseZonedDateTime(@NotNull String text) {
return zdt;
}
+ /**
+ * Part user given date with a series of formats, returning the first valid interpretation.
+ * @param text user provided date string
+ * @param possibleDateFormats list of possible date formats
+ * @return ZonedDateTime if one of the patterns matched. Otherwise Optional.empty().
+ */
@NotNull
private static Optional firstMatch(@NotNull String text, @Nullable String[] possibleDateFormats) {
Optional retval = Optional.empty();
@@ -146,14 +179,20 @@ private static Optional firstMatch(@NotNull String text, @Nullabl
if (possibleDateFormats != null) {
for (String format : possibleDateFormats) {
retval = parseWithPattern(text, format);
- if(retval.isPresent())
+ if (retval.isPresent()) {
break;
}
}
-
+ }
return retval;
}
+ /**
+ * Parse the given string text against the provided pattern.
+ * @param text user provided date string
+ * @param pattern expected date pattern to match.
+ * @return ZonedDateTime if the input was valid for the given pattern, otherwise Optional.empty().
+ */
@NotNull
public static Optional parseWithPattern(@NotNull String text, @NotNull String pattern) {
Optional retval = Optional.empty();
@@ -172,6 +211,11 @@ public static Optional parseWithPattern(@NotNull String text, @No
return retval;
}
+ /**
+ * Add ZoneID to the the given DateTimeFormatterBuilder.
+ * @param builder a valid builder instance
+ * @return The same DateTimeFormatterBuilder
+ */
@NotNull
private static DateTimeFormatterBuilder appendZoneId(@NotNull DateTimeFormatterBuilder builder) {
return builder.optionalStart() // This is to allow for bracket zoneId like [Europe/Paris]
@@ -181,6 +225,12 @@ private static DateTimeFormatterBuilder appendZoneId(@NotNull DateTimeFormatterB
.appendLiteral(']');
}
+ /**
+ * Increment the given time instance by a provided ISO8601 formatted Period.
+ * @param text provided ISO8601 period string
+ * @param now a ZoneDateTime instance
+ * @return a new ZonedDateTime instance of now + period(text)
+ */
@NotNull
private static ZonedDateTime parserUserPeriod(@NotNull String text, @NotNull ZonedDateTime now) {
Period period = Period.parse(text);
@@ -189,12 +239,24 @@ private static ZonedDateTime parserUserPeriod(@NotNull String text, @NotNull Zon
.plusDays(period.getDays());
}
+ /**
+ * Increment the given time instance by a provided ISO8601 formatted Duartion.
+ * @param text provided ISO8601 duration string
+ * @param now a ZoneDateTime instance
+ * @return a new ZonedDateTime instance of now + duration(text)
+ */
@NotNull
private static ZonedDateTime parseUserDuration(@NotNull String text, @NotNull ZonedDateTime now) {
Duration duration = Duration.parse(text);
return now.plus(duration);
}
+ /**
+ * Convert a {@link java.sql.Timestamp} value to a ZonedDateTime.
+ * ZonedDateTime returned will be in UTC.
+ * @param time provided java.sql.Timestamp, or null.
+ * @return ZoneDateTime if time is not null, otherwise null.
+ */
@Nullable
public static ZonedDateTime toZdt(@Nullable final Timestamp time) {
if (time != null) {
diff --git a/cwms-data-api/src/main/java/cwms/cda/helpers/ReplaceUtils.java b/cwms-data-api/src/main/java/cwms/cda/helpers/ReplaceUtils.java
index 019bfb8c60..1060115565 100644
--- a/cwms-data-api/src/main/java/cwms/cda/helpers/ReplaceUtils.java
+++ b/cwms-data-api/src/main/java/cwms/cda/helpers/ReplaceUtils.java
@@ -21,11 +21,11 @@ private ReplaceUtils() {
* @param key the key to be replaced in the template
* @return a Function that replaces occurrences of the key with a specified value
*/
- public static UnaryOperator replace(@NotNull String template, @NotNull String key){
- return value-> replace(template, key, value);
+ public static UnaryOperator replace(@NotNull String template, @NotNull String key) {
+ return value -> replace(template, key, value);
}
- public static String replace(@NotNull String template, @NotNull String key, String value){
+ public static String replace(@NotNull String template, @NotNull String key, String value) {
return replace(template, key, value, true);
}
@@ -38,8 +38,9 @@ public static String replace(@NotNull String template, @NotNull String key, Stri
* @param encode true to URL encode the value, false otherwise
* @return the modified string template with the key replaced by the value
* @throws NullPointerException if the template is null
+ * @throws RuntimeException any other error
*/
- public static String replace(@NotNull String template, String key, String value, boolean encode){
+ public static String replace(@NotNull String template, String key, String value, boolean encode) {
String result = null;
try {
@@ -68,12 +69,13 @@ public static String replace(@NotNull String template, String key, String value,
* @param value the value to replace the key with
* @return a new Function that replaces occurrences of the key with the value
*/
- public static UnaryOperator alsoReplace(UnaryOperator mapper, String key, String value){
- return s-> replace(mapper.apply(s), key, value);
+ public static UnaryOperator alsoReplace(UnaryOperator mapper, String key, String value) {
+ return s -> replace(mapper.apply(s), key, value);
}
- public static UnaryOperator alsoReplace(UnaryOperator mapper, String key, String value, boolean encode){
- return s-> replace(mapper.apply(s), key, value, encode);
+ public static UnaryOperator alsoReplace(UnaryOperator mapper, String key,
+ String value, boolean encode) {
+ return s -> replace(mapper.apply(s), key, value, encode);
}
@@ -93,12 +95,25 @@ public OperatorBuilder withTemplate(String template) {
return this;
}
+ /**
+ * Replace the given parameter with the value, performing url encoding.
+ * @param key key to change
+ * @param value value to substitute
+ * @return the OperationBuilder
+ */
public OperatorBuilder replace(String key, String value) {
return replace(key, value, true);
}
+ /**
+ * Replace the given parameter with the value, optionally performing url encoding.
+ * @param key key to change
+ * @param value value to subsitutue
+ * @param encode whether or not to perform URL Encoding.
+ * @return the OperationaBuilder
+ */
public OperatorBuilder replace(String key, String value, boolean encode) {
- if(value == null) {
+ if (value == null) {
value = "";
}
if (encode) {
@@ -108,12 +123,20 @@ public OperatorBuilder replace(String key, String value, boolean encode) {
return this;
}
+ /**
+ * Set key for replacement.
+ * @param key search key for replacement
+ * @return OperatorBuilder
+ */
public OperatorBuilder withOperatorKey(String key) {
this.operatorKey = key;
return this;
}
-
+ /**
+ * Create the operation for usage.
+ * @return Operator that can be called
+ */
public UnaryOperator build() {
String result = template;
diff --git a/cwms-data-api/src/main/java/cwms/cda/helpers/ResourceHelper.java b/cwms-data-api/src/main/java/cwms/cda/helpers/ResourceHelper.java
index 3fa22f58a6..04f5f7ad9a 100644
--- a/cwms-data-api/src/main/java/cwms/cda/helpers/ResourceHelper.java
+++ b/cwms-data-api/src/main/java/cwms/cda/helpers/ResourceHelper.java
@@ -1,19 +1,21 @@
package cwms.cda.helpers;
+import com.google.common.flogger.FluentLogger;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import com.google.common.flogger.FluentLogger;
import java.util.stream.Collectors;
public final class ResourceHelper {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
+
/**
* Returns resource as a string, null if resource can't be found.
* @param resource The path to the resource
* @param context The class context to load the resource from
* @return The contents of the resource
+ *
* */
public static String getResourceAsString(String resource, Class> context) {
InputStream formatList = getResourceAsStream(resource, context);
@@ -25,7 +27,7 @@ public static String getResourceAsString(String resource, Class> context) {
return null;
}
- /**
+ /**
* Returns resource as a string, null if resource can't be found.
* @param resource The path to the resource
* @return The contents of the resource
diff --git a/cwms-data-api/src/main/java/cwms/cda/helpers/ZoneIdHelper.java b/cwms-data-api/src/main/java/cwms/cda/helpers/ZoneIdHelper.java
index 1f3e638e45..ffdf9c61b2 100644
--- a/cwms-data-api/src/main/java/cwms/cda/helpers/ZoneIdHelper.java
+++ b/cwms-data-api/src/main/java/cwms/cda/helpers/ZoneIdHelper.java
@@ -1,7 +1,6 @@
package cwms.cda.helpers;
import com.google.common.flogger.FluentLogger;
-import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
import java.time.DateTimeException;
@@ -11,8 +10,8 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
-
import javax.annotation.Nullable;
+import org.jetbrains.annotations.NotNull;
/**
* Helper class for handling timezone IDs and their aliases.
diff --git a/cwms-data-api/src/test/java/cwms/cda/formatters/ContentTypeTest.java b/cwms-data-api/src/test/java/cwms/cda/formatters/ContentTypeTest.java
index 136be708af..be52d36310 100644
--- a/cwms-data-api/src/test/java/cwms/cda/formatters/ContentTypeTest.java
+++ b/cwms-data-api/src/test/java/cwms/cda/formatters/ContentTypeTest.java
@@ -29,7 +29,7 @@ void test_ctor_empty() {
ContentType ct = new ContentType("");
Map parameters = ct.getParameters();
assertTrue(parameters == null || parameters.isEmpty());
- assertNull(ct.getCharset());
+ assertNull(ct.getInstanceCharset());
}
@Test
@@ -37,7 +37,7 @@ void test_ctor_garbage() {
ContentType ct = new ContentType("qawicxqyjx");
Map parameters = ct.getParameters();
assertTrue(parameters == null || parameters.isEmpty());
- assertNull(ct.getCharset());
+ assertNull(ct.getInstanceCharset());
}
@@ -47,7 +47,7 @@ void test_ctor_w_charset() {
assertEquals("application/json", ct.getType());
Map parameters = ct.getParameters();
assertTrue(parameters == null || parameters.isEmpty());
- assertEquals("UTF-8", ct.getCharset());
+ assertEquals("UTF-8", ct.getInstanceCharset());
}
@Test
@@ -57,7 +57,7 @@ void test_ctor_w_charset_space() {
Map parameters = ct.getParameters();
assertTrue(parameters == null || parameters.isEmpty());
- assertEquals("UTF-8", ct.getCharset());
+ assertEquals("UTF-8", ct.getInstanceCharset());
}