Skip to content

Commit

Permalink
#1670 Refactor tagSrv.getOrCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 1, 2021
1 parent e2ff0ce commit 3235aaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
19 changes: 6 additions & 13 deletions thehive/app/org/thp/thehive/services/TagSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,16 @@ class TagSrv @Inject() (
def getTag(tag: Tag)(implicit graph: Graph): Traversal.V[Tag] = startTraversal.getTag(tag)

def getOrCreate(tagName: String)(implicit graph: Graph, authContext: AuthContext): Try[Tag with Entity] =
fromString(tagName) match {
case Some((ns, pred, v)) =>
startTraversal
.getByName(ns, pred, v)
.getOrFail("Tag")
.orElse(
startTraversal
.getByName(freeTagNamespace, tagName, None)
.getOrFail("Tag")
.orElse(create(freeTag(tagName)))
)
case None =>
fromString(tagName)
.flatMap {
case (ns, pred, v) => startTraversal.getByName(ns, pred, v).headOption
}
.fold {
startTraversal
.getByName(freeTagNamespace, tagName, None)
.getOrFail("Tag")
.orElse(create(freeTag(tagName)))
}
}(Success(_))

def create(tag: Tag)(implicit graph: Graph, authContext: AuthContext): Try[Tag with Entity] = {
integrityCheckActor ! EntityAdded("Tag")
Expand Down

0 comments on commit 3235aaf

Please sign in to comment.