Skip to content

Commit

Permalink
#359 more efficient etag-null handling
Browse files Browse the repository at this point in the history
  • Loading branch information
desperateCoder authored and stefan-niedermann committed Nov 22, 2020
1 parent 727a31e commit 0ec2892
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected static FullBoard parseBoard(JsonObject e) {
makeTraceableIfFails(() -> {
board.setTitle(getNullAsEmptyString(e.get("title")));
board.setColor(getNullAsEmptyString(e.get("color")));
board.setEtag(getNullAsEmptyString(e.get("ETag")));
board.setEtag(getNullAsNull(e.get("ETag")));
board.setArchived(e.get("archived").getAsBoolean());

board.setLastModified(getTimestampFromLong(e.get("lastModified")));
Expand Down Expand Up @@ -397,7 +397,7 @@ protected static FullCard parseCard(JsonObject e) {
card.setDescription(getNullAsEmptyString(e.get("description")));
card.setStackId(e.get("stackId").getAsLong());
card.setType(getNullAsEmptyString(e.get("type")));
card.setEtag(getNullAsEmptyString(e.get("ETag")));
card.setEtag(getNullAsNull(e.get("ETag")));
card.setLastModified(getTimestampFromLong(e.get("lastModified")));
card.setCreatedAt(getTimestampFromLong(e.get("createdAt")));
card.setDeletedAt(getTimestampFromLong(e.get("deletedAt")));
Expand Down Expand Up @@ -458,7 +458,7 @@ protected static Attachment parseAttachment(JsonObject e) {
a.setId(e.get("id").getAsLong());
a.setCardId(e.get("cardId").getAsLong());
a.setType(e.get("type").getAsString());
a.setEtag(getNullAsEmptyString(e.get("ETag")));
a.setEtag(getNullAsNull(e.get("ETag")));
a.setData(e.get("data").getAsString());
a.setLastModified(getTimestampFromLong(e.get("lastModified")));
a.setCreatedAt(getTimestampFromLong(e.get("createdAt")));
Expand Down Expand Up @@ -583,7 +583,7 @@ protected static FullStack parseStack(JsonObject e) {
stack.setTitle(getNullAsEmptyString(e.get("title")));
stack.setBoardId(e.get("boardId").getAsLong());
stack.setId(e.get("id").getAsLong());
stack.setEtag(getNullAsEmptyString(e.get("ETag")));
stack.setEtag(getNullAsNull(e.get("ETag")));
stack.setLastModified(getTimestampFromLong(e.get("lastModified")));
stack.setDeletedAt(getTimestampFromLong(e.get("deletedAt")));
if (e.has("order") && !e.get("order").isJsonNull()) {
Expand Down Expand Up @@ -621,7 +621,7 @@ protected static List<Activity> parseActivity(JsonObject e) {
activity.setType(ActivityType.findByPath(getNullAsEmptyString(activityObject.get("icon"))).getId());
activity.setSubject(getNullAsEmptyString(activityObject.get("subject")));
activity.setCardId(activityObject.get("object_id").getAsLong());
activity.setEtag(getNullAsEmptyString(e.get("ETag")));
activity.setEtag(getNullAsNull(e.get("ETag")));
activity.setLastModified(getTimestampFromString(activityObject.get("datetime")));

activityList.add(activity);
Expand All @@ -640,7 +640,7 @@ protected static Label parseLabel(JsonObject e) {
//todo: last modified!
// label.setLastModified(get);
label.setTitle(getNullAsEmptyString(e.get("title")));
label.setEtag(getNullAsEmptyString(e.get("ETag")));
label.setEtag(getNullAsNull(e.get("ETag")));
label.setColor(getColorAsInt(e, "color"));
}, e);
return label;
Expand All @@ -650,6 +650,10 @@ private static String getNullAsEmptyString(JsonElement jsonElement) {
return jsonElement == null || jsonElement.isJsonNull() ? "" : jsonElement.getAsString();
}

private static String getNullAsNull(JsonElement jsonElement) {
return jsonElement == null || jsonElement.isJsonNull() ? null : jsonElement.getAsString();
}

private static Instant getTimestampFromString(JsonElement jsonElement) {
if (jsonElement.isJsonNull()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onResponse(List<T> response) {
DeckLog.log("Conflicting changes on entity: " + existingEntity);
// TODO: what to do?
} else {
if (entityFromServer.getEtag() != null && !entityFromServer.getEtag().trim().isEmpty() && entityFromServer.getEtag().equals(existingEntity.getEtag())) {
if (entityFromServer.getEtag() != null && entityFromServer.getEtag().equals(existingEntity.getEtag())) {
DeckLog.info("["+provider.getClass().getSimpleName()+"] ETags do match! skipping Entitiy with localId: "+existingEntity.getLocalId());
continue;
}
Expand Down

0 comments on commit 0ec2892

Please sign in to comment.