<commit_before>package org.broadinstitute.clio.client.dispatch

import akka.NotUsed
import akka.stream.scaladsl.Source
import org.broadinstitute.clio.client.commands.DeliverCommand
import org.broadinstitute.clio.client.dispatch.MoveExecutor.IoOp
import org.broadinstitute.clio.client.util.IoUtil
import org.broadinstitute.clio.client.webclient.ClioWebClient
import org.broadinstitute.clio.transfer.model.DeliverableIndex

import scala.collection.immutable
import scala.concurrent.ExecutionContext

/**
  * Executor for "deliver" commands, which are a specialized form of "move" commands.
  *
  * Delivery executors can extend this class to add custom IO operations which
  * should be performed when moving files into a FireCloud workspace.
  */
class DeliverExecutor[CI <: DeliverableIndex](
  protected val deliverCommand: DeliverCommand[CI]
)(
  implicit ec: ExecutionContext
) extends MoveExecutor(deliverCommand) {

  override def checkPreconditions(
    ioUtil: IoUtil,
    webClient: ClioWebClient
  ): Source[moveCommand.index.MetadataType, NotUsed] = {
    val baseStream = super.checkPreconditions(ioUtil, webClient)
    val newWorkspace = deliverCommand.workspaceName

    baseStream.flatMapConcat { metadata =>
      metadata.workspaceName
        .filterNot(n => deliverCommand.force || n == newWorkspace)
        .fold(Source.single(metadata)) { existingWorkspace =>
          Source.failed(<commit_msg>Deliver when workspaceName in Arrays metadata is empty. (#304)<commit_after>package org.broadinstitute.clio.client.dispatch

import akka.NotUsed
import akka.stream.scaladsl.Source
import org.broadinstitute.clio.client.commands.DeliverCommand
import org.broadinstitute.clio.client.dispatch.MoveExecutor.IoOp
import org.broadinstitute.clio.client.util.IoUtil
import org.broadinstitute.clio.client.webclient.ClioWebClient
import org.broadinstitute.clio.transfer.model.DeliverableIndex

import scala.collection.immutable
import scala.concurrent.ExecutionContext

/**
  * Executor for "deliver" commands, which are a specialized form of "move" commands.
  *
  * Delivery executors can extend this class to add custom IO operations which
  * should be performed when moving files into a FireCloud workspace.
  */
class DeliverExecutor[CI <: DeliverableIndex](
  protected val deliverCommand: DeliverCommand[CI]
)(
  implicit ec: ExecutionContext
) extends MoveExecutor(deliverCommand) {

  override def checkPreconditions(
    ioUtil: IoUtil,
    webClient: ClioWebClient
  ): Source[moveCommand.index.MetadataType, NotUsed] = {
    val baseStream = super.checkPreconditions(ioUtil, webClient)
    val newWorkspace = deliverCommand.workspaceName

    baseStream.flatMapConcat { metadata =>
      metadata.workspaceName
        .filterNot(n => deliverCommand.force || n.isEmpty || n == newWorkspace)
        .fold(Source.single(metadata)) { existingWorkspace =>
          Source.failed(
{'fraction_non_alphanumeric': 0.08390883977900553, 'fraction_numerical': 0.0010359116022099447, 'mean_word_length': 4.852525252525252, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6545475', 'n_tokens_mistral': 818, 'n_tokens_neox': 818, 'n_words': 192}