def process()

in app/model/commands/DeleteAssetCommand.scala [22:53]


  def process(): T = {
    val atom = getPreviewAtom(atomId)
    val mediaAtom = MediaAtom.fromThrift(atom)

    val assetsToDelete: Option[Asset] = mediaAtom.assets.find(_.id == asset.id)

    val markers: LogstashMarker = Markers.appendEntries(Map(
      "userId" -> user.email,
      "atomId" -> atomId,
      "assetId" -> asset.id,
      "assetVersion" -> asset.version
    ).asJava)

    if (assetsToDelete.nonEmpty) {
      mediaAtom.activeVersion match {
        case Some(activeVersion) if assetsToDelete.get.version == activeVersion => {
          log.warn(markers, s"Cannot delete asset version ${asset.version} on atom $atomId because it is active")
          CannotDeleteActiveAsset
        }
        case _ =>
      }

      val updatedAtom = mediaAtom.copy(
        assets = mediaAtom.assets.filterNot(_.id == asset.id)
      )

      UpdateAtomCommand(atomId, updatedAtom, stores, user, awsConfig).process()
    } else {
      log.warn(markers, s"Asset version ${asset.version} does not exist on atom $atomId so cannot be deleted")
      AssetNotFound
    }
  }