From fa34a32013be1132e0153a1be8c5a17de6297c1e Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 5 Nov 2024 14:45:50 -0600 Subject: [PATCH] add dataset_url to challenge table --- .../framework/model/Challenge.scala | 3 ++- .../repository/ChallengeRepository.scala | 6 ++++-- .../maproulette/models/dal/ChallengeDAL.scala | 19 ++++++++++++++----- conf/evolutions/default/97.sql | 5 +++++ 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 conf/evolutions/default/97.sql diff --git a/app/org/maproulette/framework/model/Challenge.scala b/app/org/maproulette/framework/model/Challenge.scala index 0b74fe66..8e75988b 100644 --- a/app/org/maproulette/framework/model/Challenge.scala +++ b/app/org/maproulette/framework/model/Challenge.scala @@ -136,8 +136,9 @@ case class ChallengeExtra( isArchived: Boolean = false, reviewSetting: Int = Challenge.REVIEW_SETTING_NOT_REQUIRED, taskWidgetLayout: Option[JsValue] = None, + datasetUrl: Option[String] = None, systemArchivedAt: Option[DateTime] = None, - presets: Option[List[String]] = None + presets: Option[List[String]] = None, ) extends DefaultWrites case class ChallengeListing( diff --git a/app/org/maproulette/framework/repository/ChallengeRepository.scala b/app/org/maproulette/framework/repository/ChallengeRepository.scala index f4d8efda..af5bddee 100644 --- a/app/org/maproulette/framework/repository/ChallengeRepository.scala +++ b/app/org/maproulette/framework/repository/ChallengeRepository.scala @@ -264,6 +264,7 @@ object ChallengeRepository { get[Option[List[Long]]]("virtual_parent_ids") ~ get[Boolean]("challenges.is_archived") ~ get[Int]("challenges.review_setting") ~ + get[Option[String]]("challenges.dataset_url") ~ get[Option[JsValue]]("challenges.task_widget_layout") ~ get[Option[DateTime]]("challenges.system_archived_at") map { case id ~ name ~ created ~ modified ~ description ~ infoLink ~ ownerId ~ parentId ~ instruction ~ @@ -272,7 +273,7 @@ object ChallengeRepository { mediumPriorityRule ~ lowPriorityRule ~ defaultZoom ~ minZoom ~ maxZoom ~ defaultBasemap ~ defaultBasemapId ~ customBasemap ~ updateTasks ~ exportableProperties ~ osmIdProperty ~ taskBundleIdProperty ~ preferredTags ~ preferredReviewTags ~ limitTags ~ limitReviewTags ~ taskStyles ~ lastTaskRefresh ~ dataOriginDate ~ requiresLocal ~ location ~ bounding ~ - deleted ~ virtualParents ~ isArchived ~ reviewSetting ~ taskWidgetLayout ~ systemArchivedAt => + deleted ~ virtualParents ~ isArchived ~ reviewSetting ~ datasetUrl ~ taskWidgetLayout ~ systemArchivedAt => val hpr = highPriorityRule match { case Some(c) if StringUtils.isEmpty(c) || StringUtils.equals(c, "{}") => None case r => r @@ -330,7 +331,8 @@ object ChallengeRepository { isArchived, reviewSetting, taskWidgetLayout, - systemArchivedAt + datasetUrl, + systemArchivedAt, ), status, statusMessage, diff --git a/app/org/maproulette/models/dal/ChallengeDAL.scala b/app/org/maproulette/models/dal/ChallengeDAL.scala index 82f14db9..c764a788 100644 --- a/app/org/maproulette/models/dal/ChallengeDAL.scala +++ b/app/org/maproulette/models/dal/ChallengeDAL.scala @@ -122,6 +122,7 @@ class ChallengeDAL @Inject() ( get[Boolean]("deleted") ~ get[Boolean]("challenges.is_archived") ~ get[Int]("challenges.review_setting") ~ + get[Option[String]]("challenges.dataset_url") ~ get[Option[JsValue]]("challenges.task_widget_layout") ~ get[Option[Int]]("challenges.completion_percentage") ~ get[Option[Int]]("challenges.tasks_remaining") map { @@ -132,7 +133,7 @@ class ChallengeDAL @Inject() ( minZoom ~ maxZoom ~ defaultBasemap ~ defaultBasemapId ~ customBasemap ~ updateTasks ~ exportableProperties ~ osmIdProperty ~ taskBundleIdProperty ~ preferredTags ~ preferredReviewTags ~ limitTags ~ limitReviewTags ~ taskStyles ~ lastTaskRefresh ~ dataOriginDate ~ location ~ bounding ~ - requiresLocal ~ deleted ~ isArchived ~ reviewSetting ~ taskWidgetLayout ~ completionPercentage ~ tasksRemaining => + requiresLocal ~ deleted ~ isArchived ~ reviewSetting ~ datasetUrl ~ taskWidgetLayout ~ completionPercentage ~ tasksRemaining => val hpr = highPriorityRule match { case Some(c) if StringUtils.isEmpty(c) || StringUtils.equals(c, "{}") => None case r => r @@ -189,7 +190,8 @@ class ChallengeDAL @Inject() ( taskBundleIdProperty, isArchived, reviewSetting, - taskWidgetLayout + taskWidgetLayout, + datasetUrl ), status, statusMessage, @@ -259,6 +261,7 @@ class ChallengeDAL @Inject() ( get[Option[List[String]]]("presets") ~ get[Boolean]("challenges.is_archived") ~ get[Int]("challenges.review_setting") ~ + get[Option[String]]("challenges.dataset_url") ~ get[Option[JsValue]]("challenges.task_widget_layout") ~ get[Option[DateTime]]("challenges.system_archived_at") ~ get[Option[Int]]("challenges.completion_percentage") ~ @@ -271,7 +274,7 @@ class ChallengeDAL @Inject() ( customBasemap ~ updateTasks ~ exportableProperties ~ osmIdProperty ~ taskBundleIdProperty ~ preferredTags ~ preferredReviewTags ~ limitTags ~ limitReviewTags ~ taskStyles ~ lastTaskRefresh ~ dataOriginDate ~ location ~ bounding ~ requiresLocal ~ deleted ~ virtualParents ~ - presets ~ isArchived ~ reviewSetting ~ taskWidgetLayout ~ systemArchivedAt ~ completionPercentage ~ tasksRemaining => + presets ~ isArchived ~ reviewSetting ~ datasetUrl ~ taskWidgetLayout ~ systemArchivedAt ~ completionPercentage ~ tasksRemaining => val hpr = highPriorityRule match { case Some(c) if StringUtils.isEmpty(c) || StringUtils.equals(c, "{}") => None case r => r @@ -329,6 +332,7 @@ class ChallengeDAL @Inject() ( isArchived, reviewSetting, taskWidgetLayout, + datasetUrl, systemArchivedAt, presets ), @@ -473,6 +477,7 @@ class ChallengeDAL @Inject() ( this.permission.hasObjectWriteAccess(challenge, user) this.cacheManager.withOptionCaching { () => + var a = "a" val insertedChallenge = this.withMRTransaction { implicit c => SQL"""INSERT INTO challenges (name, owner_id, parent_id, difficulty, description, info_link, blurb, @@ -481,7 +486,7 @@ class ChallengeDAL @Inject() ( medium_priority_rule, low_priority_rule, default_zoom, min_zoom, max_zoom, default_basemap, default_basemap_id, custom_basemap, updatetasks, exportable_properties, osm_id_property, task_bundle_id_property, last_task_refresh, data_origin_date, preferred_tags, preferred_review_tags, - limit_tags, limit_review_tags, task_styles, requires_local, is_archived, review_setting, task_widget_layout) + limit_tags, limit_review_tags, task_styles, requires_local, is_archived, review_setting, dataset_url, task_widget_layout) VALUES (${challenge.name}, ${challenge.general.owner}, ${challenge.general.parent}, ${challenge.general.difficulty}, ${challenge.description}, ${challenge.infoLink}, ${challenge.general.blurb}, ${challenge.general.instruction}, ${challenge.general.enabled}, ${challenge.general.featured}, @@ -495,7 +500,7 @@ class ChallengeDAL @Inject() ( ${challenge.dataOriginDate.getOrElse(DateTime.now()).toString}::timestamptz, ${challenge.extra.preferredTags}, ${challenge.extra.preferredReviewTags}, ${challenge.extra.limitTags}, ${challenge.extra.limitReviewTags}, ${challenge.extra.taskStyles}, ${challenge.general.requiresLocal}, ${challenge.extra.isArchived}, - ${challenge.extra.reviewSetting}, + ${challenge.extra.reviewSetting}, ${challenge.extra.datasetUrl}, ${asJson(challenge.extra.taskWidgetLayout.getOrElse(Json.parse("{}")))} ) ON CONFLICT(parent_id, LOWER(name)) DO NOTHING RETURNING #${this.retrieveColumns}""" .as(this.parser.*) @@ -683,6 +688,10 @@ class ChallengeDAL @Inject() ( .asOpt[Int] .getOrElse(cachedItem.extra.reviewSetting) + val datasetUrl = (updates \ "datasetUrl") + .asOpt[String] + .getOrElse(cachedItem.extra.datasetUrl) + val taskWidgetLayout = (updates \ "taskWidgetLayout") .asOpt[JsValue] .getOrElse(cachedItem.extra.taskWidgetLayout.getOrElse(Json.parse("{}"))) diff --git a/conf/evolutions/default/97.sql b/conf/evolutions/default/97.sql new file mode 100644 index 00000000..743b0bcc --- /dev/null +++ b/conf/evolutions/default/97.sql @@ -0,0 +1,5 @@ +# --- !Ups +ALTER TABLE challenges ADD COLUMN dataset_url VARCHAR DEFAULT NULL;; + +# --- !Downs +ALTER TABLE IF EXISTS challenges DROP COLUMN dataset_url;;