Skip to content

Commit

Permalink
expose file tags via native API #3067
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jan 3, 2017
1 parent 52e9ec3 commit b69a051
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,13 @@ public static JsonObjectBuilder json(DatasetFieldType fld) {

public static JsonObjectBuilder json(FileMetadata fmd) {
return jsonObjectBuilder()
// deprecated: .add("category", fmd.getCategory())
// TODO: uh, figure out what to do here... it's deprecated
// in a sense that there's no longer the category field in the
// fileMetadata object; but there are now multiple, oneToMany file
// categories - and we probably need to export them too!) -- L.A. 4.5
.add("description", fmd.getDescription())
.add("label", fmd.getLabel()) // "label" is the filename
.add("directoryLabel", fmd.getDirectoryLabel())
.add("version", fmd.getVersion())
.add("datasetVersionId", fmd.getDatasetVersion().getId())
// We should probably export tags too.
.add("tags", getFileTags(fmd))
.add("dataFile", json(fmd.getDataFile(), fmd));
}

Expand All @@ -503,7 +500,7 @@ public static JsonObjectBuilder json(DataFile df, FileMetadata fileMetadata) {
// version *you want*! (L.A.)
fileName = df.getFileMetadata().getLabel();
}

df.getFileMetadata().getCategoriesByName();
return jsonObjectBuilder()
.add("id", df.getId())
.add("filename", fileName)
Expand All @@ -525,6 +522,17 @@ public static String format(Date d) {
return (d == null) ? null : Util.getDateTimeFormat().format(d);
}

private static JsonArrayBuilder getFileTags(FileMetadata fmd) {
if (fmd == null) {
return null;
}
JsonArrayBuilder tags = Json.createArrayBuilder();
for (String tag : fmd.getCategoriesByName()) {
tags.add(tag);
}
return tags;
}

private static class DatasetFieldsToJson implements DatasetFieldWalker.Listener {

Deque<JsonObjectBuilder> objectStack = new LinkedList<>();
Expand Down

0 comments on commit b69a051

Please sign in to comment.