FileParsingSignals.scala 2.09 KB
Newer Older
1
2
3
4
package eu.nomad_lab.integrated_pipeline.messages

import java.nio.file.Path

5
import eu.nomad_lab.integrated_pipeline.FileTree
6
import eu.nomad_lab.parsers.ParseResult.ParseResult
7
import eu.nomad_lab.parsers.{ FinishedParsingSession, ParseEvent, StartedParsingSession }
8
import eu.nomad_lab.{ CompactSha, TreeType }
9

10
sealed trait TreeScanSignal {
11
  val fileTree: FileTree
12
13
}

14
sealed trait FileParsingSignal {
15
  val fileTree: FileTree
16
17
}

18
/**
19
 * An candidate calculation which should be analyzed in detail by the given parser.
20
 * @param fileTree the file-tree scan request from which this parsing task was generated
21
22
 * @param relativePath path inside the given file tree
 * @param parserName name of the parser to use for processing the file
23
24
 * @param extractedPath the path to the temporarily extracted main file (if originating from an
 *                      archive)
25
 */
26
case class CandidateFound(
27
    fileTree: FileTree,
28
    relativePath: Path,
29
30
    parserName: String,
    extractedPath: Option[Path] = None
31
) extends TreeScanSignal {
32

33
  def mainFileUri: String = {
34
    fileTree.treeType match {
35
      case TreeType.Zip => "nmd://" + relativePath.toString
36
      case TreeType.Directory => fileTree.treeBasePath.resolve(relativePath).toAbsolutePath.toUri.toString
37
      case _ => "unknown://${treeTask.treeBasePath.resolve(relativePath).toAbsolutePath.toString}"
38
39
    }
  }
40
41
42
43
44
45
46

  def calculationGid: String = {
    val checksum = CompactSha()
    checksum.updateStr(mainFileUri)
    checksum.gidStr("C")
  }

47
}
48

49
case class TreeScanCompleted(
50
  fileTree: FileTree,
51
  numParsingTasks: Long = 0
52
) extends TreeScanSignal with FileParsingSignal
53

54
sealed trait FileParsingResult extends FileParsingSignal {
55
  val result: ParseResult
56
  val task: CandidateFound
57
58
  val start: Option[StartedParsingSession]
  val end: Option[FinishedParsingSession]
59
  val error: Option[String]
60

61
  val fileTree: FileTree = task.fileTree
62
63
}

64
65
case class ParsingResultInMemory(
  task: CandidateFound,
66
67
68
  result: ParseResult,
  start: Option[StartedParsingSession],
  events: Seq[ParseEvent],
69
70
  end: Option[FinishedParsingSession],
  error: Option[String]
71
) extends FileParsingResult