Skip to content

Commit

Permalink
#1501 Mapping macro cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 13, 2020
1 parent ec8ae98 commit 8e88204
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 64 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
Submodule ScalliGraph updated 23 files
+1 −1 core-test/src/test/scala/org/thp/scalligraph/controllers/ControllerTest.scala
+1 −1 core-test/src/test/scala/org/thp/scalligraph/controllers/TestUtils.scala
+1 −1 core-test/src/test/scala/org/thp/scalligraph/models/CardinalityTest.scala
+1 −1 core-test/src/test/scala/org/thp/scalligraph/models/ModernTest.scala
+2 −7 core/src/main/scala/org/thp/scalligraph/Annotations.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/controllers/FieldsParser.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/controllers/UpdateFieldsParser.scala
+1 −25 core/src/main/scala/org/thp/scalligraph/macro/AnnotationMacro.scala
+9 −9 core/src/main/scala/org/thp/scalligraph/macro/FieldsParserMacro.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/macro/IndexMacro.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/macro/MacroError.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/macro/MacroLogger.scala
+10 −11 core/src/main/scala/org/thp/scalligraph/macro/MacroUtil.scala
+46 −0 core/src/main/scala/org/thp/scalligraph/macro/MappingMacroHelper.scala
+4 −4 core/src/main/scala/org/thp/scalligraph/macro/ModelMacro.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/macro/TraversalMacro.scala
+0 −77 core/src/main/scala/org/thp/scalligraph/macros/MappingMacroHelper.scala
+4 −8 core/src/main/scala/org/thp/scalligraph/models/Mapping.scala
+5 −88 core/src/main/scala/org/thp/scalligraph/models/Model.scala
+5 −5 core/src/main/scala/org/thp/scalligraph/traversal/ProjectionBuilder.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/traversal/Selectors.scala
+1 −1 core/src/main/scala/org/thp/scalligraph/traversal/TraversalOps.scala
+5 −5 database/orientdb/src/main/scala/org/thp/scalligraph/orientdb/OrientDatabase.scala
29 changes: 14 additions & 15 deletions migration/src/main/scala/org/thp/thehive/migration/th3/DBGet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ class DBGet @Inject() (db: DBConfiguration, implicit val ec: ExecutionContext) {
*/
def apply(modelName: String, id: String): Future[JsObject] =
db.execute {
// Search by id is not possible on child entity without routing information ⇒ id query
search(db.indexName)
.query(idsQuery(id) /*.types(modelName)*/ )
.size(1)
.version(true)
}
.map { searchResponse =>
searchResponse
.hits
.hits
.headOption
.fold[JsObject](throw NotFoundError(s"$modelName $id not found")) { hit =>
DBUtils.hit2json(hit)
}
}
// Search by id is not possible on child entity without routing information => id query
search(db.indexName)
.query(idsQuery(id) /*.types(modelName)*/ )
.size(1)
.version(true)
}.map { searchResponse =>
searchResponse
.hits
.hits
.headOption
.fold[JsObject](throw NotFoundError(s"$modelName $id not found")) { hit =>
DBUtils.hit2json(hit)
}
}
}
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/controllers/v0/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Router @Inject() (
// case GET(p"/case/task/log/$logId") => logCtrl.get(logId)

case POST(p"/case/artifact/_search") => observableCtrl.search
// case POST(p"/case/:caseId/artifact/_search") observableCtrl.findInCase(caseId)
// case POST(p"/case/:caseId/artifact/_search") => observableCtrl.findInCase(caseId)
case POST(p"/case/artifact/_stats") => observableCtrl.stats
case POST(p"/case/$caseId/artifact") => observableCtrl.create(caseId) // Audit ok
case GET(p"/case/artifact/$observableId") => observableCtrl.get(observableId)
Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ object Conversion {
.withFieldComputed(_._createdAt, _._createdAt)
.withFieldComputed(_._createdBy, _._createdBy)
.withFieldComputed(_.obj, a => a.`object`.map(OutputEntity.apply))
// .withFieldComputed(_.obj, a OutputEntity(a.obj))
// .withFieldComputed(_.obj, a => OutputEntity(a.obj))
// .withFieldComputed(
// _.summary,
// _.summary.mapValues(
// opCount
// opCount =>
// opCount.map {
// case (op, count) op.toString → count
// case (op, count) => op.toString → count
// }
// )
.withFieldConst(_.attributeName, None) // FIXME
Expand Down
18 changes: 9 additions & 9 deletions thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ class Router @Inject() (
case PATCH(p"/case/$caseId") => caseCtrl.update(caseId)
case POST(p"/case/_merge/$caseIds") => caseCtrl.merge(caseIds)
case DELETE(p"/case/$caseId") => caseCtrl.delete(caseId)
// case PATCH(p"api/case/_bulk") caseCtrl.bulkUpdate()
// case POST(p"/case/_stats") caseCtrl.stats()
// case DELETE(p"/case/$caseId/force") caseCtrl.realDelete(caseId)
// case GET(p"/case/$caseId/links") caseCtrl.linkedCases(caseId)
// case PATCH(p"api/case/_bulk") => caseCtrl.bulkUpdate()
// case POST(p"/case/_stats") => caseCtrl.stats()
// case DELETE(p"/case/$caseId/force") => caseCtrl.realDelete(caseId)
// case GET(p"/case/$caseId/links") => caseCtrl.linkedCases(caseId)

case GET(p"/caseTemplate") => caseTemplateCtrl.list
case POST(p"/caseTemplate") => caseTemplateCtrl.create
case GET(p"/caseTemplate/$caseTemplateId") => caseTemplateCtrl.get(caseTemplateId)
case PATCH(p"/caseTemplate/$caseTemplateId") => caseTemplateCtrl.update(caseTemplateId)
//case DELETE(p"/caseTemplate/$caseTemplateId") caseTemplateCtrl.delete(caseTemplateId)
//case DELETE(p"/caseTemplate/$caseTemplateId") => caseTemplateCtrl.delete(caseTemplateId)

case POST(p"/user") => userCtrl.create
case GET(p"/user/current") => userCtrl.current
Expand All @@ -64,10 +64,10 @@ class Router @Inject() (
case GET(p"/organisation/$organisationId") => organisationCtrl.get(organisationId)
case PATCH(p"/organisation/$organisationId") => organisationCtrl.update(organisationId)

// case GET(p"/share") shareCtrl.list
// case POST(p"/share") shareCtrl.create
// case GET(p"/share/$shareId") shareCtrl.get(shareId)
// case PATCH(p"/share/$shareId") shareCtrl.update(shareId)
// case GET(p"/share") => shareCtrl.list
// case POST(p"/share") => shareCtrl.create
// case GET(p"/share/$shareId") => shareCtrl.get(shareId)
// case PATCH(p"/share/$shareId") => shareCtrl.update(shareId)

case GET(p"/task") => taskCtrl.list
case POST(p"/task") => taskCtrl.create
Expand Down
8 changes: 4 additions & 4 deletions thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ class CaseSrv @Inject() (
// .flatMap(_.customFields().toList
// .groupBy(_.name)
// .foreach {
// case (name, l)
// val values = l.collect { case cfwv: CustomFieldWithValue if cfwv.value.isDefined cfwv.value.get }
// case (name, l) =>
// val values = l.collect { case cfwv: CustomFieldWithValue if cfwv.value.isDefined => cfwv.value.get }
// val cf = customFieldSrv.getOrFail(name)
// val caseCustomField =
// if (values.size == 1) cf.`type`.setValue(CaseCustomField(), values.head)
Expand All @@ -324,12 +324,12 @@ class CaseSrv @Inject() (
// cases
// .map(get)
// .flatMap(_.tasks.toList
// .foreach(task caseTaskSrv.create(CaseTask(), task, mergedCase))
// .foreach(task => caseTaskSrv.create(CaseTask(), task, mergedCase))
//
// cases
// .map(get)
// .flatMap(_.observables.toList
// .foreach(observable observableCaseSrv.create(ObservableCase(), observable, mergedCase))
// .foreach(observable => observableCaseSrv.create(ObservableCase(), observable, mergedCase))
//
// get(mergedCase).richCase.head
// }
Expand Down
29 changes: 0 additions & 29 deletions thehive/app/org/thp/thehive/services/package.scala

This file was deleted.

4 changes: 2 additions & 2 deletions thehive/test/org/thp/thehive/services/CaseSrvTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder {
"merge two cases" in testApp { app =>
pending
// app[Database].transaction { implicit graph =>
// Seq("#2", "#3").toTry(app[CaseSrv].getOrFail) must beSuccessfulTry.which { cases: Seq[Case with Entity]
// Seq("#2", "#3").toTry(app[CaseSrv].getOrFail) must beSuccessfulTry.which { cases: Seq[Case with Entity] =>
// val mergedCase = app[CaseSrv].merge(cases)(graph, dummyUserSrv.getSystemAuthContext)
//
// mergedCase.title must_=== "case#2 / case#3"
Expand All @@ -159,7 +159,7 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder {
// mergedCase.summary must beNone
// mergedCase.impactStatus must beNone
// mergedCase.user must beSome("test")
// mergedCase.customFields.map(f (f.name, f.typeName, f.value)) must contain(
// mergedCase.customFields.map(f => (f.name, f.typeName, f.value)) must contain(
// allOf[(String, String, Option[Any])](
// ("boolean1", "boolean", Some(true)),
// ("string1", "string", Some("string1 custom field"))
Expand Down

0 comments on commit 8e88204

Please sign in to comment.