Search in sources :

Example 1 with Publication

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Item(gov.usgs.cida.coastalhazards.model.Item) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) Publication(gov.usgs.cida.coastalhazards.model.summary.Publication) Full(gov.usgs.cida.coastalhazards.model.summary.Full)

Example 2 with Publication

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;
}
Also used : PublicationType(gov.usgs.cida.coastalhazards.model.summary.Publication.PublicationType) JsonObject(com.google.gson.JsonObject) Publication(gov.usgs.cida.coastalhazards.model.summary.Publication) Full(gov.usgs.cida.coastalhazards.model.summary.Full) LinkedList(java.util.LinkedList) JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 3 with Publication

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;
}
Also used : PublicationType(gov.usgs.cida.coastalhazards.model.summary.Publication.PublicationType) JsonObject(com.google.gson.JsonObject) Publication(gov.usgs.cida.coastalhazards.model.summary.Publication)

Aggregations

Publication (gov.usgs.cida.coastalhazards.model.summary.Publication)3 JsonObject (com.google.gson.JsonObject)2 Full (gov.usgs.cida.coastalhazards.model.summary.Full)2 PublicationType (gov.usgs.cida.coastalhazards.model.summary.Publication.PublicationType)2 JsonArray (com.google.gson.JsonArray)1 Item (gov.usgs.cida.coastalhazards.model.Item)1 Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1