Skip to content

Commit

Permalink
add rudimentary link extraction for #24
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkolson committed Apr 8, 2023
1 parent a5741a6 commit 1aa1881
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import de.hamburgchimps.apple.notes.liberator.Constants;
import de.hamburgchimps.apple.notes.liberator.ProtoUtils;
import de.hamburgchimps.apple.notes.liberator.UserMessages;
import de.hamburgchimps.apple.notes.liberator.data.format.Link;
import de.hamburgchimps.apple.notes.liberator.entity.Note;
import de.hamburgchimps.apple.notes.liberator.entity.NotesCloudObject;
import io.quarkus.logging.Log;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -19,6 +21,7 @@ public class NoteData {
private String folder;
private String text;
private List<EmbeddedObjectData> embeddedObjects;
private List<Link> links = new ArrayList<>();
private NoteStoreProto proto;
private final List<RuntimeException> errors = new ArrayList<>();

Expand All @@ -37,21 +40,29 @@ public NoteData(Note n) {
this.folder = noteObject.zFolder.zTitle2;
this.text = this.getProtoNote().getNoteText();
this.parseEmbeddedObjects();
this.parseLinks();
}

public String getTitle() {
return title;
}

public String getFolder() {
return folder;
}

public String getText() {
return text;
}

public List<EmbeddedObjectData> getEmbeddedObjects() {
return embeddedObjects;
}

public List<Link> getLinks() {
return links;
}

@JsonIgnore
public List<RuntimeException> getErrors() {
return errors;
Expand Down Expand Up @@ -87,6 +98,8 @@ private Optional<EmbeddedObjectData> parseEmbeddedObject(Notestore.AttachmentInf
.firstResult();

if (notesCloudObject == null) {
// We are most likely dealing with a deleted note that has some dead references
// hanging around in the database still. There is not much we can do with these.
this.errors.add(new RuntimeException(String.format(UserMessages.EMBEDDED_OBJECT_PARSE_ERROR_IDENTIFIER_DOES_NOT_EXIST, identifier)));
return Optional.empty();
}
Expand All @@ -107,6 +120,19 @@ private Optional<EmbeddedObjectData> parseEmbeddedObject(Notestore.AttachmentInf
return Optional.of(new File(notesCloudObject));
}

private void parseLinks() {
// TODO this is hacky
var positionTracker = 0;

for (var attributeRun : this.getProtoNote().getAttributeRunList()) {
if (attributeRun.hasLink()) {
var endOfLinkText = positionTracker + attributeRun.getLength();
this.links.add(new Link(this.getText().substring(positionTracker, endOfLinkText), attributeRun.getLink()));
}
positionTracker += attributeRun.getLength();
}
}

private Notestore.Note getProtoNote() {
return this.proto.getDocument().getNote();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.hamburgchimps.apple.notes.liberator.data.format;

public record Link(String text, String url) { }
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ quarkus.hibernate-orm.validate-in-dev-mode=false

%debug.quarkus.log.category."de.hamburgchimps".level=DEBUG
%debug.quarkus.log.file.enable=true
%debug.quarkus.log.file.path=apple-notes-liberator.log
%debug.quarkus.log.file.path=liberated-notes/apple-notes-liberator.log

0 comments on commit 1aa1881

Please sign in to comment.