|
7 | 7 | import com.google.protobuf.ByteString; |
8 | 8 | import com.google.protobuf.ProtocolStringList; |
9 | 9 | import de.hamburgchimps.apple.notes.liberator.ProtoUtils; |
| 10 | +import de.hamburgchimps.apple.notes.liberator.Result; |
10 | 11 | import de.hamburgchimps.apple.notes.liberator.entity.NotesCloudObject; |
11 | 12 | import io.quarkus.logging.Log; |
12 | 13 |
|
|
25 | 26 | import static de.hamburgchimps.apple.notes.liberator.Constants.TABLE_DIRECTION_KEY_NAME; |
26 | 27 | import static de.hamburgchimps.apple.notes.liberator.Constants.TABLE_ROOT_IDENTIFIER; |
27 | 28 | 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; |
28 | 30 | import static de.hamburgchimps.apple.notes.liberator.UserMessages.TABLE_PARSE_ERROR_CANT_FIND_ROOT; |
29 | 31 | import static de.hamburgchimps.apple.notes.liberator.UserMessages.TABLE_PARSE_ERROR_CANT_PARSE_PROTO; |
30 | 32 | import static de.hamburgchimps.apple.notes.liberator.data.embedded.TableDirection.DIRECTION_IDENTIFIER_TO_DIRECTION; |
@@ -56,15 +58,25 @@ public class Table implements EmbeddedObjectData { |
56 | 58 | private final List<RuntimeException> errors = new ArrayList<>(); |
57 | 59 |
|
58 | 60 | public Table(NotesCloudObject notesCloudObject) { |
59 | | - var result = ProtoUtils.parseProtoUsingParserFromBytes(MergableDataProto.parser(), notesCloudObject.zMergeableData); |
| 61 | + var mergeableDataResult = getMergeableData(notesCloudObject); |
60 | 62 |
|
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); |
64 | 67 | return; |
65 | 68 | } |
66 | 69 |
|
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(); |
68 | 80 |
|
69 | 81 | var data = proto |
70 | 82 | .getMergableDataObject() |
@@ -244,4 +256,20 @@ private void initParsed() { |
244 | 256 | .mapToObj((i) -> new ArrayList<>(Collections.nCopies(this.numColumns, ""))) |
245 | 257 | .collect(Collectors.toList()); |
246 | 258 | } |
| 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 | + } |
247 | 275 | } |
0 commit comments