Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David
mayan-document-ui
Commits
e49c6994
Commit
e49c6994
authored
Jan 10, 2020
by
David
Browse files
Stuf
parent
b85a7dc4
Changes
20
Hide whitespace changes
Inline
Side-by-side
.java-version
0 → 100644
View file @
e49c6994
11
backend/.gitignore
View file @
e49c6994
Thumbs.db
.DS_Store
.gradle
build/
target/
out/
.idea
*.iml
*.ipr
*.iws
.project
.settings
.classpath
\ No newline at end of file
postgresql/
postgresql_data/
backend/README.md
0 → 100644
View file @
e49c6994
## 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
backend/build.gradle
View file @
e49c6994
...
...
@@ -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'
)
backend/docker-compose.yml
0 → 100644
View file @
e49c6994
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
backend/gradle.properties
View file @
e49c6994
kapt.use.worker.api
=
true
micronautVersion
=
1.2.8
kotlinVersion
=
1.3.50
spekVersion
=
2.0.8
\ No newline at end of file
backend/postgresql/.gitkeep
0 → 100644
View file @
e49c6994
backend/postgresql/data/.gitkeep
0 → 100644
View file @
e49c6994
backend/postgresql_data/.gitkeep
0 → 100644
View file @
e49c6994
backend/src/main/kotlin/
example/micronaut
/Application.kt
→
backend/src/main/kotlin/
is/kow/homeedms
/Application.kt
View file @
e49c6994
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
backend/src/main/kotlin/is/kow/homeedms/ApplicationConfiguration.kt
0 → 100644
View file @
e49c6994
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
backend/src/main/kotlin/
example/micronaut
/HelloController.kt
→
backend/src/main/kotlin/
is/kow/homeedms
/HelloController.kt
View file @
e49c6994
package
example.micronaut
package
`is`.kow.homeedms
import
io.micronaut.http.MediaType
import
io.micronaut.http.annotation.Controller
...
...
backend/src/main/kotlin/is/kow/homeedms/documents/Document.kt
0 → 100644
View file @
e49c6994
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
backend/src/main/kotlin/is/kow/homeedms/documents/DocumentController.kt
0 → 100644
View file @
e49c6994
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
backend/src/main/kotlin/is/kow/homeedms/documents/StagingWatcher.kt
0 → 100644
View file @
e49c6994
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
backend/src/main/resources/application-local.yml
0 → 100644
View file @
e49c6994
app
:
pgUser
:
homeedms
pgPass
:
homeedms
pgPort
:
5432
pgDatabase
:
homeedms
pgHost
:
localhost
watchDirectory
:
/tmp/homeedms/watch
mediaDirectory
:
/tmp/homeedms/media
backend/src/main/resources/application.yml
View file @
e49c6994
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
backend/src/main/resources/db/migration/V001__initial.sql
0 → 100644
View file @
e49c6994
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
backend/src/main/resources/logback.xml
View file @
e49c6994
...
...
@@ -9,6 +9,8 @@
</encoder>
</appender>
<logger
name=
"is.kow.homeedms"
level=
"DEBUG"
/>
<root
level=
"info"
>
<appender-ref
ref=
"STDOUT"
/>
</root>
...
...
backend/src/test/kotlin/
example/micronaut
/HelloControllerSpec.kt
→
backend/src/test/kotlin/
is/kow/homeedms
/HelloControllerSpec.kt
View file @
e49c6994
package
example.micronaut
package
`is`.kow.homeedms
import
assertk.assertThat
import
assertk.assertions.isEqualTo
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment