Skip to content

Commit

Permalink
Removing external dependencies on the ContentTypeAliasMap, and accept…
Browse files Browse the repository at this point in the history
…ing the class into Formats instead
  • Loading branch information
RyanM-RMA committed Jun 4, 2024
1 parent 2547b96 commit 2f77aa3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import cwms.cda.data.dao.CountyDao;
import cwms.cda.data.dto.County;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.ContentTypeAliasMap;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.FormattingException;
import io.javalin.apibuilder.CrudHandler;
Expand Down Expand Up @@ -93,7 +92,7 @@ public void getAll(@NotNull Context ctx) {
CountyDao dao = new CountyDao(dsl);
List<County> counties = dao.getCounties();
String formatHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeader(formatHeader, ContentTypeAliasMap.forDtoClass(County.class));
ContentType contentType = Formats.parseHeader(formatHeader, County.class);
if (contentType == null) {
throw new FormattingException("Format header could not be parsed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.HashMap;
import java.util.Map;

public final class ContentTypeAliasMap
final class ContentTypeAliasMap
{
private final Map<String, ContentType> _contentTypeMap = new HashMap<>();
private static final Map<Class<? extends CwmsDTOBase>, ContentTypeAliasMap> ALIAS_MAP = new HashMap<>();
Expand Down
15 changes: 9 additions & 6 deletions cwms-data-api/src/main/java/cwms/cda/formatters/Formats.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,26 @@ public static ContentType parseQueryParam(String queryParam) {


public static ContentType parseHeader(String header) {
return parseHeader(header, ContentTypeAliasMap.empty());
return parseHeader(header, null);
}
public static ContentType parseHeader(String header, ContentTypeAliasMap aliasMap) {

public static ContentType parseHeader(String header, Class<? extends CwmsDTOBase> klass) {
ArrayList<ContentType> contentTypes = new ArrayList<>();
ContentTypeAliasMap aliasMap = ContentTypeAliasMap.empty();
if (klass != null) {
aliasMap = ContentTypeAliasMap.forDtoClass(klass);
}

if (header != null && !header.isEmpty()) {
String[] all = header.split(",");
logger.log(Level.FINEST, "Finding handlers {0}", all.length);
for (String ct : all) {
ContentType aliasType = aliasMap.getContentType(ct);
if (aliasType != null)
{
if (aliasType != null) {
logger.finest(() -> ct + " converted to " + aliasType);
contentTypes.add(aliasType);
}
else
{
else {
logger.finest(ct);
contentTypes.add(new ContentType(ct));
}
Expand Down

0 comments on commit 2f77aa3

Please sign in to comment.