.

Imprimir

Mapping

Abstract Delimited String To Entity Mapper

Definition

class DelimitedStrToEntityMapperComp[T](implicit tag:TypeTag[T]) extends ComponentContract {
  abstract class DelimitedStrToEntityMapper() extends Cell[Config] {
    ...
  }
}

Description

Component receiving String and applying a split operation to it. The resulting Array of Strings is then used to map an arbitrary entity using a mapping function passed in the configuration.

The Split functionality of this component only accepts a single separator character. The separator character can appear in the field strings if they are quoted. This splitter supports trimming blanks around the separators removing the quotes from quoted text.
Double quotes cannot be used as separator. The results are undefined if they are used in that manner.

Contract

def contract: Contract = contract(Receives[String], Sends[T])

Configuration

trait Config extends CellCfg {
  val separator : Char = ','              // The character to split the string by
  val trimSpace : Boolean = true          // Remove white space between separators and fields
  val unquote   : Boolean = false         // Remove quotes from quoted fields
  val skipEmpty : Boolean = true          // Skip empty lines
  val fieldMap  : Array[String] => T      // Mapping function associating fields to an arbitrary Entity of type T
}

Usage

See DelimitedStringToRecordComp for concrete usage of this abstract component.

Abstract Entity To Record Mapper

Definition

def contract: Contract = contract(Receives[T], Sends[Record])

Description

Component receiving an arbitrary type and converting it to a Record representation based on a configurable mapping function.

Contract

def contract: Contract = contract(Receives[T], Sends[Record])

Configuration

trait Config extends CellCfg {
  def map: T => Record    // Function to map from a particular type T to a Record representation
}

Abstract Record To Entity Mapper

Definition

abstract class RecordToEntityMapperComp[T: TypeTag] extends ComponentContract {
    abstract class RecordToEntityMapper extends Cell[Config] {
    ...
    }
}

Description

Component which receives Record and applies a mapping function to them in order to produce an arbitrary type T.

Contract

def contract: Contract = contract(Receives[Record], Sends[T])

Configuration

trait Config extends CellCfg {
  def map: Record => T  // Function applied to the Record to produce an instance of an arbitrary type T
}

Usage

The following is a concrete usage of this abstract component to map a Record representing a trade to a type ClientTrade. All what is required is to extend the component binding it to the type ClientTrade and provide a mapping function to map the fields to the parameter values within the ClientTrade constructor.

object ClientTradeEntityMapperComp extends RecordToEntityMapperComp[ClientTrade]{

  trait Config extends super.Config {
    override def map: Record => ClientTrade = record =>
      ClientTrade(Trade(record.findField[TradeId]("tradeId").get,
        record.findField[SecurityId]("security").get,
        record.findField[Identifier]("trader").get,
        record.findField[Identifier]("tradingBookId").get,
        record.findField[DeskId]("deskId").get,
        record.findField[RegionCode]("regionCodeUs").get,
        record.findField[RegionCode]("regionCodeThem").get,
        record.findField[SalesPersonId]("salesPerson").get,
        record.findField[BookId]("salesBookId").get,
        record.findField[CptyCode]("counterpartyCode").get,
        record.findField[CptyCode]("brokerCode").get,
        record.findField[ZonedDateTime]("tradeDate").get,
        record.findField[ZonedDateTime]("maturityDate").get,
        record.findField[ZonedDateTime]("settlementDate").get,
        record.findField[Identifier]("accountId").get,
        record.findField[BigDecimal]("quantity").get,
        record.findField[BuySellInd]("buySell").get,
        record.findField[BigDecimal]("price").get,
        record.findField[TradeStatus]("tradeStatus").get,
        record.findField[SettlementStatus]("settlementStatus").get,
        record.findField[Int]("version").get,
        record.findField[TaxCode]("tx1").get,
        record.findField[TaxCode]("tx2").get,
        record.findField[TaxCode]("tx3").get,
        record.findField[Option[TradeId]]("hedgeOpt").get,
        record.findField[Identifier]("origin").get,
        record.findField[Identifier]("secId").get,
        record.findField[Map[Identifier, Identifier]]("altIds").get))
  }

  case class ClientTradeEntityMapper() extends RecordToEntityMapper()
}

Delimited String To Record

Definition

This component is derived from the Abstract Delimited Str To EntityMapper Component and it just needs to bind the generic Entity type T to the concrete type Record. Here is the full definition of it:

object DelimitedStringToRecordComp extends DelimitedStrToEntityMapperComp[Record] {

  trait Config extends super.Config {
    override val fieldMap: Array[String] => Record
  }

  class DelimitedStringToRecord extends DelimitedStrToEntityMapper
}

Description
Concrete delimited string to entity implementation for generic Records

Contract

The contract is inherited from the parent component and it does not require re-definition. It will therefore Receive[String] and Send[Record]

Configuration

The configuration trait is also inherited from the parent. In the definition the config trait overrides fieldMap method just to make it more explicit.

Usage

Example of usage within a subsystem:

cell[DelimitedStringToRecord]("StringToRecord") {
  cellConfig := new DelimitedStringToRecordComp.Config {
    override val fieldMap: Array[String] => Record = fields => StatsRecordDef(fields: _*)
  }
}

Delimited String To Parts Count

Definition

class DelimitedStrToPartsCountComp() extends ComponentContract {
  abstract class DelimitedStrToPartsCount() extends Cell[Config] {
    ...
  }
}

Description

Component receiving String batches and applying a split operation to them. The resulting Array of Strings is then used to construct a key-count map of the parts.

The Split functionality of this component only accepts a single separator character which by default is a space.

This splitter supports trimming blanks around the separators.

Contract

def contract: Contract = contract(Receives[BatchOf[String]], Sends[Map[String, Long]])

Configuration

trait Config extends CellCfg {
  val separator : Char = ' '
  val trimSpace : Boolean = true
}
Table of Contents