diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-06-27 16:35:25 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-06-27 16:35:48 +0300 |
commit | 6cb07fb27d46ad9685867abb627cd57e415f5212 (patch) | |
tree | ac044e675ebaeb9364fd63256468911b377386b9 /app/src/main/java/it/niedermann/nextcloud/deck/api | |
parent | d0d74eff0f2c546876fbc5cd632577c9039a86c4 (diff) |
fixes #510: fetching all users
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/api')
3 files changed, 57 insertions, 4 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java index f81c9f191..29b3706fa 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java @@ -16,6 +16,8 @@ import it.niedermann.nextcloud.deck.model.full.FullStack; import it.niedermann.nextcloud.deck.model.ocs.Activity; import it.niedermann.nextcloud.deck.model.ocs.Capabilities; import it.niedermann.nextcloud.deck.model.ocs.comment.OcsComment; +import it.niedermann.nextcloud.deck.model.ocs.user.OcsUser; +import it.niedermann.nextcloud.deck.model.ocs.user.OcsUserList; /** * Created by david on 27.06.17. @@ -37,9 +39,9 @@ public class GsonConfig { Type stackList = new TypeToken<List<FullStack>>() {}.getType(); Type stack = new TypeToken<FullStack>() {}.getType(); Type capabilities = new TypeToken<Capabilities>() {}.getType(); - Type capabilitiesList = new TypeToken<List<Capabilities>>() {}.getType(); + Type ocsUserList = new TypeToken<OcsUserList>() {}.getType(); + Type ocsUser = new TypeToken<OcsUser>() {}.getType(); Type activity = new TypeToken<Activity>() {}.getType(); - Type activityList = new TypeToken<List<Activity>>() {}.getType(); Type attachment = new TypeToken<Attachment>() {}.getType(); Type attachmentList = new TypeToken<List<Attachment>>() {}.getType(); Type comment = new TypeToken<OcsComment>() {}.getType(); @@ -56,9 +58,9 @@ public class GsonConfig { .registerTypeAdapter(label, new NextcloudDeserializer<>("label", Label.class)) .registerTypeAdapter(stackList, new NextcloudArrayDeserializer<>("stacks", FullStack.class)) .registerTypeAdapter(stack, new NextcloudDeserializer<>("stack", FullStack.class)) - .registerTypeAdapter(capabilitiesList, new NextcloudArrayDeserializer<>("capabilities", Capabilities.class)) .registerTypeAdapter(capabilities, new NextcloudDeserializer<>("capability", Capabilities.class)) - .registerTypeAdapter(activityList, new NextcloudDeserializer<>("activities", Activity.class)) + .registerTypeAdapter(ocsUserList, new NextcloudDeserializer<>("ocsUserList", OcsUserList.class)) + .registerTypeAdapter(ocsUser, new NextcloudDeserializer<>("ocsUser", OcsUser.class)) .registerTypeAdapter(activity, new NextcloudDeserializer<>("activity", Activity.class)) .registerTypeAdapter(attachmentList, new NextcloudArrayDeserializer<>("attachments", Attachment.class)) .registerTypeAdapter(attachment, new NextcloudDeserializer<>("attachment", Attachment.class)) diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java index c64e5db1d..6dedefa01 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java @@ -32,6 +32,8 @@ import it.niedermann.nextcloud.deck.model.ocs.Version; import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; import it.niedermann.nextcloud.deck.model.ocs.comment.Mention; import it.niedermann.nextcloud.deck.model.ocs.comment.OcsComment; +import it.niedermann.nextcloud.deck.model.ocs.user.OcsUser; +import it.niedermann.nextcloud.deck.model.ocs.user.OcsUserList; import static it.niedermann.nextcloud.deck.exceptions.DeckException.Hint.CAPABILITIES_VERSION_NOT_PARSABLE; @@ -50,6 +52,10 @@ public class JsonToEntityParser { return (T) parseActivity(obj); } else if (mType == Capabilities.class) { return (T) parseCapabilities(obj); + } else if (mType == OcsUserList.class) { + return (T) parseOcsUserList(obj); + } else if (mType == OcsUser.class) { + return (T) parseOcsUser(obj); } else if (mType == Attachment.class) { return (T) parseAttachment(obj); } else if (mType == OcsComment.class) { @@ -58,6 +64,43 @@ public class JsonToEntityParser { throw new IllegalArgumentException("unregistered type: " + mType.getCanonicalName()); } + private static OcsUser parseOcsUser(JsonObject obj) { + DeckLog.verbose(obj.toString()); + OcsUser ocsUser = new OcsUser(); + TraceableException.makeTraceableIfFails(() -> { + JsonElement data = obj.get("ocs").getAsJsonObject().get("data"); + if (!data.isJsonNull()) { + JsonObject jsonObject = data.getAsJsonObject(); + if (jsonObject.has("id")) { + ocsUser.setId(getNullAsEmptyString(jsonObject.get("id"))); + } + if (jsonObject.has("displayname")) { + ocsUser.setDisplayName(getNullAsEmptyString(jsonObject.get("displayname"))); + } + } + + }, obj); + return ocsUser; + } + + private static OcsUserList parseOcsUserList(JsonObject obj) { + DeckLog.verbose(obj.toString()); + OcsUserList ocsUserList = new OcsUserList(); + TraceableException.makeTraceableIfFails(() -> { + JsonElement data = obj.get("ocs").getAsJsonObject().get("data"); + if (!data.isJsonNull() && data.getAsJsonObject().has("users")) { + JsonElement users = data.getAsJsonObject().get("users"); + if (!users.isJsonNull() && users.isJsonArray()) { + for (JsonElement userElement : users.getAsJsonArray()) { + ocsUserList.add(userElement.getAsString()); + } + } + } + + }, obj); + return ocsUserList; + } + private static OcsComment parseOcsComment(JsonObject obj) { DeckLog.verbose(obj.toString()); OcsComment comment = new OcsComment(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java index b3e4f4c84..d69ee8513 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java @@ -8,6 +8,8 @@ import it.niedermann.nextcloud.deck.model.ocs.Activity; import it.niedermann.nextcloud.deck.model.ocs.Capabilities; import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; import it.niedermann.nextcloud.deck.model.ocs.comment.OcsComment; +import it.niedermann.nextcloud.deck.model.ocs.user.OcsUser; +import it.niedermann.nextcloud.deck.model.ocs.user.OcsUserList; import retrofit2.http.Body; import retrofit2.http.DELETE; import retrofit2.http.GET; @@ -22,6 +24,12 @@ public interface NextcloudServerAPI { @GET("cloud/capabilities?format=json") Observable<Capabilities> getCapabilities(); + @GET("cloud/users?format=json") + Observable<OcsUserList> getAllUsers(); + + @GET("cloud/users/{uid}?format=json") + Observable<OcsUser> getUserDetails(@Path("uid") String uid); + @GET("apps/activity/api/v2/activity/filter?format=json&object_type=deck_card&limit=50&since=-1&sort=asc") Observable<List<Activity>> getActivitiesForCard(@Query("object_id") long cardId); |