• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ObjectNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.fasterxml.jackson.databind.node.ObjectNode的典型用法代码示例。如果您正苦于以下问题:Scala ObjectNode类的具体用法?Scala ObjectNode怎么用?Scala ObjectNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ObjectNode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: SmsProviderResponseFormatter

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.busybees.streams.flows.transformers

import akka.http.scaladsl.model.{ContentTypes, HttpResponse}
import akka.stream.Materializer
import com.fasterxml.jackson.databind.node.ObjectNode
import com.flipkart.connekt.busybees.models.{SmsRequestTracker, SmsResponse}
import com.flipkart.connekt.busybees.streams.flows.MapAsyncFlowStage
import com.flipkart.connekt.commons.core.Wrappers._
import com.flipkart.connekt.commons.factories.ServiceFactory
import com.flipkart.connekt.commons.metrics.Instrumented
import com.flipkart.connekt.commons.utils.StringUtils._

import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try


class SmsProviderResponseFormatter(parallelism: Int)(implicit m: Materializer, ec: ExecutionContext) extends MapAsyncFlowStage[(Try[HttpResponse], SmsRequestTracker), (Try[SmsResponse], SmsRequestTracker)](parallelism) with Instrumented {

  lazy implicit val stencilService = ServiceFactory.getStencilService

  override val map: ((Try[HttpResponse], SmsRequestTracker)) => Future[List[(Try[SmsResponse], SmsRequestTracker)]] = responseTrackerPair => Future(profile("map") {

    val providerResponseHandlerStencil = stencilService.getStencilsByName(s"ckt-sms-${responseTrackerPair._2.provider}").find(_.component.equalsIgnoreCase("parse")).get

    val smsResponse = responseTrackerPair._1.flatMap(hR => Try_ {

      val stringBody = hR.entity.getString
      val body = if (hR.entity.contentType == ContentTypes.`application/json`) {
        stringBody.getObj[ObjectNode]
      } else {
        stringBody
      }

      val result = stencilService.materialize(providerResponseHandlerStencil, Map("statusCode" -> hR._1.intValue(),
        "tracker" -> responseTrackerPair._2,
        "body" -> body).getJsonNode).asInstanceOf[SmsResponse]
      assert(result != null, "Provider Parser Failed, NULL Returned")
      result
    })

    List(smsResponse -> responseTrackerPair._2)
  })(m.executionContext)

} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:45,代码来源:SmsProviderResponseFormatter.scala


示例2: AndroidChannelFormatter

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.busybees.streams.flows.formaters

import com.fasterxml.jackson.databind.node.ObjectNode
import com.flipkart.connekt.busybees.streams.errors.ConnektPNStageException
import com.flipkart.connekt.busybees.streams.flows.NIOFlow
import com.flipkart.connekt.commons.entities.MobilePlatform
import com.flipkart.connekt.commons.factories.{ConnektLogger, LogFile, ServiceFactory}
import com.flipkart.connekt.commons.helpers.CallbackRecorder._
import com.flipkart.connekt.commons.helpers.ConnektRequestHelper._
import com.flipkart.connekt.commons.iomodels.MessageStatus.InternalStatus
import com.flipkart.connekt.commons.iomodels._
import com.flipkart.connekt.commons.services.DeviceDetailsService
import com.flipkart.connekt.commons.utils.StringUtils._

import scala.concurrent.ExecutionContextExecutor
import scala.concurrent.duration._

class AndroidChannelFormatter(parallelism: Int)(implicit ec: ExecutionContextExecutor) extends NIOFlow[ConnektRequest, GCMPayloadEnvelope](parallelism)(ec) {

  lazy val stencilService = ServiceFactory.getStencilService

  override def map: ConnektRequest => List[GCMPayloadEnvelope] = message => {

    try {
      ConnektLogger(LogFile.PROCESSORS).info(s"AndroidChannelFormatter received message: ${message.id}")
      ConnektLogger(LogFile.PROCESSORS).trace(s"AndroidChannelFormatter received message: ${message.toString}")

      val pnInfo = message.channelInfo.asInstanceOf[PNRequestInfo]

      val devicesInfo = DeviceDetailsService.get(pnInfo.appName, pnInfo.deviceIds).get.toSeq
      val validDeviceIds = devicesInfo.map(_.deviceId)
      val invalidDeviceIds = pnInfo.deviceIds.diff(validDeviceIds.toSet)

      invalidDeviceIds.map(PNCallbackEvent(message.id, message.clientId, _, InternalStatus.MissingDeviceInfo, MobilePlatform.ANDROID, pnInfo.appName, message.contextId.orEmpty)).persist
      ServiceFactory.getReportingService.recordPushStatsDelta(message.clientId, message.contextId, message.meta.get("stencilId").map(_.toString), Option(message.platform), message.appName, InternalStatus.MissingDeviceInfo, invalidDeviceIds.size)

      val tokens = devicesInfo.map(_.token)
      val androidStencil = stencilService.getStencilsByName(s"ckt-${pnInfo.appName.toLowerCase}-android").head
      val appDataWithId = stencilService.materialize(androidStencil, message.channelData.asInstanceOf[PNRequestData].data).asInstanceOf[String].getObj[ObjectNode]
        .put("messageId", message.id)
        .put("contextId", message.contextId.orEmpty)

      val ttl = message.expiryTs.map(expiry => (expiry - System.currentTimeMillis) / 1000).getOrElse(6.hour.toSeconds)

      if (tokens.nonEmpty && ttl > 0) {
        val payload = GCMPNPayload(registration_ids = tokens, delay_while_idle = Option(pnInfo.delayWhileIdle), appDataWithId, time_to_live = Some(ttl), dry_run = Option(message.isTestRequest))
        List(GCMPayloadEnvelope(message.id, message.clientId, validDeviceIds, pnInfo.appName, message.contextId.orEmpty, payload, message.meta))
      } else if (tokens.nonEmpty) {
        ConnektLogger(LogFile.PROCESSORS).warn(s"AndroidChannelFormatter dropping ttl-expired message: ${message.id}")
        devicesInfo.map(d => PNCallbackEvent(message.id, message.clientId, d.deviceId, InternalStatus.TTLExpired, MobilePlatform.ANDROID, d.appName, message.contextId.orEmpty)).persist
        ServiceFactory.getReportingService.recordPushStatsDelta(message.clientId, message.contextId, message.meta.get("stencilId").map(_.toString), Option(message.platform), message.appName, InternalStatus.TTLExpired, devicesInfo.size)
        List.empty[GCMPayloadEnvelope]
      } else
        List.empty[GCMPayloadEnvelope]
    } catch {
      case e: Exception =>
        ConnektLogger(LogFile.PROCESSORS).error(s"AndroidChannelFormatter error for ${message.id}", e)
        throw new ConnektPNStageException(message.id, message.clientId, message.destinations, InternalStatus.StageError, message.appName, message.platform, message.contextId.orEmpty, message.meta, "AndroidChannelFormatter::".concat(e.getMessage), e)
    }
  }
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:62,代码来源:AndroidChannelFormatter.scala


示例3: VelocityFabric

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.entities.fabric

import java.io.StringWriter

import com.fasterxml.jackson.databind.node.ObjectNode
import com.flipkart.connekt.commons.factories.{ConnektLogger, LogFile}
import com.flipkart.connekt.commons.utils.VelocityUtils
import org.apache.velocity.app.Velocity
import org.apache.velocity.context.Context

import scala.util.{Failure, Success, Try}

class VelocityFabric(dataVtl: String) extends EngineFabric {
  
  def fabricate(id: String, context: Context, vtlFabric: String, errorTag: String): Try[String] = {
    try {
      val w = new StringWriter()
      Velocity.evaluate(context, w, errorTag, vtlFabric)
      Success(w.toString)
    } catch {
      case e: Exception =>
        ConnektLogger(LogFile.PROCESSORS).error(s"Velocity fabricate failed for [$id}], ${e.getMessage}", e)
        Failure(new Throwable(s"Velocity fabricate failed for [$id}] error: ${e.getMessage}"))
    }
  }

  def fabricate(id: String, context: ObjectNode, vtlFabric: String, errorTag: String): Try[String] = {
    fabricate(id, VelocityUtils.convertToVelocityContext(context), vtlFabric, errorTag)
  }

  def validateVtl(): Try[Boolean] = Try.apply(true)

  def compute(id: String, context: ObjectNode): AnyRef = {
    fabricate(id, context, dataVtl, s"_$id _").get
  }
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:37,代码来源:VelocityFabric.scala


示例4: ConnektRequest

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.iomodels

import com.fasterxml.jackson.annotation.{JsonIgnore, JsonProperty}
import com.fasterxml.jackson.databind.node.ObjectNode
import com.flipkart.connekt.commons.entities.Channel
import com.flipkart.connekt.commons.services.TStencilService
import com.flipkart.connekt.commons.utils.StringUtils._

case class ConnektRequest(@JsonProperty(required = false) id: String,
                          @JsonProperty(required = false) clientId: String,
                          contextId: Option[String],
                          channel: String,
                          @JsonProperty(required = true) sla: String,
                          stencilId: Option[String],
                          scheduleTs: Option[Long],
                          expiryTs: Option[Long],
                          @JsonProperty(required = true) channelInfo: ChannelRequestInfo,
                          @JsonProperty(required = false) channelData: ChannelRequestData,
                          @JsonProperty(required = false) channelDataModel: ObjectNode = getObjectNode,
                          meta: Map[String, String]) {

  def this(id: String, clientId: String, contextId: Option[String], channel: String, sla: String, stencilId: Option[String],
           scheduleTs: Option[Long], expiryTs: Option[Long], channelInfo: ChannelRequestInfo,
           channelData: ChannelRequestData, channelDataModel: ObjectNode) {
    this(id, clientId, contextId, channel, sla, stencilId, scheduleTs, expiryTs, channelInfo, channelData, channelDataModel, Map.empty[String, String])
  }

  def validate(implicit stencilService: TStencilService) = {
    require(stencilId.map(stencilService.get(_).nonEmpty).getOrElse(Option(channelData).isDefined), "given stencil Id doesn't exist")
    require(contextId.forall(_.hasOnlyAllowedChars), "`contextId` field can only contain [A-Za-z0-9_.-:|] allowed chars.")
    require(sla.isDefined, "`sla` field can cannot be null or empty.")
    require(meta != null, "`meta` field cannot be null. It is optional but non-null")
    require(channelInfo != null, "`channelInfo` field cannot be null.")
    require(contextId.forall(_.length <= 20), "`contextId` can be max 20 characters")
  }

  @JsonIgnore
  def isTestRequest : Boolean = meta.get("x-perf-test").exists(v => v.trim.equalsIgnoreCase("true"))

  def getComputedChannelData(implicit stencilService: TStencilService): ChannelRequestData =
    stencilId.map(stencilService.get(_)).map { stencil =>
      Channel.withName(channel) match {
        case Channel.PUSH =>
          val pushType = if (channelData != null) channelData.asInstanceOf[PNRequestData].pushType else null
          PNRequestData(pushType = pushType, data = stencilService.materialize(stencil.head, channelDataModel).asInstanceOf[String].getObj[ObjectNode])
        case Channel.SMS =>
          SmsRequestData(body = stencilService.materialize(stencil.head, channelDataModel).asInstanceOf[String])
        case Channel.EMAIL =>
          val subject = stencilService.materialize(stencil.filter(_.component.equalsIgnoreCase("subject")).head, channelDataModel).asInstanceOf[String]
          val html = stencilService.materialize(stencil.filter(_.component.equalsIgnoreCase("html")).head, channelDataModel).asInstanceOf[String]
          val txt = stencilService.materialize(stencil.filter(_.component.equalsIgnoreCase("text")).head, channelDataModel).asInstanceOf[String]
          EmailRequestData(subject = subject, html = html, text = txt, attachments = Option(channelData).map(_.asInstanceOf[EmailRequestData].attachments).orNull)
        case unsupportedChannel =>
          throw new Exception(s"`channelData` compute undefined for $unsupportedChannel")
      }
    }.getOrElse(channelData)
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:58,代码来源:ConnektRequest.scala


示例5: Histogram

//设置package包名称以及导入依赖的类
package models.charts

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.{ArrayNode, ObjectNode}


case class Histogram(titleAndAxesLabels: TitleAndAxesLabels, data: Seq[LabelAndDataValue]) extends Chart {

  def toJson(): String = {
    val mapper: ObjectMapper = new ObjectMapper()
    val retNode: ObjectNode = mapper.createObjectNode()
    val titleAndAxesLabelsNode: ObjectNode = mapper.createObjectNode()
    titleAndAxesLabelsNode.put("title", titleAndAxesLabels.title)
    titleAndAxesLabelsNode.put("x", titleAndAxesLabels.x)
    titleAndAxesLabelsNode.put("y", titleAndAxesLabels.y)

    val dataArrayNode: ArrayNode = mapper.createArrayNode()
    data.foreach(labelAndDataValue => {
      val dataPointNode: ObjectNode = mapper.createObjectNode()
      dataPointNode.put("label", labelAndDataValue.label)
      dataPointNode.put("value", labelAndDataValue.value)
      dataArrayNode.add(dataPointNode)
    })
    retNode.set("titlesAndAxesLabels", titleAndAxesLabelsNode)
    retNode.set("labelsAndDataValues", dataArrayNode)
    retNode.toString
  }
} 
开发者ID:Aams1000,项目名称:SafetyFirstFinances,代码行数:29,代码来源:Histogram.scala


示例6: AuthenticationViews

//设置package包名称以及导入依赖的类
package controllers

import javax.inject._

import auth.models._
import auth.scala._
import com.fasterxml.jackson.databind.node.ObjectNode
import play.api._
import play.api.cache.CacheApi
import play.api.mvc._

class AuthenticationViews @Inject()(cacheApi: CacheApi, configuration: Configuration) extends Controller with AuthenticatedActionBuilder {
  def cache = cacheApi
  def config = configuration

  def index = AuthenticatedAction(auth.AuthenticationType.None) { request =>
    val response = new BasicAuthViewResponse("Authentication", request.user)
    val viewData: ObjectNode = play.libs.Json.newObject()
    Ok(views.html.index.render(viewData, response))
  }

  def groups = AuthenticatedAction(auth.AuthenticationType.None) { request =>
    val response = new BasicAuthViewResponse("Authentication", request.user)
    val viewData: ObjectNode = play.libs.Json.newObject()
    Ok(views.html.groups.render(viewData, response))
  }

  def permissions = AuthenticatedAction(auth.AuthenticationType.None) { request =>
    val response = new BasicAuthViewResponse("Authentication", request.user)
    val viewData: ObjectNode = play.libs.Json.newObject()
    Ok(views.html.permissions.render(viewData, response))
  }

  def users = AuthenticatedAction(auth.AuthenticationType.None) { request =>
    val response = new BasicAuthViewResponse("Authentication", request.user)
    val viewData: ObjectNode = play.libs.Json.newObject()
    Ok(views.html.users.render(viewData, response))
  }
} 
开发者ID:RichyHBM,项目名称:Dux,代码行数:40,代码来源:AuthenticationViews.scala


示例7: JsonRow

//设置package包名称以及导入依赖的类
package io.eels.util

import com.fasterxml.jackson.databind.node.ObjectNode
import io.eels.Row

object JsonRow {
  def apply(row: Row): ObjectNode = {
    val node = JacksonSupport.mapper.createObjectNode()
    row.map.foreach {
      case (name, str: String) => node.put(name, str)
      case (name, long: Long) => node.put(name, long)
      case (name, int: Integer) => node.put(name, int)
      case (name, bool: Boolean) => node.put(name, bool)
      case (name, double: Double) => node.put(name, double)
      case (name, float: Float) => node.put(name, float)
      case (name, str) => node.put(name, str.toString)
    }
    node
  }
} 
开发者ID:51zero,项目名称:eel-sdk,代码行数:21,代码来源:JsonRow.scala



注:本文中的com.fasterxml.jackson.databind.node.ObjectNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala MongoClient类代码示例发布时间:2022-05-23
下一篇:
Scala ConnectionFactory类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap