Search in sources :

Example 86 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.

the class LogAndSecurityFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String uri = ((HttpServletRequest) request).getRequestURI().toString();
    if (!uri.equals("/poc1")) {
        DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
        Page page = dataAccessor.getPage(uri);
        if (page != null) {
            if (page.getType() == PageType.BLOG_POST) {
                JsonObject jsonObject = new JsonObject();
                jsonObject.addProperty("pageId", page.getId());
                jsonObject.addProperty("accessToken", AccessTokenFilter.getAccessToken().getId());
                logger.log(Level.INFO, "DataFlow#PAGE_HIT::" + jsonObject.toString());
            }
        }
    }
    chain.doFilter(request, response);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) JsonObject(com.google.gson.JsonObject) Page(com.pratilipi.data.type.Page)

Example 87 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.

the class JsonWrapper method serialize.

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    for (String property : propertiesToInclude) {
        String value;
        try {
            value = (String) PropertyUtils.getSimpleProperty(target, property);
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (InvocationTargetException ite) {
            throw new RuntimeException(ite);
        } catch (NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        }
        serialized.addProperty(property, value);
    }
    return serialized;
}
Also used : JsonObject(com.google.gson.JsonObject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 88 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.

the class ArticleIngestionView method serialize.

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.addProperty("doi", ingestion.getArticle().getDoi());
    serialized.addProperty("ingestionNumber", ingestion.getIngestionNumber());
    serialized.add("journal", context.serialize(journal));
    serialized.addProperty("bucketName", bucketName);
    ArticleItem strikingImage = ingestion.getStrikingImage();
    if (strikingImage != null) {
        serialized.add("strikingImage", context.serialize(ItemSetView.getItemView(strikingImage)));
    }
    JsonAdapterUtil.copyWithoutOverwriting(context.serialize(metadata).getAsJsonObject(), serialized);
    JsonAdapterUtil.copyWithoutOverwriting(context.serialize(customMetadata).getAsJsonObject(), serialized);
    serialized.remove("assets");
    List<AssetMetadataView> assetViews = metadata.getAssets().stream().map(AssetMetadataView::new).collect(Collectors.toList());
    serialized.add("assetsLinkedFromManuscript", context.serialize(assetViews));
    return serialized;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) JsonObject(com.google.gson.JsonObject)

Example 89 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.

the class ArticleRevisionView method serialize.

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.addProperty("doi", article.getDoi());
    this.revision.ifPresent((ArticleRevision revision) -> {
        serialized.addProperty("revisionNumber", revision.getRevisionNumber());
        serialized.add("ingestion", serializeIngestion(context, revision.getIngestion()));
    });
    return serialized;
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) JsonObject(com.google.gson.JsonObject)

Example 90 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.

the class ArticleRevisionView method serializeIngestion.

// Could be extracted for more public use, in case we ever need this shallow ArticleIngestion view elsewhere.
private JsonObject serializeIngestion(JsonSerializationContext context, ArticleIngestion ingestion) {
    JsonObject serialized = new JsonObject();
    JournalOutputView journalOutputView = JournalOutputView.getView(ingestion.getJournal());
    serialized.add("journal", context.serialize(journalOutputView));
    serialized.addProperty("ingestionNumber", ingestion.getIngestionNumber());
    serialized.addProperty("title", ingestion.getTitle());
    serialized.addProperty("publicationDate", ingestion.getPublicationDate().toLocalDate().toString());
    if (ingestion.getRevisionDate() != null) {
        serialized.addProperty("revisionDate", ingestion.getRevisionDate().toLocalDate().toString());
    }
    serialized.addProperty("publicationStage", ingestion.getPublicationStage());
    serialized.addProperty("articleType", ingestion.getArticleType());
    return serialized;
}
Also used : JsonObject(com.google.gson.JsonObject) JournalOutputView(org.ambraproject.rhino.view.journal.JournalOutputView)

Aggregations

JsonObject (com.google.gson.JsonObject)5111 JsonArray (com.google.gson.JsonArray)1162 JsonElement (com.google.gson.JsonElement)1084 JsonParser (com.google.gson.JsonParser)710 Test (org.junit.Test)491 IOException (java.io.IOException)471 JsonPrimitive (com.google.gson.JsonPrimitive)387 ArrayList (java.util.ArrayList)376 Gson (com.google.gson.Gson)369 HashMap (java.util.HashMap)324 Map (java.util.Map)269 Test (org.testng.annotations.Test)208 Test (org.junit.jupiter.api.Test)201 File (java.io.File)146 List (java.util.List)142 InputStreamReader (java.io.InputStreamReader)135 JsonParseException (com.google.gson.JsonParseException)121 GsonBuilder (com.google.gson.GsonBuilder)93 JsonSyntaxException (com.google.gson.JsonSyntaxException)88 Nonnull (javax.annotation.Nonnull)87