diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-06-16 15:03:34 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-06-16 15:03:34 +0300 |
commit | f7d1746d7c131720f02c23a99ddc215df54335fd (patch) | |
tree | 287fdd86524d60429c4ce615f8d96b92acb13991 /app/src/main/java/it/niedermann/nextcloud/deck/api | |
parent | 58122f4cbeabafda2d7b4e38a0fc2878b1127dfb (diff) | |
parent | c0c89fb98c67162a7d3ca8abd8461f67ff9709af (diff) |
Merge branch 'master' into 454-replay-to-comments
# Conflicts:
# app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java
# app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java
# app/src/main/res/layout/fragment_card_edit_tab_comments.xml
# app/src/main/res/layout/item_comment.xml
# app/src/main/res/values/strings.xml
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/api')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java | 427 |
1 files changed, 226 insertions, 201 deletions
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 2556deb02..c64e5db1d 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 @@ -14,6 +14,7 @@ import java.util.List; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.exceptions.DeckException; +import it.niedermann.nextcloud.deck.exceptions.TraceableException; import it.niedermann.nextcloud.deck.model.AccessControl; import it.niedermann.nextcloud.deck.model.Attachment; import it.niedermann.nextcloud.deck.model.Board; @@ -60,31 +61,35 @@ public class JsonToEntityParser { private static OcsComment parseOcsComment(JsonObject obj) { DeckLog.verbose(obj.toString()); OcsComment comment = new OcsComment(); - JsonElement data = obj.get("ocs").getAsJsonObject().get("data"); - if (data.isJsonArray()) { - for (JsonElement deckComment : data.getAsJsonArray()) { - comment.addComment(parseDeckComment(deckComment)); + TraceableException.makeTraceableIfFails(() -> { + JsonElement data = obj.get("ocs").getAsJsonObject().get("data"); + if (data.isJsonArray()) { + for (JsonElement deckComment : data.getAsJsonArray()) { + comment.addComment(parseDeckComment(deckComment)); + } + } else { + comment.addComment(parseDeckComment(data)); } - } else { - comment.addComment(parseDeckComment(data)); - } + }, obj); return comment; } private static DeckComment parseDeckComment(JsonElement data) { DeckLog.verbose(data.toString()); - JsonObject commentJson = data.getAsJsonObject(); DeckComment deckComment = new DeckComment(); - deckComment.setId(commentJson.get("id").getAsLong()); - deckComment.setObjectId(commentJson.get("objectId").getAsLong()); - deckComment.setMessage(commentJson.get("message").getAsString()); - deckComment.setActorId(commentJson.get("actorId").getAsString()); - deckComment.setActorDisplayName(commentJson.get("actorDisplayName").getAsString()); - deckComment.setActorType(commentJson.get("actorType").getAsString()); - deckComment.setCreationDateTime(getTimestampFromString(commentJson.get("creationDateTime"))); + TraceableException.makeTraceableIfFails(() -> { + JsonObject commentJson = data.getAsJsonObject(); + + deckComment.setId(commentJson.get("id").getAsLong()); + deckComment.setObjectId(commentJson.get("objectId").getAsLong()); + deckComment.setMessage(commentJson.get("message").getAsString()); + deckComment.setActorId(commentJson.get("actorId").getAsString()); + deckComment.setActorDisplayName(commentJson.get("actorDisplayName").getAsString()); + deckComment.setActorType(commentJson.get("actorType").getAsString()); + deckComment.setCreationDateTime(getTimestampFromString(commentJson.get("creationDateTime"))); - if (commentJson.has("replyTo")){ + if (commentJson.has("replyTo")){ JsonObject replyTo = commentJson.get("replyTo").getAsJsonObject(); deckComment.setParentId(replyTo.get("id").getAsLong()); } @@ -94,7 +99,7 @@ public class JsonToEntityParser { for (JsonElement mention : mentions.getAsJsonArray()) { deckComment.addMention(parseMention(mention)); } - } + }}, data); return deckComment; } @@ -103,10 +108,13 @@ public class JsonToEntityParser { Mention mention = new Mention(); DeckLog.verbose(mentionJson.toString()); - JsonObject mentionObject = mentionJson.getAsJsonObject(); - mention.setMentionId(mentionObject.get("mentionId").getAsString()); - mention.setMentionType(mentionObject.get("mentionType").getAsString()); - mention.setMentionDisplayName(mentionObject.get("mentionDisplayName").getAsString()); + + TraceableException.makeTraceableIfFails(() -> { + JsonObject mentionObject = mentionJson.getAsJsonObject(); + mention.setMentionId(mentionObject.get("mentionId").getAsString()); + mention.setMentionType(mentionObject.get("mentionType").getAsString()); + mention.setMentionDisplayName(mentionObject.get("mentionDisplayName").getAsString()); + }, mentionJson); return mention; } @@ -117,75 +125,78 @@ public class JsonToEntityParser { DeckLog.verbose(e.toString()); Board board = new Board(); - board.setTitle(getNullAsEmptyString(e.get("title"))); - board.setColor(getNullAsEmptyString(e.get("color"))); - board.setArchived(e.get("archived").getAsBoolean()); - - board.setLastModified(getTimestampFromLong(e.get("lastModified"))); - board.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); - board.setId(e.get("id").getAsLong()); - fullBoard.setBoard(board); - - if (e.has("labels") && !e.get("labels").isJsonNull()) { - JsonArray labelsJson = e.getAsJsonArray("labels"); - List<Label> labels = new ArrayList<>(); - for (JsonElement labelJson : labelsJson) { - labels.add(parseLabel(labelJson.getAsJsonObject())); - } - fullBoard.setLabels(labels); - } - if (e.has("stacks") && !e.get("stacks").isJsonNull()) { - JsonArray stacksJson = e.getAsJsonArray("stacks"); - List<Stack> stacks = new ArrayList<>(); - for (JsonElement stackJson : stacksJson) { - stacks.add(parseStack(stackJson.getAsJsonObject()).getStack()); + TraceableException.makeTraceableIfFails(() -> { + board.setTitle(getNullAsEmptyString(e.get("title"))); + board.setColor(getNullAsEmptyString(e.get("color"))); + board.setArchived(e.get("archived").getAsBoolean()); + + board.setLastModified(getTimestampFromLong(e.get("lastModified"))); + board.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); + board.setId(e.get("id").getAsLong()); + fullBoard.setBoard(board); + + if (e.has("labels") && !e.get("labels").isJsonNull()) { + JsonArray labelsJson = e.getAsJsonArray("labels"); + List<Label> labels = new ArrayList<>(); + for (JsonElement labelJson : labelsJson) { + labels.add(parseLabel(labelJson.getAsJsonObject())); + } + fullBoard.setLabels(labels); } - fullBoard.setStacks(stacks); - } - if (e.has("acl") && !e.get("acl").isJsonNull()) { - JsonElement assignedUsers = e.get("acl"); - if (assignedUsers.isJsonArray() && assignedUsers.getAsJsonArray().size() > 0) { - JsonArray assignedUsersArray = assignedUsers.getAsJsonArray(); - - List<AccessControl> acl = new ArrayList<>(); - for (JsonElement aclElement : assignedUsersArray) { - acl.add(parseAcl(aclElement.getAsJsonObject())); + if (e.has("stacks") && !e.get("stacks").isJsonNull()) { + JsonArray stacksJson = e.getAsJsonArray("stacks"); + List<Stack> stacks = new ArrayList<>(); + for (JsonElement stackJson : stacksJson) { + stacks.add(parseStack(stackJson.getAsJsonObject()).getStack()); } - fullBoard.setParticipants(acl); + fullBoard.setStacks(stacks); } - } + if (e.has("acl") && !e.get("acl").isJsonNull()) { + JsonElement assignedUsers = e.get("acl"); + if (assignedUsers.isJsonArray() && assignedUsers.getAsJsonArray().size() > 0) { + JsonArray assignedUsersArray = assignedUsers.getAsJsonArray(); + + List<AccessControl> acl = new ArrayList<>(); + for (JsonElement aclElement : assignedUsersArray) { + acl.add(parseAcl(aclElement.getAsJsonObject())); + } + fullBoard.setParticipants(acl); + } - if (e.has("permissions")) { - JsonElement permissions = e.get("permissions"); - JsonObject permissionsObject = permissions.getAsJsonObject(); - if (permissionsObject.has("PERMISSION_READ")) { - JsonElement read = permissionsObject.get("PERMISSION_READ"); - fullBoard.getBoard().setPermissionRead(read.getAsBoolean()); - } - if (permissionsObject.has("PERMISSION_EDIT")) { - JsonElement read = permissionsObject.get("PERMISSION_EDIT"); - fullBoard.getBoard().setPermissionEdit(read.getAsBoolean()); - } - if (permissionsObject.has("PERMISSION_MANAGE")) { - JsonElement read = permissionsObject.get("PERMISSION_MANAGE"); - fullBoard.getBoard().setPermissionManage(read.getAsBoolean()); } - if (permissionsObject.has("PERMISSION_SHARE")) { - JsonElement read = permissionsObject.get("PERMISSION_SHARE"); - fullBoard.getBoard().setPermissionShare(read.getAsBoolean()); + + if (e.has("permissions")) { + JsonElement permissions = e.get("permissions"); + JsonObject permissionsObject = permissions.getAsJsonObject(); + if (permissionsObject.has("PERMISSION_READ")) { + JsonElement read = permissionsObject.get("PERMISSION_READ"); + fullBoard.getBoard().setPermissionRead(read.getAsBoolean()); + } + if (permissionsObject.has("PERMISSION_EDIT")) { + JsonElement read = permissionsObject.get("PERMISSION_EDIT"); + fullBoard.getBoard().setPermissionEdit(read.getAsBoolean()); + } + if (permissionsObject.has("PERMISSION_MANAGE")) { + JsonElement read = permissionsObject.get("PERMISSION_MANAGE"); + fullBoard.getBoard().setPermissionManage(read.getAsBoolean()); + } + if (permissionsObject.has("PERMISSION_SHARE")) { + JsonElement read = permissionsObject.get("PERMISSION_SHARE"); + fullBoard.getBoard().setPermissionShare(read.getAsBoolean()); + } } - } - JsonElement owner = e.get("owner"); - if (owner != null) { - if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! - DeckLog.verbose("owner is Primitive, skipping"); - } else - fullBoard.setOwner(parseUser(owner.getAsJsonObject())); - } + JsonElement owner = e.get("owner"); + if (owner != null) { + if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! + DeckLog.verbose("owner is Primitive, skipping"); + } else + fullBoard.setOwner(parseUser(owner.getAsJsonObject())); + } + }, e); return fullBoard; } @@ -194,16 +205,18 @@ public class JsonToEntityParser { AccessControl acl = new AccessControl(); if (aclJson.has("participant") && !aclJson.get("participant").isJsonNull()) { - User participant = parseUser(aclJson.get("participant").getAsJsonObject()); - acl.setUser(participant); - acl.setType(aclJson.get("type").getAsLong()); - acl.setBoardId(aclJson.get("boardId").getAsLong()); - acl.setId(aclJson.get("id").getAsLong()); - - acl.setOwner(aclJson.get("owner").getAsBoolean()); - acl.setPermissionEdit(aclJson.get("permissionEdit").getAsBoolean()); - acl.setPermissionManage(aclJson.get("permissionManage").getAsBoolean()); - acl.setPermissionShare(aclJson.get("permissionShare").getAsBoolean()); + TraceableException.makeTraceableIfFails(() -> { + User participant = parseUser(aclJson.get("participant").getAsJsonObject()); + acl.setUser(participant); + acl.setType(aclJson.get("type").getAsLong()); + acl.setBoardId(aclJson.get("boardId").getAsLong()); + acl.setId(aclJson.get("id").getAsLong()); + + acl.setOwner(aclJson.get("owner").getAsBoolean()); + acl.setPermissionEdit(aclJson.get("permissionEdit").getAsBoolean()); + acl.setPermissionManage(aclJson.get("permissionManage").getAsBoolean()); + acl.setPermissionShare(aclJson.get("permissionShare").getAsBoolean()); + }, aclJson); } @@ -215,62 +228,64 @@ public class JsonToEntityParser { FullCard fullCard = new FullCard(); Card card = new Card(); fullCard.setCard(card); - card.setId(e.get("id").getAsLong()); - card.setTitle(getNullAsEmptyString(e.get("title"))); - card.setDescription(getNullAsEmptyString(e.get("description"))); - card.setStackId(e.get("stackId").getAsLong()); - card.setType(getNullAsEmptyString(e.get("type"))); - card.setLastModified(getTimestampFromLong(e.get("lastModified"))); - card.setCreatedAt(getTimestampFromLong(e.get("createdAt"))); - card.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); - if (e.has("labels") && !e.get("labels").isJsonNull()) { - JsonArray labelsJson = e.getAsJsonArray("labels"); - List<Label> labels = new ArrayList<>(); - for (JsonElement labelJson : labelsJson) { - labels.add(parseLabel(labelJson.getAsJsonObject())); + TraceableException.makeTraceableIfFails(() -> { + card.setId(e.get("id").getAsLong()); + card.setTitle(getNullAsEmptyString(e.get("title"))); + card.setDescription(getNullAsEmptyString(e.get("description"))); + card.setStackId(e.get("stackId").getAsLong()); + card.setType(getNullAsEmptyString(e.get("type"))); + card.setLastModified(getTimestampFromLong(e.get("lastModified"))); + card.setCreatedAt(getTimestampFromLong(e.get("createdAt"))); + card.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); + if (e.has("labels") && !e.get("labels").isJsonNull()) { + JsonArray labelsJson = e.getAsJsonArray("labels"); + List<Label> labels = new ArrayList<>(); + for (JsonElement labelJson : labelsJson) { + labels.add(parseLabel(labelJson.getAsJsonObject())); + } + fullCard.setLabels(labels); } - fullCard.setLabels(labels); - } - if (e.has("assignedUsers") && !e.get("assignedUsers").isJsonNull()) { - JsonArray assignedUsers = e.getAsJsonArray("assignedUsers"); + if (e.has("assignedUsers") && !e.get("assignedUsers").isJsonNull()) { + JsonArray assignedUsers = e.getAsJsonArray("assignedUsers"); - List<User> users = new ArrayList<>(); - for (JsonElement assignedUser : assignedUsers) { - JsonObject userJson = assignedUser.getAsJsonObject(); - if (userJson.has("participant") && !userJson.get("participant").isJsonNull()) { - users.add(parseUser(userJson.get("participant").getAsJsonObject())); + List<User> users = new ArrayList<>(); + for (JsonElement assignedUser : assignedUsers) { + JsonObject userJson = assignedUser.getAsJsonObject(); + if (userJson.has("participant") && !userJson.get("participant").isJsonNull()) { + users.add(parseUser(userJson.get("participant").getAsJsonObject())); + } } + fullCard.setAssignedUsers(users); } - fullCard.setAssignedUsers(users); - } - if (e.has("attachments") && !e.get("attachments").isJsonNull()) { - JsonArray attachmentsJson = e.getAsJsonArray("attachments"); + if (e.has("attachments") && !e.get("attachments").isJsonNull()) { + JsonArray attachmentsJson = e.getAsJsonArray("attachments"); - List<Attachment> attachments = new ArrayList<>(); - for (JsonElement att : attachmentsJson) { - JsonObject attachmentJson = att.getAsJsonObject(); - attachments.add(parseAttachment(attachmentJson)); + List<Attachment> attachments = new ArrayList<>(); + for (JsonElement att : attachmentsJson) { + JsonObject attachmentJson = att.getAsJsonObject(); + attachments.add(parseAttachment(attachmentJson)); + } + fullCard.setAttachments(attachments); } - fullCard.setAttachments(attachments); - } - if (e.has("attachmentCount") && !e.get("attachmentCount").isJsonNull()) { - card.setAttachmentCount(e.get("attachmentCount").getAsInt()); - } + if (e.has("attachmentCount") && !e.get("attachmentCount").isJsonNull()) { + card.setAttachmentCount(e.get("attachmentCount").getAsInt()); + } - card.setOrder(e.get("order").getAsInt()); - card.setOverdue(e.get("overdue").getAsInt()); - card.setDueDate(getTimestampFromString(e.get("duedate"))); - card.setCommentsUnread(e.get("commentsUnread").getAsInt()); - JsonElement owner = e.get("owner"); - if (owner != null) { - if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! - DeckLog.verbose("owner is Primitive, skipping"); - } else - fullCard.setOwner(parseUser(owner.getAsJsonObject())); - } - card.setArchived(e.get("archived").getAsBoolean()); + card.setOrder(e.get("order").getAsInt()); + card.setOverdue(e.get("overdue").getAsInt()); + card.setDueDate(getTimestampFromString(e.get("duedate"))); + card.setCommentsUnread(e.get("commentsUnread").getAsInt()); + JsonElement owner = e.get("owner"); + if (owner != null) { + if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! + DeckLog.verbose("owner is Primitive, skipping"); + } else + fullCard.setOwner(parseUser(owner.getAsJsonObject())); + } + card.setArchived(e.get("archived").getAsBoolean()); + }, e); return fullCard; } @@ -278,28 +293,30 @@ public class JsonToEntityParser { protected static Attachment parseAttachment(JsonObject e) { DeckLog.verbose(e.toString()); Attachment a = new Attachment(); - a.setId(e.get("id").getAsLong()); - a.setCardId(e.get("cardId").getAsLong()); - a.setType(e.get("type").getAsString()); - a.setData(e.get("data").getAsString()); - a.setLastModified(getTimestampFromLong(e.get("lastModified"))); - a.setCreatedAt(getTimestampFromLong(e.get("createdAt"))); - a.setCreatedBy(e.get("createdBy").getAsString()); - a.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); - if (e.has("extendedData") && !e.get("extendedData").isJsonNull()) { - JsonObject extendedData = e.getAsJsonObject("extendedData").getAsJsonObject(); - a.setFilesize(extendedData.get("filesize").getAsLong()); - a.setMimetype(extendedData.get("mimetype").getAsString()); - if (extendedData.has("info") && !extendedData.get("info").isJsonNull()) { - JsonObject info = extendedData.getAsJsonObject("info").getAsJsonObject(); - a.setDirname(info.get("dirname").getAsString()); - a.setBasename(info.get("basename").getAsString()); - if (info.has("extension")) { - a.setExtension(info.get("extension").getAsString()); + TraceableException.makeTraceableIfFails(() -> { + a.setId(e.get("id").getAsLong()); + a.setCardId(e.get("cardId").getAsLong()); + a.setType(e.get("type").getAsString()); + a.setData(e.get("data").getAsString()); + a.setLastModified(getTimestampFromLong(e.get("lastModified"))); + a.setCreatedAt(getTimestampFromLong(e.get("createdAt"))); + a.setCreatedBy(e.get("createdBy").getAsString()); + a.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); + if (e.has("extendedData") && !e.get("extendedData").isJsonNull()) { + JsonObject extendedData = e.getAsJsonObject("extendedData").getAsJsonObject(); + a.setFilesize(extendedData.get("filesize").getAsLong()); + a.setMimetype(extendedData.get("mimetype").getAsString()); + if (extendedData.has("info") && !extendedData.get("info").isJsonNull()) { + JsonObject info = extendedData.getAsJsonObject("info").getAsJsonObject(); + a.setDirname(info.get("dirname").getAsString()); + a.setBasename(info.get("basename").getAsString()); + if (info.has("extension")) { + a.setExtension(info.get("extension").getAsString()); + } + a.setFilename(info.get("filename").getAsString()); } - a.setFilename(info.get("filename").getAsString()); } - } + }, e); return a; } @@ -307,9 +324,11 @@ public class JsonToEntityParser { protected static User parseUser(JsonObject e) { DeckLog.verbose(e.toString()); User user = new User(); - user.setDisplayname(getNullAsEmptyString(e.get("displayname"))); - user.setPrimaryKey(getNullAsEmptyString(e.get("primaryKey"))); - user.setUid(getNullAsEmptyString(e.get("uid"))); + TraceableException.makeTraceableIfFails(() -> { + user.setDisplayname(getNullAsEmptyString(e.get("displayname"))); + user.setPrimaryKey(getNullAsEmptyString(e.get("primaryKey"))); + user.setUid(getNullAsEmptyString(e.get("uid"))); + }, e); return user; } @@ -317,7 +336,7 @@ public class JsonToEntityParser { protected static Capabilities parseCapabilities(JsonObject e) { DeckLog.verbose(e.toString()); Capabilities capabilities = new Capabilities(); - + // not traceable, we need the original DeckException for error handling if (e.has("ocs")) { JsonObject ocs = e.getAsJsonObject("ocs"); if (ocs.has("meta")) { @@ -371,24 +390,26 @@ public class JsonToEntityParser { DeckLog.verbose(e.toString()); List<Activity> activityList = new ArrayList<>(); - if (e.has("ocs")) { - JsonObject ocs = e.getAsJsonObject("ocs"); - if (ocs.has("data")) { - JsonArray data = ocs.getAsJsonArray("data"); - for (JsonElement activityJson : data) { - Activity activity = new Activity(); - JsonObject activityObject = activityJson.getAsJsonObject(); - - activity.setId(activityObject.get("activity_id").getAsLong()); - activity.setType(ActivityType.findByPath(getNullAsEmptyString(activityObject.get("icon"))).getId()); - activity.setSubject(getNullAsEmptyString(activityObject.get("subject"))); - activity.setCardId(activityObject.get("object_id").getAsLong()); - activity.setLastModified(getTimestampFromString(activityObject.get("datetime"))); - - activityList.add(activity); + TraceableException.makeTraceableIfFails(() -> { + if (e.has("ocs")) { + JsonObject ocs = e.getAsJsonObject("ocs"); + if (ocs.has("data")) { + JsonArray data = ocs.getAsJsonArray("data"); + for (JsonElement activityJson : data) { + Activity activity = new Activity(); + JsonObject activityObject = activityJson.getAsJsonObject(); + + activity.setId(activityObject.get("activity_id").getAsLong()); + activity.setType(ActivityType.findByPath(getNullAsEmptyString(activityObject.get("icon"))).getId()); + activity.setSubject(getNullAsEmptyString(activityObject.get("subject"))); + activity.setCardId(activityObject.get("object_id").getAsLong()); + activity.setLastModified(getTimestampFromString(activityObject.get("datetime"))); + + activityList.add(activity); + } } } - } + }, e); return activityList; } @@ -396,37 +417,41 @@ public class JsonToEntityParser { DeckLog.verbose(e.toString()); FullStack fullStack = new FullStack(); Stack stack = new Stack(); - stack.setTitle(getNullAsEmptyString(e.get("title"))); - stack.setBoardId(e.get("boardId").getAsLong()); - stack.setId(e.get("id").getAsLong()); - stack.setLastModified(getTimestampFromLong(e.get("lastModified"))); - stack.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); - if (e.has("order") && !e.get("order").isJsonNull()) { - stack.setOrder(e.get("order").getAsInt()); - } else { - stack.setOrder(0); - } - if (e.has("cards")) { - JsonArray cardsJson = e.getAsJsonArray("cards"); - List<Card> cards = new ArrayList<>(); - for (JsonElement cardJson : cardsJson) { - cards.add(parseCard(cardJson.getAsJsonObject()).getCard()); - } - fullStack.setCards(cards); - } fullStack.setStack(stack); - stack.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); + TraceableException.makeTraceableIfFails(() -> { + stack.setTitle(getNullAsEmptyString(e.get("title"))); + stack.setBoardId(e.get("boardId").getAsLong()); + stack.setId(e.get("id").getAsLong()); + stack.setLastModified(getTimestampFromLong(e.get("lastModified"))); + stack.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); + if (e.has("order") && !e.get("order").isJsonNull()) { + stack.setOrder(e.get("order").getAsInt()); + } else { + stack.setOrder(0); + } + if (e.has("cards")) { + JsonArray cardsJson = e.getAsJsonArray("cards"); + List<Card> cards = new ArrayList<>(); + for (JsonElement cardJson : cardsJson) { + cards.add(parseCard(cardJson.getAsJsonObject()).getCard()); + } + fullStack.setCards(cards); + } + stack.setDeletedAt(getTimestampFromLong(e.get("deletedAt"))); + }, e); return fullStack; } protected static Label parseLabel(JsonObject e) { DeckLog.verbose(e.toString()); Label label = new Label(); - label.setId(e.get("id").getAsLong()); - //todo: last modified! -// label.setLastModified(get); - label.setTitle(getNullAsEmptyString(e.get("title"))); - label.setColor(getNullAsEmptyString(e.get("color"))); + TraceableException.makeTraceableIfFails(() -> { + label.setId(e.get("id").getAsLong()); + //todo: last modified! +// label.setLastModified(get); + label.setTitle(getNullAsEmptyString(e.get("title"))); + label.setColor(getNullAsEmptyString(e.get("color"))); + }, e); return label; } |