in lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Estimation.scala [57:94]
def subscriptionToSubscriptionData2024(subscription: ZuoraSubscription): Either[String, SubscriptionData2024] = {
val productName = subscriptionToMigrationProductName(subscription).toOption.get
val ratePlans = {
subscription.ratePlans
.filter(ratePlan => ratePlan.productName == productName)
.filter(ratePlanLastChangeTypeIsNoneOrAdd)
.distinct
}
ratePlans match {
case Nil =>
Left(
s"[error 93a21a48] Subscription ${subscription.subscriptionNumber} was found to have zero RatePlans making determination of rate plan name impossible"
)
case ratePlan :: Nil => {
(for {
billingPeriod <- ZuoraRatePlan.ratePlanToBillingPeriod(ratePlan)
currency <- ZuoraRatePlan.ratePlanToCurrency(ratePlan)
currentPrice = ratePlan.ratePlanCharges.foldLeft(BigDecimal(0))(
(price: BigDecimal, ratePlanCharge: ZuoraRatePlanCharge) =>
price + ratePlanCharge.price.getOrElse(BigDecimal(0))
)
targetRatePlanId <- StaticData.ratePlanIdLookUp(productName, ratePlan.ratePlanName)
} yield SubscriptionData2024(
productName = productName,
ratePlan = ratePlan,
ratePlanName = ratePlan.ratePlanName,
billingPeriod = billingPeriod,
currency = currency,
currentPrice = currentPrice,
targetRatePlanId = targetRatePlanId
)).toRight(s"[error: 0e218c37] Could not determine SubscriptionData2024 for subscription ${subscription}")
}
case _ =>
Left(
s"[error 93a21a48] Subscription ${subscription.subscriptionNumber} was found to have more than one RatePlans making determination of rate plan name impossible"
)
}
}