Skip to content

Commit d6cfd90

Browse files
authored
add changeset source to submitOsmChange (#1186)
1 parent 0bb6f3a commit d6cfd90

2 files changed

Lines changed: 42 additions & 21 deletions

File tree

app/org/maproulette/controllers/api/TaskController.scala

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -756,24 +756,35 @@ class TaskController @Inject() (
756756
)
757757
p success Ok(Json.toJson(true))
758758
case _ =>
759-
None
760-
changeService.submitOsmChange(
761-
change,
762-
element.comment,
763-
user.osmProfile.requestToken,
764-
Some(taskId)
765-
) onComplete {
766-
case Success(res) => {
767-
this.customTaskStatus(
768-
taskId,
769-
TaskStatusSet(Task.STATUS_FIXED),
770-
user,
771-
tags,
772-
requestReview
773-
)
774-
p success Ok(res)
775-
}
776-
case Failure(f) => p failure f
759+
// Get the parent challenge to retrieve the changeset source
760+
this.dal.retrieveById(taskId) match {
761+
case Some(task) =>
762+
val challengeSource = this.dalManager.challenge
763+
.retrieveById(task.parent)
764+
.map(_.general.checkinSource)
765+
.getOrElse("")
766+
767+
changeService.submitOsmChange(
768+
change,
769+
element.comment,
770+
user.osmProfile.requestToken,
771+
Some(taskId),
772+
Some(challengeSource)
773+
) onComplete {
774+
case Success(res) => {
775+
this.customTaskStatus(
776+
taskId,
777+
TaskStatusSet(Task.STATUS_FIXED),
778+
user,
779+
tags,
780+
requestReview
781+
)
782+
p success Ok(res)
783+
}
784+
case Failure(f) => p failure f
785+
}
786+
case None =>
787+
p failure new NotFoundException(s"Task with $taskId not found")
777788
}
778789
}
779790
p.future

app/org/maproulette/provider/osm/ChangesetProvider.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,21 @@ class ChangesetProvider @Inject() (
6868
*
6969
* @param changes The changes to be submitted to OSM
7070
* @param changeSetComment The changeset comment to be associated with the change
71+
* @param accessToken The OAuth access token for authentication
72+
* @param taskId Optional taskId to associate with this changeset
73+
* @param source Optional source to be associated with the changeset
7174
* @return future that will return the OSMChange that was submitted to the OSM servers
7275
*/
7376
def submitOsmChange(
7477
changes: OSMChange,
7578
changeSetComment: String,
7679
accessToken: String,
77-
taskId: Option[Long] = None
80+
taskId: Option[Long] = None,
81+
source: Option[String] = None
7882
)(implicit c: Option[Connection] = None): Future[Elem] = {
7983
val p = Promise[Elem]()
8084
// create the new changeset
81-
this.createChangeset(changeSetComment, accessToken) onComplete {
85+
this.createChangeset(changeSetComment, accessToken, source) onComplete {
8286
case Success(changesetId) =>
8387
// retrieve the current version of the osm feature
8488
// conflate the current tags with provided tags
@@ -248,15 +252,21 @@ class ChangesetProvider @Inject() (
248252
*
249253
* @param comment The comment to associate with the changeset
250254
* @param accessToken The access token for the user
255+
* @param source Optional source to be associated with the changeset
251256
* @return
252257
*/
253-
def createChangeset(comment: String, accessToken: String): Future[Int] = {
258+
def createChangeset(
259+
comment: String,
260+
accessToken: String,
261+
source: Option[String] = None
262+
): Future[Int] = {
254263
// Changeset XML Element
255264
val newChangeSet =
256265
<osm>
257266
<changeset>
258267
<tag k="created_by" v="MapRoulette"/>
259268
<tag k="comment" v={comment}/>
269+
{source.filter(_.nonEmpty).map(s => <tag k="source" v={s}/>).getOrElse(NodeSeq.Empty)}
260270
</changeset>
261271
</osm>
262272
implicit val url = s"${config.getOSMServer}/api/0.6/changeset/create"

0 commit comments

Comments
 (0)