Skip to content

Commit

Permalink
#1731 Fix parent/child query in Cortex
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 15, 2021
1 parent 4c75dfa commit a323f48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,15 @@ class CortexParentQueryInputFilter(parentFilter: InputQuery[Traversal.Unk, Trave
traversalType: ru.Type,
traversal: Traversal.Unk,
authContext: AuthContext
): Traversal.Unk = {
def filter[F, T: ru.TypeTag](t: Traversal.V[F] => Traversal.V[T]): Traversal.Unk =
parentFilter(
publicProperties,
ru.typeOf[Traversal.V[T]],
t(traversal.asInstanceOf[Traversal.V[F]]).asInstanceOf[Traversal.Unk],
authContext
)
if (traversalType =:= ru.typeOf[Traversal.V[Job]]) filter[Job, Observable](_.observable)
): Traversal.Unk =
if (traversalType =:= ru.typeOf[Traversal.V[Job]])
traversal
.asInstanceOf[Traversal.V[Job]]
.filter { t =>
parentFilter(publicProperties, ru.typeOf[Traversal.V[Observable]], t.observable.asInstanceOf[Traversal.Unk], authContext)
}
.asInstanceOf[Traversal.Unk]
else throw BadRequestError(s"$traversalType hasn't parent")
}
}

class CortexChildQueryInputFilter(childType: String, childFilter: InputQuery[Traversal.Unk, Traversal.Unk])
Expand All @@ -100,15 +98,13 @@ class CortexChildQueryInputFilter(childType: String, childFilter: InputQuery[Tra
traversalType: ru.Type,
traversal: Traversal.Unk,
authContext: AuthContext
): Traversal.Unk = {
def filter[F, T: ru.TypeTag](t: Traversal.V[F] => Traversal.V[T]): Traversal.Unk =
childFilter(
publicProperties,
ru.typeOf[Traversal.V[T]],
t(traversal.asInstanceOf[Traversal.V[F]]).asInstanceOf[Traversal.Unk],
authContext
)
if (traversalType =:= ru.typeOf[Traversal.V[Observable]] && childType == "case_artifact_job") filter[Observable, Job](_.jobs)
): Traversal.Unk =
if (traversalType =:= ru.typeOf[Traversal.V[Observable]] && childType == "case_artifact_job")
traversal
.asInstanceOf[Traversal.V[Observable]]
.filter { t =>
childFilter(publicProperties, ru.typeOf[Traversal.V[Job]], t.jobs.asInstanceOf[Traversal.Unk], authContext)
}
.asInstanceOf[Traversal.Unk]
else throw BadRequestError(s"$traversalType hasn't child of type $childType")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class PublicJob @Inject() (jobSrv: JobSrv) extends PublicData with JobRenderer {
)
override val outputQuery: Query = Query.outputWithContext[RichJob, Traversal.V[Job]]((jobSteps, authContext) => jobSteps.richJob(authContext))
override val extraQueries: Seq[ParamQuery[_]] = Seq(
Query[Traversal.V[Observable], Traversal.V[Job]]("jobs", (jobTraversal, _) => jobTraversal.jobs)
Query[Traversal.V[Observable], Traversal.V[Job]]("jobs", (observables, _) => observables.jobs)
)
override val publicProperties: PublicProperties = PublicPropertyListBuilder[Job]
.property("analyzerId", UMapping.string)(_.rename("workerId").readonly)
Expand Down

0 comments on commit a323f48

Please sign in to comment.