use of gov.usgs.cida.coastalhazards.model.summary.Publication in project coastal-hazards by USGS-CIDA.
the class TemplateResource method gatherTemplateSummary.
protected Summary gatherTemplateSummary(Summary previousSummary, List<Item> children) {
Summary newSummary = Summary.copyValues(previousSummary, null);
String keywords = previousSummary.getKeywords();
Set<String> keywordSet = keywordsFromString(keywords);
Set<Publication> publicationSet = new LinkedHashSet<>();
Full full = previousSummary.getFull();
List<Publication> publications = full.getPublications();
publicationSet.addAll(publications);
if (children != null) {
for (Item item : children) {
Set<String> childKeywords = keywordsFromString(item.getSummary().getKeywords());
keywordSet.addAll(childKeywords);
List<Publication> childPubs = item.getSummary().getFull().getPublications();
for (Publication pub : childPubs) {
publicationSet.add(Publication.copyValues(pub, null));
}
}
}
String newKeywords = StringUtils.join(keywordSet, "|");
newSummary.setKeywords(newKeywords);
newSummary.getFull().setPublications(Lists.newArrayList(publicationSet));
return newSummary;
}
use of gov.usgs.cida.coastalhazards.model.summary.Publication in project coastal-hazards by USGS-CIDA.
the class FullSummaryAdapter method deserialize.
@Override
public Full deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Full result = new Full();
if (json instanceof JsonObject) {
JsonObject fullJson = (JsonObject) json;
result.setTitle(fullJson.getAsJsonPrimitive("title").getAsString());
result.setText(fullJson.getAsJsonPrimitive("text").getAsString());
List<Publication> fullPubList = new LinkedList<>();
JsonObject publications = fullJson.getAsJsonObject("publications");
for (PublicationType type : PublicationType.values()) {
JsonArray typedArray = publications.getAsJsonArray(type.name());
if (typedArray != null) {
List<Map<String, Object>> typeList = context.deserialize(typedArray, ArrayList.class);
for (Map<String, Object> pubMap : typeList) {
if (!pubMap.containsKey(Publication.TITLE) || !pubMap.containsKey(Publication.LINK)) {
throw new IllegalStateException("Expected publication, was not a publication");
}
Publication pub = new Publication();
pub.setTitle((String) pubMap.get(Publication.TITLE));
pub.setLink((String) pubMap.get(Publication.LINK));
pub.setType(type);
fullPubList.add(pub);
}
}
}
result.setPublications(fullPubList);
}
return result;
}
use of gov.usgs.cida.coastalhazards.model.summary.Publication in project coastal-hazards by USGS-CIDA.
the class FullSummaryAdapter method serialize.
@Override
public JsonElement serialize(Full src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject fullSummary = new JsonObject();
fullSummary.add("title", context.serialize(src.getTitle()));
fullSummary.add("text", context.serialize(src.getText()));
JsonObject publications = new JsonObject();
for (PublicationType type : PublicationType.values()) {
List<Publication> typedPubs = Publication.getTypedPublications(src.getPublications(), type);
publications.add(type.name(), context.serialize(typedPubs));
}
fullSummary.add("publications", publications);
return fullSummary;
}
Aggregations