Salat - Marshalling issue

21 views
Skip to first unread message

Sri Manga Maddi

unread,
Nov 22, 2016, 12:03:14 AM11/22/16
to scala-salat

Issue is, grater method for Salat convering SavingCost case class as key, value pair.

"SavingsCost(1370044800,1380499200,Summer,22.43,12.39,19.43,12.1)"
     start = 1370044800
     stop = 1380499200
     description = "Summer"
     baseLoad = {BigDecimal@20606} "22.43"
     baseMultiplier = {BigDecimal@20605} "12.39"
     actualLoad = {BigDecimal@20604} "19.43"
     actualMultiplier = {BigDecimal@19676} "12.1"
     baseTotal = {BigDecimal@21374} "277.9077"
     actualTotal = {BigDecimal@21375} "235.103"

In other case class ModulePeriod it converting as list.

"periods": [
        [1370044800, 1380499200, "Summer", "peak", [], null, null, null]
    ],

Only the big diffrent is SavingCost dont have any other case class fields or collections like ModulePeriod Have.

Update method in Repository class:

 def update(id: Id, partialEntity: PartialEntity): Unit = {
    println("Before update: ", partialEntity)
    val dbObject = grater[PartialEntity].asDBObject(partialEntity)
    println("DBObject update : ", dbObject)
    salatDao.update(idToDBObject(id), $set(dbObject.toSeq: _*), upsert = false)
  }

MainEntity:

case class AlertModule(
  @Key("_id") id: String,
  regionId: String,
  zoneId: String,
  organizationId: String,
  clientId: String,
  siteId: String,
  name: String,
  utilityContractId: String,
  version: Long = -1,
  meterId: Option[String] = None,
  smoothing: Option[Time] = None,
  dispatcher: Option[String] = None,
  description: Option[String] = None,
  alertRecipients: List[Email] = Nil,
  savingsCosts: List[SavingsCost] = Nil,
  periods: List[ModulePeriod] = Nil,
  exclusions: List[OnPeakExclusion] = Nil)
    extends UtilityDemandManagement
    with VersionIdentity {

============

final case class SavingsCost private (
    start: Long,
    stop: Long,
    description: String,
    baseLoad: BigDecimal,
    baseMultiplier: BigDecimal,
    actualLoad: BigDecimal,
    actualMultiplier: BigDecimal) {
  var baseTotal: BigDecimal = baseLoad * baseMultiplier
  var actualTotal: BigDecimal = actualLoad * actualMultiplier
}

======================

case class ModulePeriod private (
    start: Long,
    stop: Long,
    description: String,
    manageTo: String,
    onPeakRanges: List[OnPeakRange] = Nil,
    offPeakCurrentThreshold: Option[Int] = None,
    offPeakExpectedThreshold: Option[Int] = None,
    offPeakOriginalThreshold: Option[Int] = None) extends ModulePeriodT

======================

 case class OnPeakRange(
      startTime: Int,
      stopTime: Int,
      daysOfTheWeek: List[Int],
      currentThreshold: Int,
      expectedThreshold: Int,
      originalThreshold: Int) extends OnPeakRangeT with OnPeakRangeValidations {
    def startTimeOverlap = OnPeakRange.StartTimeOverlap.failure
    def stopTimeOverlap = OnPeakRange.StopTimeOverlap.failure
    def allHoursPeakNotFullDay = OnPeakRange.AllHoursPeakNotFullDay.failure
  }

==============================

While Debug SavingCost I collected AlertModule content:

partialEntity = {AlertModule@20661} "AlertModule(id,regionId,zoneId,orgId,clientId,siteId,nameChanged,utilityContractId,11,None,None,None,None,List(Email(swa...@aaa.com,Secondary)),List(SavingsCost(1370044800,1380499200,Summer,22.43,12.39,19.43,12.1)),List(),List())"
 id = "id"
 regionId = "regionId"
 zoneId = "zoneId"
 organizationId = "orgId"
 clientId = "clientId"
 siteId = "siteId"
 name = "nameChanged"
 utilityContractId = "utilityContractId"
 version = 11
 meterId = {None$@20675} "None"
 smoothing = {None$@20675} "None"
 dispatcher = {None$@20675} "None"
 description = {None$@20675} "None"
 alertRecipients = {$colon$colon@20676} "::" size = 1
 savingsCosts = {$colon$colon@21352} "::" size = 1
    0 = {SavingsCost@21372} "SavingsCost(1370044800,1380499200,Summer,22.43,12.39,19.43,12.1)"
     start = 1370044800
     stop = 1380499200
     description = "Summer"
     baseLoad = {BigDecimal@20606} "22.43"
     baseMultiplier = {BigDecimal@20605} "12.39"
     actualLoad = {BigDecimal@20604} "19.43"
     actualMultiplier = {BigDecimal@19676} "12.1"
     baseTotal = {BigDecimal@21374} "277.9077"
     actualTotal = {BigDecimal@21375} "235.103"
 periods = {Nil$@21353} "Nil$" size = 0
 exclusions = {Nil$@21353} "Nil$" size = 0
 program = "Alert UDM"
 totalBaseCost = {BigDecimal@21355} "277.9077"
 totalActualCost = {BigDecimal@21356} "235.103"
 totalEstimatedSavings = {BigDecimal@21357} "42.8047"
 programGroup = "Utility Demand Management"
 programCategory = "Demand Management"
 programType = "Energy Savings"

============================================================

{
    "id": "id",
    "regionId": "regionId",
    "zoneId": "zoneId",
    "organizationId": "orgId",
    "clientId": "clientId",
    "siteId": "siteId",
    "name": "nameChanged",
    "utilityContractId": "utilityContractId",
    "version": 11,
    "alertRecipients": [{
        "address": "swa...@aaa.com",
        "emailType": "Secondary"
    }],
    "savingsCosts": [{
        "start": 1370044800,
        "stop": 1380499200,
        "description": "Summer",
        "baseLoad": 22.43,
        "baseMultiplier": 12.39,
        "actualLoad": 19.43,
        "actualMultiplier": 12.1
    }],
    "periods": [],
    "exclusions": []
}

======================

While debug create ModulePeriod test case:

partialEntity = {AlertModule@25869} "AlertModule(id,regionId,zoneId,orgId,clientId,siteId,nameChanged,utilityContractId,11,None,None,None,None,List(Email(swa...@aaa.com,Secondary)),List(),List(ModulePeriod(1370044800,1380499200,Summer,peak,List(),None,None,None)),List())"
 id = "id"
 regionId = "regionId"
 zoneId = "zoneId"
 organizationId = "orgId"
 clientId = "clientId"
 siteId = "siteId"
 name = "nameChanged"
 utilityContractId = "utilityContractId"
 version = 11
 meterId = {None$@20675} "None"
 smoothing = {None$@20675} "None"
 dispatcher = {None$@20675} "None"
 description = {None$@20675} "None"
 alertRecipients = {$colon$colon@25884} "::" size = 1
 savingsCosts = {Nil$@21353} "Nil$" size = 0
 periods = {$colon$colon@25885} "::" size = 1
  0 = {package$ModulePeriod@25896} "ModulePeriod(1370044800,1380499200,Summer,peak,List(),None,None,None)"
   start = 1370044800
   stop = 1380499200
   description = "Summer"
   manageTo = "peak"
   onPeakRanges = {Nil$@21353} "Nil$" size = 0
   offPeakCurrentThreshold = {None$@20675} "None"
   offPeakExpectedThreshold = {None$@20675} "None"
   offPeakOriginalThreshold = {None$@20675} "None"
 exclusions = {Nil$@21353} "Nil$" size = 0
 program = "Alert UDM"
 totalBaseCost = {BigDecimal@25886} "0.0"
 totalActualCost = {BigDecimal@25887} "0.0"
 totalEstimatedSavings = {BigDecimal@25888} "0.0"
 programGroup = "Utility Demand Management"
 programCategory = "Demand Management"
 programType = "Energy Savings"

{
    "id": "id",
    "regionId": "regionId",
    "zoneId": "zoneId",
    "organizationId": "orgId",
    "clientId": "clientId",
    "siteId": "siteId",
    "name": "nameChanged",
    "utilityContractId": "utilityContractId",
    "version": 11,
    "alertRecipients": [{
        "address": "swa...@aaa.com",
        "emailType": "Secondary"
    }],
    "savingsCosts": [],
    "periods": [
        [1370044800, 1380499200, "Summer", "peak", [], null, null, null]
    ],
    "exclusions": []
}

Noah Zucker

unread,
Nov 22, 2016, 12:15:57 AM11/22/16
to scala-salat
Greetings - I'm afraid I don't quite understand the problem you're facing.

Could you please restate the question in 2 or 3 sentences, and call out the exact code / Salat API usage that you feel isn't behaving as you expect?

Thanks -
Reply all
Reply to author
Forward
0 new messages