Skip to content

Commit 00a3477

Browse files
author
Michael Cuthbert
authored
Merge pull request #72 from pdevkota1/user_attributes
User attributes
2 parents f674c44 + abd8b69 commit 00a3477

File tree

8 files changed

+233
-1
lines changed

8 files changed

+233
-1
lines changed

src/main/java/org/maproulette/client/api/QueryConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public final class QueryConstants
3131
public static final String URI_TASK_BASE = API_VERSION + "/task/%s";
3232
public static final String URI_TASK_POST = API_VERSION + "/task";
3333
public static final String URI_TASK_FIND = URI_TASK_POST + URI_FIND;
34+
// USER URIS
35+
public static final String URI_USER_PUBLIC_BY_ID = API_VERSION + "/user/%d/public";
3436
// Flags
3537
public static final String FLAG_IMMEDIATE_DELETE = "immediate";
3638

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.maproulette.client.api;
2+
3+
import java.io.IOException;
4+
import java.util.Optional;
5+
6+
import org.apache.commons.lang.StringUtils;
7+
import org.maproulette.client.connection.IMapRouletteConnection;
8+
import org.maproulette.client.connection.MapRouletteConfiguration;
9+
import org.maproulette.client.connection.MapRouletteConnection;
10+
import org.maproulette.client.connection.Query;
11+
import org.maproulette.client.exception.MapRouletteException;
12+
import org.maproulette.client.model.User;
13+
14+
import com.fasterxml.jackson.databind.ObjectMapper;
15+
16+
import lombok.RequiredArgsConstructor;
17+
18+
/**
19+
* That User service handles the API requests for Users
20+
*
21+
* @author pdevkota1
22+
*/
23+
@RequiredArgsConstructor
24+
public class UserAPI
25+
{
26+
27+
private final ObjectMapper mapper = new ObjectMapper();
28+
private final IMapRouletteConnection connection;
29+
30+
public UserAPI(final MapRouletteConfiguration configuration)
31+
{
32+
this(new MapRouletteConnection(configuration));
33+
}
34+
35+
public Optional<User> getPublicFromId(final long identifier) throws MapRouletteException
36+
{
37+
final var query = Query.builder()
38+
.get(String.format(QueryConstants.URI_USER_PUBLIC_BY_ID, identifier)).build();
39+
return this.parseResponse(this.connection.execute(query).orElse(""));
40+
}
41+
42+
private Optional<User> parseResponse(final String response) throws MapRouletteException
43+
{
44+
if (StringUtils.isEmpty(response))
45+
{
46+
return Optional.empty();
47+
}
48+
try
49+
{
50+
return Optional.of(this.mapper.readValue(response, User.class));
51+
}
52+
catch (final IOException e)
53+
{
54+
throw new MapRouletteException(e);
55+
}
56+
}
57+
}

src/main/java/org/maproulette/client/model/Task.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public Task build()
129129
this.parent(-1);
130130
}
131131
return new Task(this.id, this.parent, this.name, this.instruction, this.location,
132-
this.status, this.priority, this.geometries, this.tags);
132+
this.status, this.priority, this.geometries, this.tags, null, null, null);
133133
}
134134

135135
protected ArrayNode generateTaskFeatures(final Set<PointInformation> source,
@@ -201,6 +201,9 @@ private JsonNode buildGeometries() throws MapRouletteException
201201
private ChallengePriority priority;
202202
private JsonNode geometries;
203203
private List<String> tags;
204+
private Long completedBy;
205+
private Long completedTimeSpent;
206+
private String mappedOn;
204207

205208
public static TaskBuilder builder(final long parentIdentifier, final String name)
206209
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.maproulette.client.model;
2+
3+
import java.io.Serializable;
4+
5+
import org.maproulette.client.exception.MapRouletteException;
6+
import org.maproulette.client.utilities.Utilities;
7+
8+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
9+
import com.fasterxml.jackson.annotation.JsonInclude;
10+
11+
import lombok.AllArgsConstructor;
12+
import lombok.Data;
13+
import lombok.NoArgsConstructor;
14+
15+
/**
16+
* Very class defining the structure of user data
17+
*
18+
* @author pdevkota1
19+
*/
20+
@Data
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
@JsonInclude(JsonInclude.Include.NON_NULL)
24+
@JsonIgnoreProperties(ignoreUnknown = true)
25+
public class User implements Serializable
26+
{
27+
@SuppressWarnings("checkstyle:memberName")
28+
private long id;
29+
private String name;
30+
31+
public static User fromJson(final String json) throws MapRouletteException
32+
{
33+
return Utilities.fromJson(json, User.class);
34+
}
35+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.maproulette.client.api;
2+
3+
/**
4+
* @author pdevkota1
5+
*/
6+
public class UserAPITest
7+
{
8+
9+
}

src/test/java/org/maproulette/client/serializer/TaskSerializerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.junit.jupiter.api.Assertions;
77
import org.junit.jupiter.api.Test;
8+
import org.maproulette.client.exception.MapRouletteException;
89
import org.maproulette.client.model.ChallengePriority;
910
import org.maproulette.client.model.PointInformation;
1011
import org.maproulette.client.model.Task;
@@ -81,4 +82,14 @@ private void verifyTask(final Task task1, final Task task2)
8182
Assertions.assertEquals(task1.getPriority(), task2.getPriority());
8283
Assertions.assertEquals(task1.getStatus(), task2.getStatus());
8384
}
85+
86+
@Test
87+
public void taskWithStatusFroJson() throws MapRouletteException
88+
{
89+
final Task task = Task
90+
.fromJson(SerializerUtilities.getResourceAsString("task/testTask.json"));
91+
Assertions.assertEquals(999, task.getCompletedBy());
92+
Assertions.assertEquals(58871, task.getCompletedTimeSpent());
93+
Assertions.assertEquals("2021-09-15T18:30:57.652Z", task.getMappedOn());
94+
}
8495
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.maproulette.client.serializer;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import org.maproulette.client.exception.MapRouletteException;
6+
import org.maproulette.client.model.User;
7+
8+
/**
9+
* @author pdevkota1
10+
*/
11+
public class UserSerializationTest
12+
{
13+
@Test
14+
public void userSerialization() throws MapRouletteException
15+
{
16+
final var testUserString = "{\"id\":12345 ,\"name\":\"someOsmName\", \"created\": \"2016-08-16T12:34:36.372Z\"}";
17+
final User testUser = User.fromJson(testUserString);
18+
Assertions.assertEquals(12345, testUser.getId());
19+
Assertions.assertEquals("someOsmName", testUser.getName());
20+
}
21+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"id": 134825569,
3+
"name": "some-name",
4+
"created": "2021-09-10T03:38:51.964Z",
5+
"modified": "2021-09-15T18:30:57.652Z",
6+
"parent": 34786,
7+
"instruction": "",
8+
"location":
9+
{
10+
"type": "Point",
11+
"coordinates":
12+
[
13+
12.3392320375663,
14+
56.1175800771846
15+
]
16+
},
17+
"geometries":
18+
{
19+
"type": "FeatureCollection",
20+
"features":
21+
[
22+
{
23+
"id": "some-id",
24+
"type": "Feature",
25+
"geometry":
26+
{
27+
"type": "LineString",
28+
"coordinates":
29+
[
30+
[
31+
12.3394633,
32+
56.1178221
33+
],
34+
[
35+
12.3393923,
36+
56.117798
37+
],
38+
[
39+
12.3393263,
40+
56.1177314
41+
],
42+
[
43+
12.3391997,
44+
56.1175408
45+
],
46+
[
47+
12.3390849,
48+
56.1173754
49+
],
50+
[
51+
12.3390546,
52+
56.1173319
53+
],
54+
[
55+
12.3390611,
56+
56.1172921
57+
]
58+
]
59+
},
60+
"properties":
61+
{
62+
"confidence": "252.08934328358208",
63+
"maxCountRatio": "0.9874626865671642",
64+
"osmIdentifier": "93584898"
65+
}
66+
}
67+
]
68+
},
69+
"status": 1,
70+
"mappedOn": "2021-09-15T18:30:57.652Z",
71+
"completedTimeSpent": 58871,
72+
"completedBy": 999,
73+
"review":
74+
{
75+
"reviewStatus": 1,
76+
"reviewRequestedBy": 999,
77+
"reviewedBy": 9999,
78+
"reviewedAt": "2021-09-16T22:16:05.341Z",
79+
"reviewStartedAt": "2021-09-16T22:15:56.463Z"
80+
},
81+
"priority": 0,
82+
"changesetId": -1,
83+
"bundleId": 67106,
84+
"isBundlePrimary": true,
85+
"reviewStatus": 1,
86+
"reviewRequestedBy": 999,
87+
"reviewedBy": 9999,
88+
"reviewedAt": "2021-09-16T22:16:05.341Z",
89+
"reviewStartedAt": "2021-09-16T22:15:56.463Z",
90+
"tags":
91+
[
92+
""
93+
]
94+
}

0 commit comments

Comments
 (0)