Skip to content

Commit

Permalink
Add feature id filter (#1108)
Browse files Browse the repository at this point in the history
* add feature id table filter

* update review table CSV to include feature id filter

* fix test

* fix test again

* formatting

* remove invert variable from filters as its never used and not needed

* remove invert filter test and fix test output format
  • Loading branch information
CollinBeczak authored May 11, 2024
1 parent 49bffd1 commit 72645d4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class TaskReviewController @Inject() (
*/
def extractReviewTableData(
taskId: String,
featureId: String,
reviewStatus: String,
mapper: String,
challengeId: String,
Expand Down Expand Up @@ -303,6 +304,7 @@ class TaskReviewController @Inject() (
val projectIdFilter = parseParameterLong(projectId)
val challengeIdsFilter = parseParameterLong(challengeId)
val taskIdFilter = parseParameterLong(taskId).map(_.head)
val taskFeatureIdFilter = parseParameterString(featureId).map(_.head)
val mappedOnFilter = parseParameterString(mappedOn).map(_.head)
val mapperFilter = parseParameterString(mapper).map(_.head)
val metaReviewedByFilter = parseParameterString(metaReviewedBy).map(_.head)
Expand All @@ -318,6 +320,7 @@ class TaskReviewController @Inject() (
),
taskParams = params.taskParams.copy(
taskId = taskIdFilter,
taskFeatureId = taskFeatureIdFilter,
taskStatus = statusFilter,
taskReviewStatus = reviewStatusFilter,
taskPriorities = priorityFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ trait ReviewSearchMixin extends SearchParametersMixin {
.addFilterGroup(this.filterLocation(searchParameters))
.addFilterGroup(this.filterProjectSearch(searchParameters))
.addFilterGroup(this.filterTaskId(searchParameters))
.addFilterGroup(this.filterTaskFeatureId(searchParameters))
.addFilterGroup(this.filterPriority(searchParameters))
.addFilterGroup(this.filterTaskTags(searchParameters))
.addFilterGroup(this.filterReviewDate(searchParameters))
Expand Down
19 changes: 19 additions & 0 deletions app/org/maproulette/framework/mixins/SearchParametersMixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trait SearchParametersMixin {
this.filterBounding(params),
this.filterTaskStatus(params),
this.filterTaskId(params),
this.filterTaskFeatureId(params),
this.filterProjectSearch(params),
this.filterTaskReviewStatus(params),
this.filterMetaReviewStatus(params),
Expand Down Expand Up @@ -305,6 +306,24 @@ trait SearchParametersMixin {
}
}

/**
* Filters by tasks.name
* @param params with inverting on 'fid'
*/
def filterTaskFeatureId(params: SearchParameters): FilterGroup = {
params.taskParams.taskFeatureId match {
case Some(fid) =>
FilterGroup(
List(
CustomParameter(
s"LOWER(TRIM(${Task.TABLE}.${Task.FIELD_NAME}::TEXT)) LIKE LOWER('%${fid.trim}%')"
)
)
)
case None => FilterGroup(List())
}
}

/**
* Filters by tasks.priority
* @param params with inverting on 'priorities'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trait SearchParametersMixin
this.paramsBounding(params, whereClause)
this.paramsTaskStatus(params, whereClause)
this.paramsTaskId(params, whereClause)
this.paramsTaskFeatureId(params, whereClause)
this.paramsProjectSearch(params, whereClause)
this.paramsTaskReviewStatus(params, whereClause)
this.paramsMetaReviewStatus(params, whereClause)
Expand Down Expand Up @@ -105,6 +106,10 @@ trait SearchParametersMixin
this.appendInWhereClause(whereClause, this.filterTaskId(params).sql())
}

def paramsTaskFeatureId(params: SearchParameters, whereClause: StringBuilder): Unit = {
this.appendInWhereClause(whereClause, this.filterTaskFeatureId(params).sql())
}

def paramsTaskPriorities(params: SearchParameters, whereClause: StringBuilder): Unit = {
this.appendInWhereClause(whereClause, this.filterTaskPriorities(params).sql())
}
Expand Down
7 changes: 7 additions & 0 deletions app/org/maproulette/session/SearchParameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ case class SearchTaskParameters(
taskSearch: Option[String] = None,
taskStatus: Option[List[Int]] = None,
taskId: Option[Long] = None,
taskFeatureId: Option[String] = None,
taskReviewStatus: Option[List[Int]] = None,
taskProperties: Option[Map[String, String]] = None,
taskPropertySearchType: Option[String] = None,
Expand Down Expand Up @@ -245,6 +246,10 @@ object SearchParameters {
case Some(c) => Utils.insertIntoJson(updated, "taskId", c, true)
case None => updated
}
updated = o.taskParams.taskFeatureId match {
case Some(c) => Utils.insertIntoJson(updated, "taskFeatureId", c, true)
case None => updated
}
updated = o.taskParams.taskReviewStatus match {
case Some(c) => Utils.insertIntoJson(updated, "taskReviewStatus", c, true)
case None => updated
Expand Down Expand Up @@ -448,6 +453,8 @@ object SearchParameters {
},
//taskIds
this.getLongParameter(request.getQueryString("tid"), params.taskParams.taskId),
//taskFeatureId
this.getStringParameter(request.getQueryString("fid"), params.taskParams.taskFeatureId),
//taskReviewStatus
request.getQueryString("trStatus") match {
case Some(v) => Utils.toIntList(v)
Expand Down
2 changes: 1 addition & 1 deletion conf/v2_route/review.api
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ GET /tasks/review/mappers/export @org.maproulette.f
# in: query
# description: Reviews to equivalent onlySaved.
###
GET /tasks/review/reviewTable/export @org.maproulette.framework.controller.TaskReviewController.extractReviewTableData(taskId: String ?= "", reviewStatus: String ?= "0,1,2,3,4,5,6,7,-1", mapper: String ?= "", challengeId: String ?= "", projectId: String ?= "", mappedOn: String ?= "", reviewedBy: String ?= "", reviewedAt: String ?= "", metaReviewedBy: String ?= "", metaReviewStatus: String ?= "2,0,1,2,3,6", status: String ?= "0,1,2,3,4,5,6,9", priority: String ?= "0,1,2", tagFilter: String ?= "", sortBy: String ?= "mapped_on", direction: String ?= "ASC", displayedColumns: String ?= "Internal Id,Review Status,Mapper,Challenge,Project,Mapped On,Reviewer,Reviewed On,Status,Priority,Actions,Additional Reviewers", invertedFilters: String ?= "", onlySaved: Boolean ?= false)
GET /tasks/review/reviewTable/export @org.maproulette.framework.controller.TaskReviewController.extractReviewTableData(taskId: String ?= "", featureId: String ?= "", reviewStatus: String ?= "0,1,2,3,4,5,6,7,-1", mapper: String ?= "", challengeId: String ?= "", projectId: String ?= "", mappedOn: String ?= "", reviewedBy: String ?= "", reviewedAt: String ?= "", metaReviewedBy: String ?= "", metaReviewStatus: String ?= "2,0,1,2,3,6", status: String ?= "0,1,2,3,4,5,6,9", priority: String ?= "0,1,2", tagFilter: String ?= "", sortBy: String ?= "mapped_on", direction: String ?= "ASC", displayedColumns: String ?= "Internal Id,Review Status,Mapper,Challenge,Project,Mapped On,Reviewer,Reviewed On,Status,Priority,Actions,Additional Reviewers", invertedFilters: String ?= "", onlySaved: Boolean ?= false)
###
# tags: [ Review ]
# summary: Retrieve a summary of meta-review coverage for reviewers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ class SearchParametersMixinSpec() extends PlaySpec with SearchParametersMixin {
}
}

"filterTaskFeatureId" should {
"match on task feature id" in {
val params = SearchParameters(taskParams = SearchTaskParameters(taskFeatureId = Some("123")))
this
.filterTaskFeatureId(params)
.sql() mustEqual s"LOWER(TRIM(tasks.name::TEXT)) LIKE LOWER('%123%')"
}
}

"filterTaskPriorities" should {
"match on task priority" in {
val params =
Expand Down

0 comments on commit 72645d4

Please sign in to comment.