-
Notifications
You must be signed in to change notification settings - Fork 4
Event processor: create processor interface #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rfc2822
merged 7 commits into
main
from
74-split-processor-into-field-processor-classes
Sep 22, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
64aca54
Add AttendeesProcessor
rfc2822 c81479f
Add UidProcessor
rfc2822 24dcc85
Add RemindersProcessor
rfc2822 fd8f1ec
Fix typo
rfc2822 5fde697
Also provide main Entity to processors
rfc2822 f283121
Indenting
rfc2822 3654075
Fix processor calls + tests
rfc2822 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
357 changes: 0 additions & 357 deletions
357
...droidTest/kotlin/at/bitfire/synctools/mapping/calendar/LegacyAndroidEventProcessorTest.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...main/kotlin/at/bitfire/synctools/mapping/calendar/processor/AndroidEventFieldProcessor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * This file is part of bitfireAT/synctools which is released under GPLv3. | ||
| * Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details. | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package at.bitfire.synctools.mapping.calendar.processor | ||
|
|
||
| import android.content.Entity | ||
| import at.bitfire.ical4android.Event | ||
|
|
||
| interface AndroidEventFieldProcessor { | ||
|
|
||
| /** | ||
| * Takes specific data from an event (= event row plus data rows, taken from the content provider) | ||
| * and maps it to the [Event] data class. | ||
| * | ||
| * If [from] references the same object as [main], this method is called for a main event (not an exception). | ||
| * If [from] references another object as [main], this method is called for an exception (not a main event). | ||
| * | ||
| * So you can use (note the referential equality operator): | ||
| * | ||
| * ``` | ||
| * val isMainEvent = from === main // or | ||
| * val isException = from !== main | ||
| * ``` | ||
| * | ||
| * In a later step of refactoring, it should map to [net.fortuna.ical4j.model.component.VEvent]. | ||
| * | ||
| * @param from event from content provider | ||
| * @param main main event from content provider | ||
| * @param to destination object where the mapped data are stored | ||
| */ | ||
| fun process(from: Entity, main: Entity, to: Event) | ||
|
|
||
| } | ||
75 changes: 75 additions & 0 deletions
75
lib/src/main/kotlin/at/bitfire/synctools/mapping/calendar/processor/AttendeesProcessor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * This file is part of bitfireAT/synctools which is released under GPLv3. | ||
| * Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details. | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package at.bitfire.synctools.mapping.calendar.processor | ||
|
|
||
| import android.content.ContentValues | ||
| import android.content.Entity | ||
| import android.provider.CalendarContract.Attendees | ||
| import at.bitfire.ical4android.Event | ||
| import at.bitfire.synctools.mapping.calendar.AttendeeMappings | ||
| import net.fortuna.ical4j.model.parameter.Cn | ||
| import net.fortuna.ical4j.model.parameter.Email | ||
| import net.fortuna.ical4j.model.parameter.PartStat | ||
| import net.fortuna.ical4j.model.parameter.Rsvp | ||
| import net.fortuna.ical4j.model.property.Attendee | ||
| import java.net.URI | ||
| import java.net.URISyntaxException | ||
| import java.util.logging.Level | ||
| import java.util.logging.Logger | ||
|
|
||
| class AttendeesProcessor: AndroidEventFieldProcessor { | ||
|
|
||
| private val logger | ||
| get() = Logger.getLogger(javaClass.name) | ||
|
|
||
| override fun process(from: Entity, main: Entity, to: Event) { | ||
| for (row in from.subValues.filter { it.uri == Attendees.CONTENT_URI }) | ||
| populateAttendee(row.values, to) | ||
| } | ||
|
|
||
| private fun populateAttendee(row: ContentValues, to: Event) { | ||
| logger.log(Level.FINE, "Read event attendee from calendar provider", row) | ||
|
|
||
| try { | ||
| val attendee: Attendee | ||
| val email = row.getAsString(Attendees.ATTENDEE_EMAIL) | ||
| val idNS = row.getAsString(Attendees.ATTENDEE_ID_NAMESPACE) | ||
| val id = row.getAsString(Attendees.ATTENDEE_IDENTITY) | ||
|
|
||
| if (idNS != null || id != null) { | ||
| // attendee identified by namespace and ID | ||
| attendee = Attendee(URI(idNS, id, null)) | ||
| email?.let { attendee.parameters.add(Email(it)) } | ||
| } else | ||
| // attendee identified by email address | ||
| attendee = Attendee(URI("mailto", email, null)) | ||
| val params = attendee.parameters | ||
|
|
||
| // always add RSVP (offer attendees to accept/decline) | ||
| params.add(Rsvp.TRUE) | ||
|
|
||
| row.getAsString(Attendees.ATTENDEE_NAME)?.let { cn -> params.add(Cn(cn)) } | ||
|
|
||
| // type/relation mapping is complex and thus outsourced to AttendeeMappings | ||
| AttendeeMappings.androidToICalendar(row, attendee) | ||
|
|
||
| // status | ||
| when (row.getAsInteger(Attendees.ATTENDEE_STATUS)) { | ||
| Attendees.ATTENDEE_STATUS_INVITED -> params.add(PartStat.NEEDS_ACTION) | ||
| Attendees.ATTENDEE_STATUS_ACCEPTED -> params.add(PartStat.ACCEPTED) | ||
| Attendees.ATTENDEE_STATUS_DECLINED -> params.add(PartStat.DECLINED) | ||
| Attendees.ATTENDEE_STATUS_TENTATIVE -> params.add(PartStat.TENTATIVE) | ||
| Attendees.ATTENDEE_STATUS_NONE -> { /* no information, don't add PARTSTAT */ } | ||
| } | ||
|
|
||
| to.attendees.add(attendee) | ||
| } catch (e: URISyntaxException) { | ||
| logger.log(Level.WARNING, "Couldn't parse attendee information, ignoring", e) | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.