}
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()
+ }
+ }
+ }
}
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
}
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()
})