Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

Commit 58128cf

Browse files
authored
[jtx] Add builders for non-content properties (#386)
* Add `CollectionIdBuilder` * Add `SyncPropertiesBuilder` * Add `DirtyAndDeletedBuilder`
1 parent 8838945 commit 58128cf

8 files changed

Lines changed: 185 additions & 3 deletions

File tree

lib/src/main/kotlin/at/bitfire/synctools/mapping/jtx/JtxItemBuilder.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ package at.bitfire.synctools.mapping.jtx
99
import android.content.ContentValues
1010
import android.content.Entity
1111
import at.bitfire.synctools.icalendar.AssociatedComponents
12-
import at.bitfire.synctools.mapping.jtx.builder.JtxEntityBuilder
12+
import at.bitfire.synctools.mapping.jtx.builder.CollectionIdBuilder
1313
import at.bitfire.synctools.mapping.jtx.builder.DescriptionBuilder
14+
import at.bitfire.synctools.mapping.jtx.builder.JtxEntityBuilder
15+
import at.bitfire.synctools.mapping.jtx.builder.SyncPropertiesBuilder
1416
import at.bitfire.synctools.storage.jtx.JtxItemAndExceptions
1517
import net.fortuna.ical4j.model.component.CalendarComponent
1618
import net.fortuna.ical4j.model.component.VJournal
@@ -19,9 +21,18 @@ import net.fortuna.ical4j.model.component.VToDo
1921
/**
2022
* Mapper from an [AssociatedComponents] data object to jtx Board content provider data rows.
2123
*/
22-
class JtxItemBuilder {
24+
class JtxItemBuilder(
25+
collectionId: Long,
26+
fileName: String?,
27+
eTag: String?,
28+
scheduleTag: String?,
29+
flags: Int
30+
) {
2331

2432
private val fieldBuilders: Array<JtxEntityBuilder> = arrayOf(
33+
CollectionIdBuilder(collectionId),
34+
SyncPropertiesBuilder(fileName, eTag, scheduleTag, flags),
35+
2536
DescriptionBuilder()
2637
)
2738

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.jtx.builder
8+
9+
import android.content.Entity
10+
import at.techbee.jtx.JtxContract
11+
import net.fortuna.ical4j.model.component.CalendarComponent
12+
13+
class CollectionIdBuilder(private val collectionId: Long) : JtxEntityBuilder {
14+
override fun build(from: CalendarComponent, main: CalendarComponent, to: Entity) {
15+
to.entityValues.put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, collectionId)
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.jtx.builder
8+
9+
import android.content.Entity
10+
import at.techbee.jtx.JtxContract
11+
import net.fortuna.ical4j.model.component.CalendarComponent
12+
13+
class DirtyAndDeletedBuilder : JtxEntityBuilder {
14+
override fun build(from: CalendarComponent, main: CalendarComponent, to: Entity) {
15+
// DIRTY and DELETED is always unset when we create or update an event row
16+
to.entityValues.put(JtxContract.JtxICalObject.DIRTY, false)
17+
to.entityValues.put(JtxContract.JtxICalObject.DELETED, false)
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.jtx.builder
8+
9+
import android.content.Entity
10+
import at.techbee.jtx.JtxContract
11+
import net.fortuna.ical4j.model.component.CalendarComponent
12+
13+
class SyncPropertiesBuilder(
14+
private val fileName: String?,
15+
private val eTag: String?,
16+
private val scheduleTag: String?,
17+
private val flags: Int
18+
) : JtxEntityBuilder {
19+
20+
override fun build(from: CalendarComponent, main: CalendarComponent, to: Entity) {
21+
to.entityValues.put(JtxContract.JtxICalObject.FILENAME, fileName)
22+
to.entityValues.put(JtxContract.JtxICalObject.ETAG, eTag)
23+
to.entityValues.put(JtxContract.JtxICalObject.SCHEDULETAG, scheduleTag)
24+
to.entityValues.put(JtxContract.JtxICalObject.FLAGS, flags)
25+
}
26+
}

lib/src/test/kotlin/at/bitfire/synctools/mapping/jtx/JtxItemBuilderTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ import java.time.Instant
2525
@RunWith(RobolectricTestRunner::class)
2626
class JtxItemBuilderTest {
2727

28-
private val builder = JtxItemBuilder()
28+
private val builder = JtxItemBuilder(
29+
collectionId = 1,
30+
fileName = null,
31+
eTag = null,
32+
scheduleTag = null,
33+
flags = 0
34+
)
2935

3036
@Test
3137
fun `build() with VToDo`() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.jtx.builder
8+
9+
import android.content.ContentValues
10+
import android.content.Entity
11+
import at.techbee.jtx.JtxContract
12+
import net.fortuna.ical4j.model.component.VJournal
13+
import org.junit.Assert.assertEquals
14+
import org.junit.Test
15+
import org.junit.runner.RunWith
16+
import org.robolectric.RobolectricTestRunner
17+
18+
@RunWith(RobolectricTestRunner::class)
19+
class CollectionIdBuilderTest {
20+
21+
@Test
22+
fun happyPath() {
23+
val builder = CollectionIdBuilder(collectionId = 1L)
24+
val output = Entity(ContentValues())
25+
val journal = VJournal()
26+
27+
builder.build(from = journal, main = journal, output)
28+
29+
assertEquals(1L, output.entityValues.get(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID))
30+
}
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.jtx.builder
8+
9+
import android.content.ContentValues
10+
import android.content.Entity
11+
import at.techbee.jtx.JtxContract
12+
import net.fortuna.ical4j.model.component.VJournal
13+
import org.junit.Assert.*
14+
import org.junit.Test
15+
import org.junit.runner.RunWith
16+
import org.robolectric.RobolectricTestRunner
17+
18+
@RunWith(RobolectricTestRunner::class)
19+
class DirtyAndDeletedBuilderTest {
20+
21+
private val builder = DirtyAndDeletedBuilder()
22+
23+
@Test
24+
fun happyPath() {
25+
val output = Entity(ContentValues())
26+
val journal = VJournal()
27+
28+
builder.build(from = journal, main = journal, output)
29+
30+
assertEquals(false, output.entityValues.get(JtxContract.JtxICalObject.DIRTY))
31+
assertEquals(false, output.entityValues.get(JtxContract.JtxICalObject.DELETED))
32+
}
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.jtx.builder
8+
9+
import android.content.ContentValues
10+
import android.content.Entity
11+
import at.techbee.jtx.JtxContract
12+
import net.fortuna.ical4j.model.component.VJournal
13+
import org.junit.Assert.assertEquals
14+
import org.junit.Test
15+
import org.junit.runner.RunWith
16+
import org.robolectric.RobolectricTestRunner
17+
18+
@RunWith(RobolectricTestRunner::class)
19+
class SyncPropertiesBuilderTest {
20+
21+
@Test
22+
fun happyPath() {
23+
val builder = SyncPropertiesBuilder(
24+
fileName = "filename",
25+
eTag = "etag",
26+
scheduleTag = "scheduletag",
27+
flags = 0
28+
)
29+
val output = Entity(ContentValues())
30+
val journal = VJournal()
31+
32+
builder.build(from = journal, main = journal, output)
33+
34+
assertEquals("filename", output.entityValues.get(JtxContract.JtxICalObject.FILENAME))
35+
assertEquals("etag", output.entityValues.get(JtxContract.JtxICalObject.ETAG))
36+
assertEquals("scheduletag", output.entityValues.get(JtxContract.JtxICalObject.SCHEDULETAG))
37+
assertEquals(0, output.entityValues.get(JtxContract.JtxICalObject.FLAGS))
38+
}
39+
}

0 commit comments

Comments
 (0)