Skip to content

Commit a1d00b0

Browse files
authored
Merge pull request #45 from HamburgChimps/look-for-data-in-all-mergeable-data-columns
Look for data in all mergeable data columns
2 parents 8d32d89 + 39cf322 commit a1d00b0

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/main/java/de/hamburgchimps/apple/notes/liberator/UserMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class UserMessages {
1010
public static final String EMBEDDED_OBJECT_PARSE_ERROR_IDENTIFIER_DOES_NOT_EXIST = String.format("%s there is no object with that identifier in notes database", EMBEDDED_OBJECT_PARSE_ERROR);
1111
public static final String EMBEDDED_OBJECT_PARSE_ERROR_NO_TYPE_IDENTIFIER = String.format("%s no type identifier present", EMBEDDED_OBJECT_PARSE_ERROR);
1212
public static final String TABLE_PARSE_ERROR_CANT_FIND_ROOT = "Failed to parse table: unable to find root table";
13+
public static final String TABLE_PARSE_ERROR_CANT_FIND_DATA = "Failed to parse table: unable to find data in expected columns";
1314
public static final String TABLE_PARSE_ERROR_CANT_PARSE_PROTO = "Failed to parse table";
1415
}

src/main/java/de/hamburgchimps/apple/notes/liberator/data/embedded/Table.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.google.protobuf.ByteString;
88
import com.google.protobuf.ProtocolStringList;
99
import de.hamburgchimps.apple.notes.liberator.ProtoUtils;
10+
import de.hamburgchimps.apple.notes.liberator.Result;
1011
import de.hamburgchimps.apple.notes.liberator.entity.NotesCloudObject;
1112
import io.quarkus.logging.Log;
1213

@@ -25,6 +26,7 @@
2526
import static de.hamburgchimps.apple.notes.liberator.Constants.TABLE_DIRECTION_KEY_NAME;
2627
import static de.hamburgchimps.apple.notes.liberator.Constants.TABLE_ROOT_IDENTIFIER;
2728
import static de.hamburgchimps.apple.notes.liberator.Constants.TABLE_ROWS_KEY_NAME;
29+
import static de.hamburgchimps.apple.notes.liberator.UserMessages.TABLE_PARSE_ERROR_CANT_FIND_DATA;
2830
import static de.hamburgchimps.apple.notes.liberator.UserMessages.TABLE_PARSE_ERROR_CANT_FIND_ROOT;
2931
import static de.hamburgchimps.apple.notes.liberator.UserMessages.TABLE_PARSE_ERROR_CANT_PARSE_PROTO;
3032
import static de.hamburgchimps.apple.notes.liberator.data.embedded.TableDirection.DIRECTION_IDENTIFIER_TO_DIRECTION;
@@ -56,15 +58,25 @@ public class Table implements EmbeddedObjectData {
5658
private final List<RuntimeException> errors = new ArrayList<>();
5759

5860
public Table(NotesCloudObject notesCloudObject) {
59-
var result = ProtoUtils.parseProtoUsingParserFromBytes(MergableDataProto.parser(), notesCloudObject.zMergeableData);
61+
var mergeableDataResult = getMergeableData(notesCloudObject);
6062

61-
if (result.isError()) {
62-
Log.error(TABLE_PARSE_ERROR_CANT_PARSE_PROTO, result.error());
63-
this.errors.add(result.error());
63+
if (mergeableDataResult.isError()) {
64+
var error = mergeableDataResult.error();
65+
Log.error(TABLE_PARSE_ERROR_CANT_FIND_DATA, error);
66+
this.errors.add(error);
6467
return;
6568
}
6669

67-
var proto = result.get();
70+
var protoParseResult = ProtoUtils.parseProtoUsingParserFromBytes(MergableDataProto.parser(), mergeableDataResult.get());
71+
72+
if (protoParseResult.isError()) {
73+
var error = protoParseResult.error();
74+
Log.error(TABLE_PARSE_ERROR_CANT_PARSE_PROTO, error);
75+
this.errors.add(error);
76+
return;
77+
}
78+
79+
var proto = protoParseResult.get();
6880

6981
var data = proto
7082
.getMergableDataObject()
@@ -244,4 +256,20 @@ private void initParsed() {
244256
.mapToObj((i) -> new ArrayList<>(Collections.nCopies(this.numColumns, "")))
245257
.collect(Collectors.toList());
246258
}
259+
260+
private Result<byte[], RuntimeException> getMergeableData(NotesCloudObject notesCloudObject) {
261+
if (notesCloudObject.zMergeableData != null) {
262+
return Result.Ok(notesCloudObject.zMergeableData);
263+
}
264+
265+
if (notesCloudObject.zMergeableData1 != null) {
266+
return Result.Ok(notesCloudObject.zMergeableData1);
267+
}
268+
269+
if (notesCloudObject.zMergeableData2 != null) {
270+
return Result.Ok(notesCloudObject.zMergeableData2);
271+
}
272+
273+
return Result.Error(new RuntimeException("No data found in any of the expected columns"));
274+
}
247275
}

src/main/java/de/hamburgchimps/apple/notes/liberator/entity/NotesCloudObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ public class NotesCloudObject extends Base {
2525
public NotesCloudObject zFolder;
2626
public String zFileName;
2727
public byte[] zMergeableData;
28+
public byte[] zMergeableData1;
29+
public byte[] zMergeableData2;
2830
}

0 commit comments

Comments
 (0)