<commit_before>package audit1

import models._
import uk.gov.dvla.vehicles.presentation.common.model.AddressModel
import uk.gov.dvla.auditing.Message
import uk.gov.dvla.vehicles.presentation.common.model.VehicleAndKeeperDetailsModel

case class AuditMessage(override val name: String, override val serviceType: String, override val data: (String, Any)*)
  extends Message(name, serviceType, data :_*)


object KeeperNameOptString {

  def from(vehicleAndKeeperDetailsModel: VehicleAndKeeperDetailsModel) = {

    // flatten and then iterate
    val keeperNameList = List(vehicleAndKeeperDetailsModel.title,
      vehicleAndKeeperDetailsModel.firstName,
      vehicleAndKeeperDetailsModel.lastName).flatten

    if (keeperNameList.size > 0) {
      var nameString = keeperNameList(0)
      for (nameItem <- keeperNameList.drop(1)) {
        nameString += (" " + nameItem)
      }
      Some(nameString)
    } else {
      None
    }
  }
}

object KeeperAddressOptString {

  def from(addressModel: Option[AddressModel]) = {

    addressModel match {
      case Some(address) =>
        if (address.address.size > 0) {
          var addressString = address.address(0)
          for (addressLine <- address.address.drop(1)) {
            addressString += (", " + addressLine)
          }
          Some(addressString)
        } else {
          None
        }
      case _ =>
        None
    }
  }
}

object BusinessAddressOptString {

  def from(businessDetailsModel: BusinessDetailsModel) = {

    var addressString = businessDetailsModel.name

    if (businessDetailsModel.address.address.size > 0) {
      for (addressLine <- businessDetailsModel.address.address) {
        addressString += (", " + addressLine)
      }
    }
    Some(addressString)
  }
}

object BusinessDetailsModelOptSeq {

  def from(businessDetailsModel: Option[BusinessDetailsModel]) = {
    businessDetailsModel match {
      case Some(businessDetailsModel) => {
        val businessNameOpt = Some(("businessName", businessDetailsModel.contact))
        val businessAddressOpt = BusinessAddressOptString.from(businessDetailsModel).map(
          businessAddress => ("businessAddress", businessAddress))
        val businessEmailOpt = Some(("businessEmail", businessDetailsModel.email))
        Seq(businessNameOpt, businessAddressOpt, businessEmailOpt)
      }
      case _ => Seq.empty
    }
  }
}

object VehicleAndKeeperDetailsModelOptSeq {

  def from(vehicleAndKeeperDetailsModel: Option[VehicleAndKeeperDetailsModel]) = {
    vehicleAndKeeperDetailsModel match {
      case Some(vehicleAndKeeperDetailsModel) => {
        val currentVrmOpt = Some(("currentVrm", vehicleAndKeeperDetailsModel.registrationNumber))
        val makeOpt = vehicleAndKeeperDetailsModel.make.map(make => ("make", make))
        val modelOpt = vehicleAndKeeperDetailsModel.model.map(model => ("model", model))
        val keeperNameOpt = KeeperNameOptString.from(vehicleAndKeeperDetailsModel).map(
          keeperName => ("keeperName", keeperName))
        val keeperAddressOpt = KeeperAddressOptString.from(vehicleAndKeeperDetailsModel.address).map(
          keeperAddress => ("keeperAddress", keeperAddress))
        Seq(currentVrmOpt, makeOpt, modelOpt, keeperNameOpt, keeperAddressOpt)
      }
      case _ => Seq.empty
    }
  }
}

object CaptureCertificateDetailsFormModelOptSeq {

  def from(captureCertificateDetailsFormModel: Option[CaptureCertificateDetailsFormModel]) = {
    captureCertificateDetailsFormModel match {
      case Some(captureCertificateDetailsFormModel) => {
        val certificateDocumentCountOpt = Some(("certificateDocumentCount", captureCertificateDetailsFormModel.certificateDocumentCount))
        val certificateDateOpt = Some(("certificateDate", captureCertificateDetailsFormModel.certificateDate))
        val certificateTimeOpt = Some(("certificateTime", captureCertificateDetailsFormModel.certificateTime))
        val certificateRegistrationMarkOpt = Some(("certificateRegistrationMark", captureCertificateDetailsFormModel.certificateRegistrationMark))
        val prVrmOpt = Some(("prVrm", captureCertificateDetailsFormModel.prVrm))
        Seq(certificateDocumentCountOpt, certificateDateOpt, certificateTimeOpt, certificateRegistrationMarkOpt, prVrmOpt)
      }
      case _ => Seq.empty
    }
  }
}

object CaptureCertificateDetailsModelOptSeq {

  def from(captureCertificateDetailsModel: Option[CaptureCertificateDetailsModel]) = {
    captureCertificateDetailsModel match {
      case Some(captureCertificateDetailsModel) => {
        val certificateExpiryDateOpt = Some(("certificateExpiryDate", captureCertificateDetailsModel.certificateExpiryDate))
        val outstandingFeesOpt = Some(("outstandingFees", captureCertificateDetailsModel.outstandingFees))
        Seq(certificateExpiryDateOpt, outstandingFeesOpt)
      }
      case _ => Seq.empty
    }
  }
}

object PaymentModelOptSeq {

  def from(paymentModelOpt: Option[PaymentModel]) = {
    paymentModelOpt match {
      case Some(paymentModel) =>
        val paymentTrxRefOpt = paymentModel.trxRef.map(trxRef => ("paymentTrxRef", trxRef))
        val paymentStatusOpt = paymentModel.paymentStatus.map(paymentStatus => ("paymentStatus", paymentStatus))
        val paymentMaskedPanOpt = Some(("paymentMaskedPan", "****************")) //paymentModel.maskedPAN.map(maskedPan => ("paymentMaskedPan", maskedPan))<commit_msg>Fix: audit message certificateExpiryDate should not be added to the data if it is None<commit_after>package audit1

import models._
import uk.gov.dvla.vehicles.presentation.common.model.AddressModel
import uk.gov.dvla.auditing.Message
import uk.gov.dvla.vehicles.presentation.common.model.VehicleAndKeeperDetailsModel

case class AuditMessage(override val name: String, override val serviceType: String, override val data: (String, Any)*)
  extends Message(name, serviceType, data :_*)


object KeeperNameOptString {

  def from(vehicleAndKeeperDetailsModel: VehicleAndKeeperDetailsModel) = {

    // flatten and then iterate
    val keeperNameList = List(vehicleAndKeeperDetailsModel.title,
      vehicleAndKeeperDetailsModel.firstName,
      vehicleAndKeeperDetailsModel.lastName).flatten

    if (keeperNameList.size > 0) {
      var nameString = keeperNameList(0)
      for (nameItem <- keeperNameList.drop(1)) {
        nameString += (" " + nameItem)
      }
      Some(nameString)
    } else {
      None
    }
  }
}

object KeeperAddressOptString {

  def from(addressModel: Option[AddressModel]) = {

    addressModel match {
      case Some(address) =>
        if (address.address.size > 0) {
          var addressString = address.address(0)
          for (addressLine <- address.address.drop(1)) {
            addressString += (", " + addressLine)
          }
          Some(addressString)
        } else {
          None
        }
      case _ =>
        None
    }
  }
}

object BusinessAddressOptString {

  def from(businessDetailsModel: BusinessDetailsModel) = {

    var addressString = businessDetailsModel.name

    if (businessDetailsModel.address.address.size > 0) {
      for (addressLine <- businessDetailsModel.address.address) {
        addressString += (", " + addressLine)
      }
    }
    Some(addressString)
  }
}

object BusinessDetailsModelOptSeq {

  def from(businessDetailsModel: Option[BusinessDetailsModel]) = {
    businessDetailsModel match {
      case Some(businessDetailsModel) => {
        val businessNameOpt = Some(("businessName", businessDetailsModel.contact))
        val businessAddressOpt = BusinessAddressOptString.from(businessDetailsModel).map(
          businessAddress => ("businessAddress", businessAddress))
        val businessEmailOpt = Some(("businessEmail", businessDetailsModel.email))
        Seq(businessNameOpt, businessAddressOpt, businessEmailOpt)
      }
      case _ => Seq.empty
    }
  }
}

object VehicleAndKeeperDetailsModelOptSeq {

  def from(vehicleAndKeeperDetailsModel: Option[VehicleAndKeeperDetailsModel]) = {
    vehicleAndKeeperDetailsModel match {
      case Some(vehicleAndKeeperDetailsModel) => {
        val currentVrmOpt = Some(("currentVrm", vehicleAndKeeperDetailsModel.registrationNumber))
        val makeOpt = vehicleAndKeeperDetailsModel.make.map(make => ("make", make))
        val modelOpt = vehicleAndKeeperDetailsModel.model.map(model => ("model", model))
        val keeperNameOpt = KeeperNameOptString.from(vehicleAndKeeperDetailsModel).map(
          keeperName => ("keeperName", keeperName))
        val keeperAddressOpt = KeeperAddressOptString.from(vehicleAndKeeperDetailsModel.address).map(
          keeperAddress => ("keeperAddress", keeperAddress))
        Seq(currentVrmOpt, makeOpt, modelOpt, keeperNameOpt, keeperAddressOpt)
      }
      case _ => Seq.empty
    }
  }
}

object CaptureCertificateDetailsFormModelOptSeq {

  def from(captureCertificateDetailsFormModel: Option[CaptureCertificateDetailsFormModel]) = {
    captureCertificateDetailsFormModel match {
      case Some(captureCertificateDetailsFormModel) => {
        val certificateDocumentCountOpt = Some(("certificateDocumentCount", captureCertificateDetailsFormModel.certificateDocumentCount))
        val certificateDateOpt = Some(("certificateDate", captureCertificateDetailsFormModel.certificateDate))
        val certificateTimeOpt = Some(("certificateTime", captureCertificateDetailsFormModel.certificateTime))
        val certificateRegistrationMarkOpt = Some(("certificateRegistrationMark", captureCertificateDetailsFormModel.certificateRegistrationMark))
        val prVrmOpt = Some(("prVrm", captureCertificateDetailsFormModel.prVrm))
        Seq(certificateDocumentCountOpt, certificateDateOpt, certificateTimeOpt, certificateRegistrationMarkOpt, prVrmOpt)
      }
      case _ => Seq.empty
    }
  }
}

object CaptureCertificateDetailsModelOptSeq {

  def from(captureCertificateDetailsModel: Option[CaptureCertificateDetailsModel]) = {
    captureCertificateDetailsModel match {
      case Some(certificateDetailsModel) => {
        val certificateExpiryDateOpt = certificateDetailsModel.certificateExpiryDate.map(expiryDate => ("certificateExpiryDate", expiryDate))
        val outstandingFeesOpt = Some(("outstandingFees", certificateDetailsModel.outstandingFees))
        Seq(certificateExpiryDateOpt, outstandingFeesOpt)
      }
      case _ => Seq.empty
    }
  }
}

object PaymentModelOptSeq {

  def from(paymentModelOpt: Option[PaymentModel]) = {
    paymentModelOpt match {
      case Some(paymentModel) =>
        val paymentTrxRefOpt = paymentModel.trxRef.map(trxRef => ("paymentTrxRef", trxRef))
        val paymentStatusOpt = paymentModel.paymentStatus.map(paymentStatus => ("paymentStatus", paymentStatus))
        val paymentMaskedPanOpt = Some(("paymentMaskedPan", "****************")) //paymentModel.maskedPAN.map(maskedPan => ("paymentMaskedPan", maskedPan))
{'fraction_non_alphanumeric': 0.0943778801843318, 'fraction_numerical': 0.0014746543778801843, 'mean_word_length': 4.075304022450888, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '492862', 'n_tokens_mistral': 3006, 'n_tokens_neox': 2871, 'n_words': 516}