Commit e49c6994 authored by David's avatar David
Browse files

Stuf

parent b85a7dc4
Thumbs.db
.DS_Store
.gradle
build/
target/
out/
.idea
*.iml
*.ipr
*.iws
.project
.settings
.classpath
\ No newline at end of file
postgresql/
postgresql_data/
## Plan:
* OpenID Authentication via light.kow.is
* Staged documents API
Document IDs are UUID, so that they can be used in many locations
```text
GET /stage -- List of staged documents
GET /trash -- List of documents in the garbage
GET /documents -- List all documents, except staged ones
GET /documents/{uuid} -- specific document
GET /documents/byTag/{tag,tag,tag...} -- List documents by tags
POST /documents -- Create a new document
PUT /documents/{uuid} -- update a document (adding tags, changing metadata)
DELETE /documents/{uuid} -- trash document
GET /tags -- List of all tags
GET /tags/{tag} -- tag details
POST /tags -- create new tag
DELETE /tags/{tag} -- delete a tag
```
## Parameters:
* Staging directory
* Media storage directory
* Database credentials
## Database tables:
* documents
* document_tags
* tags
Special tags: `trash`, `new`
\ No newline at end of file
......@@ -3,6 +3,7 @@ plugins {
id "org.jetbrains.kotlin.kapt" version "1.3.50"
id "org.jetbrains.kotlin.plugin.allopen" version "1.3.50"
id "com.github.johnrengelman.shadow" version "5.0.0"
id "com.avast.gradle.docker-compose" version "0.10.7"
id "application"
}
......@@ -50,6 +51,12 @@ dependencies {
}
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
implementation 'io.micronaut.configuration:micronaut-flyway'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.9'
implementation 'io.micronaut.configuration:micronaut-postgres-reactive'
kapt "io.micronaut.configuration:micronaut-openapi"
compile "io.swagger.core.v3:swagger-annotations"
......@@ -58,7 +65,20 @@ dependencies {
test.classpath += configurations.developmentOnly
mainClassName = "example.micronaut.Application"
mainClassName = "is.kow.homeedms.Application"
dockerCompose.isRequiredBy(run)
def username = System.properties['user.name']
dockerCompose {
environment.put 'UID', ["id", "-u", username].execute().text.trim()
environment.put 'GID', ["id", "-g", username].execute().text.trim()
}
run.doFirst {
environment 'MICRONAUT_ENVIRONMENTS', 'local'
}
test {
useJUnitPlatform()
......@@ -91,5 +111,9 @@ shadowJar {
mergeServiceFiles()
}
kapt {
useBuildCache = false
}
run.classpath += configurations.developmentOnly
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
version: '3.7'
services:
db:
image: postgres
user: "$UID:$GID"
ports:
- "5432:5432"
environment:
- POSTGRES_USER=homeedms
- POSTGRES_PASSWORD=homeedms
volumes:
- ./postgresql:/var/lib/postgresql
# This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
- ./postgresql_data:/var/lib/postgresql/data
kapt.use.worker.api=true
micronautVersion=1.2.8
kotlinVersion=1.3.50
spekVersion=2.0.8
\ No newline at end of file
package example.micronaut
package `is`.kow.homeedms
import `is`.kow.homeedms.documents.StagingWatcher
import io.micronaut.configuration.postgres.reactive.PgPoolConfiguration
import io.micronaut.runtime.Micronaut
import io.swagger.v3.oas.annotations.OpenAPIDefinition
import io.swagger.v3.oas.annotations.info.Contact
import io.swagger.v3.oas.annotations.info.Info
import io.swagger.v3.oas.annotations.info.License
import org.flywaydb.core.Flyway
import org.slf4j.LoggerFactory
@OpenAPIDefinition(
info = Info(
......@@ -17,11 +22,31 @@ import io.swagger.v3.oas.annotations.info.License
)
object Application {
val logger = LoggerFactory.getLogger(Application::class.java)
@JvmStatic
fun main(args: Array<String>) {
Micronaut.build()
.packages("example.micronaut")
//TODO: need to add CLI args for staging directory
val context = Micronaut.build()
.packages("is.kow.homeedms")
.mainClass(Application.javaClass)
.start()
val environment = context.getEnvironment()
logger.debug("Active Environments: ${environment.activeNames.joinToString(", ")}")
val options: PgPoolConfiguration = context.getBean(PgPoolConfiguration::class.java)
val flyway = Flyway.configure()
.dataSource("jdbc:postgresql://${options.pgPoolOptions.host}:${options.pgPoolOptions.port}/${options.pgPoolOptions.database}",
options.pgPoolOptions.user,
options.pgPoolOptions.password)
.load()
logger.info("Beginning Flyway migrations!")
flyway.migrate()
val stagingWatcher = context.getBean(StagingWatcher::class.java)
logger.debug("Got the staging watcher")
}
}
\ No newline at end of file
package `is`.kow.homeedms
import io.micronaut.context.annotation.ConfigurationProperties
import javax.validation.constraints.NotBlank
@ConfigurationProperties("app")
class ApplicationConfiguration {
@NotBlank
var pgUser: String = "homeedms"
@NotBlank
lateinit var pgPass: String
@NotBlank
var pgHost: String = "localhost"
@NotBlank
var pgPort: Int = 5432
@NotBlank
var pgDatabase: String = "homeedms"
@NotBlank
lateinit var watchDirectory: String
@NotBlank
lateinit var mediaDirectory: String
}
\ No newline at end of file
package example.micronaut
package `is`.kow.homeedms
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
......
package `is`.kow.homeedms.documents
import java.nio.file.Path
import java.util.*
data class Document(
val uuid: UUID, //Document UUID
val path: Path //Relative to media root
)
\ No newline at end of file
package `is`.kow.homeedms.documents
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.PathVariable
import io.micronaut.http.annotation.Produces
import org.slf4j.LoggerFactory
import java.util.*
@Controller("/documents")
class DocumentController {
val logger = LoggerFactory.getLogger(DocumentController::class.java)
@Get("/")
@Produces(MediaType.APPLICATION_JSON)
fun index(): List<Document> {
logger.debug("THIS IS A DEBUG")
return listOf()
}
@Get("/byTag/{tagList}")
@Produces(MediaType.APPLICATION_JSON)
fun documentsByTagList(@PathVariable tagList: String): List<Document> {
return listOf()
}
@Get("/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
fun documentDetails(@PathVariable uuid: UUID): Document? {
return null;
}
@Get("/{uuid}.pdf")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
fun documentContent(@PathVariable uuid: UUID): ByteArray? {
//TODO: how to stream the document back to them?
return null;
}
}
\ No newline at end of file
package `is`.kow.homeedms.documents
import `is`.kow.homeedms.ApplicationConfiguration
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import org.reactivestreams.Subscription
import org.slf4j.LoggerFactory
import java.util.*
import java.util.concurrent.TimeUnit
import javax.annotation.PostConstruct
import javax.inject.Singleton
@Singleton
class StagingWatcher(
private val config: ApplicationConfiguration
) {
val logger = LoggerFactory.getLogger(StagingWatcher::class.java)
val subscriptions: Stack<Disposable> = Stack()
@PostConstruct
fun init() {
while (subscriptions.isNotEmpty()) {
subscriptions.pop().dispose() //turn them off!
}
val watcher = Observable.interval(0, 500, TimeUnit.MILLISECONDS)
.map { count ->
logger.debug("Checking ${config.watchDirectory} at ${count}")
}
subscriptions.push(watcher.subscribe())
}
//TODO: create and start up a Observer watching for documents
}
\ No newline at end of file
app:
pgUser: homeedms
pgPass: homeedms
pgPort: 5432
pgDatabase: homeedms
pgHost: localhost
watchDirectory: /tmp/homeedms/watch
mediaDirectory: /tmp/homeedms/media
micronaut:
application:
name: complete
name: HomeEDMS
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
---
postgres:
reactive:
client:
port: ${app.pgPort}
host: ${app.pgHost}
database: ${app.pgDatabase}
user: ${app.pgUser}
password: ${app.pgPass}
maxSize: 5
create table documents (
uuid uuid not null primary key
);
create table tags (
id serial primary key,
name varchar not null,
description varchar,
UNIQUE(name)
);
create table document_tags(
document_id uuid references documents(uuid),
tag_id serial references tags(id)
);
\ No newline at end of file
......@@ -9,6 +9,8 @@
</encoder>
</appender>
<logger name="is.kow.homeedms" level="DEBUG"/>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
......
package example.micronaut
package `is`.kow.homeedms
import assertk.assertThat
import assertk.assertions.isEqualTo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment