]> uap-core.de Git - rssreader.git/commitdiff
implement adding new feeds main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 15 Aug 2025 16:18:06 +0000 (18:18 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 15 Aug 2025 16:18:06 +0000 (18:18 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Feed.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
ui-java/src/main/java/de/unixwork/ui/UiList.java
ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt

index 9927d6520560d30eba10377400d3d87d4383d860..5d7603af458d2c7ac4c85aaea08fad0835c72b08 100644 (file)
@@ -134,4 +134,46 @@ object Database {
         }
         return FeedGroup(groupId, name)
     }
+
+    public fun newFeeds(
+        parent: FeedGroup,
+        name: String,
+        uris: Collection<String>,
+        user: String? = null,
+        password: String? = null,
+        cert: String? = null)
+    {
+        var feedcollectionId = -1
+        connection.prepareStatement("""
+            insert into feedcollections (group_id, pos, name) select ?, max(pos)+1, ? from groups
+        """.trimIndent()).use { stmt ->
+            stmt.setInt(1, parent.id)
+            stmt.setString(2, name)
+            stmt.execute()
+            stmt.generatedKeys.use { rs ->
+                if(rs.next()) {
+                    feedcollectionId = rs.getInt(1)
+                } else {
+                    throw Exception("Insert FeedCollection failed")
+                }
+            }
+        }
+
+        uris.forEach { uri ->
+            connection.prepareStatement("""
+                insert into feeds (feedcollection_id, url, user, password, certpath)
+                select ?, ?, ?, ?, ?
+                from dual
+                where not exists (select 1 from feeds where url = ?)
+            """.trimIndent()).use { stmt ->
+                stmt.setInt(1, feedcollectionId)
+                stmt.setString(2, uri)
+                stmt.setString(3, user)
+                stmt.setString(4, password)
+                stmt.setString(5, cert)
+
+                stmt.execute()
+            }
+        }
+    }
 }
index a098c698548242131d3ee2d8c2787bedf45635ff..7109d0ae222605e5c2db5c997e59e9c8d633bb13 100644 (file)
@@ -1,6 +1,11 @@
 package de.unixwork.rssreader
 
 
-class Feed(uri: String) {
+class Feed(id: Int, feedCollectionId: Int, uri: String) {
+    val id = id
+    val feedCollectionId = feedCollectionId
     val uri = uri
+    var user: String? = null
+    var password: String? = null
+    var certpath: String? = null
 }
index f41f3fee455a0d1be19ab8bf81b07ab4f15c26f9..a827416dc7e2a0f669c19247e2b43afd66cba2fd 100644 (file)
@@ -67,10 +67,14 @@ class MainWindow {
             showCloseButton = false,
             onClick = { ev ->
                 if(ev.intValue == 1) {
-                    val groupSel = groups?.selectedIndex
+                    val parent = groups?.selected
                     val feedName = name.toString()
                     val urlStr = urls.toString()
-                    println("groupSel: $groupSel, feedName: $feedName, urlStr: $urlStr")
+                    val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() }
+                    println("groupSel: ${groups?.selectedIndex}, feedName: $feedName, urlStr: $urlStr")
+                    parent?.let {
+                        Database.newFeeds(it, feedName, uris, user.toString(), password.toString(), cert.toString())
+                    }
                 }
                 ev.`object`.close()
             })
index 0fdce38d3f363d4cbe0ac3c3d4e83971c5629964..104d7f0fec8594a39dbe99489e629bc797b58f4c 100644 (file)
@@ -101,6 +101,14 @@ public class UiList<T> extends ArrayList<T> {
         return selection[0];
     }
 
+    public T getSelected() {
+        int index = getSelectedIndex();
+        if(index == -1) {
+            return null;
+        }
+        return get(index);
+    }
+
     public void free() {
         ToolkitFuncs tk = ToolkitFuncs.getInstance();
         try {
index a2ec59a156eb512dfb0dd156516bc88ec31fc64c..bccd7f2c24f05dd474e33c3a5a91e558109ea252 100644 (file)
@@ -1329,7 +1329,6 @@ class Toplevel(obj: UiObject) {
         rowspan: Int = -1,
         name: String? = null,
         styleClass: String? = null,
-
         ): UiWidget {
         labelStr?.let {
             label.label(it)