Skip to content

Commit

Permalink
generate document action
Browse files Browse the repository at this point in the history
  • Loading branch information
floris-thijssen-ritense committed Oct 11, 2024
1 parent 3ee39f2 commit fd02bd4
Show file tree
Hide file tree
Showing 18 changed files with 663 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
27 changes: 27 additions & 0 deletions backend/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ plugins {
id "org.jetbrains.kotlin.plugin.spring" version "${kotlinVersion}"
id "org.jetbrains.kotlin.plugin.allopen" version "${kotlinVersion}"
id "com.avast.gradle.docker-compose" version "0.16.9"

id "org.openapi.generator" version "7.9.0"
}

repositories {
Expand All @@ -49,9 +51,17 @@ dependencies {
implementation "com.ritense.valtimo:value-resolver:${valtimoVersion}"

implementation "org.springframework.boot:spring-boot-starter-webflux:${springVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springVersion}"

implementation "io.github.microutils:kotlin-logging:3.0.5"

implementation "jakarta.inject:jakarta.inject-api:2.0.1"
implementation "jakarta.persistence:jakarta.persistence-api:3.1.0"

implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.moshi:moshi:1.15.1")
implementation("com.squareup.moshi:moshi-kotlin:1.15.1")

// Testing
testImplementation "com.ritense.valtimo:document:${valtimoVersion}"
testImplementation "com.ritense.valtimo:local-resource:${valtimoVersion}"
Expand All @@ -74,6 +84,23 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
}

openApiGenerate {
inputSpec.set("$rootDir/plugin/src/main/resources/dcsg_xential.yaml")
generatorName.set("kotlin")
outputDir.set("${getLayout().getBuildDirectory().get()}/generated")
apiPackage.set("com.rotterdam.xential.api")
invokerPackage.set("com.rotterdam.xential.invoker")
modelPackage.set("com.rotterdam.xential.model")
}

sourceSets {
main {
java {
srcDir("${buildDir}/generated/src/main")
}
}
}

tasks.register("integrationTesting", Test) {
group = "verification"
useJUnitPlatform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,64 @@
package com.ritense.valtimo.xential.autoconfiguration

import com.ritense.plugin.service.PluginService
import com.ritense.resource.service.TemporaryResourceStorageService
import com.ritense.valtimo.contract.config.LiquibaseMasterChangeLogLocation
import com.ritense.valtimo.xential.plugin.XentialPluginFactory
import com.ritense.valtimo.xential.repository.XentialTokenRepository
import com.ritense.valtimo.xential.service.DocumentGenerationService
import com.rotterdam.xential.api.DefaultApi
import org.openapitools.client.infrastructure.ApiClient
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.context.annotation.Bean
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.web.reactive.function.client.WebClient

@AutoConfiguration
@EnableJpaRepositories(basePackages = ["com.ritense.valtimo.xential.repository"])
@EntityScan("com.ritense.valtimo.xential.domain")
class XentialAutoConfiguration {

@Bean
@ConditionalOnMissingBean(XentialPluginFactory::class)
fun xentialPluginFactory(
pluginService: PluginService,
documentGenerationService: DocumentGenerationService
): XentialPluginFactory {
return XentialPluginFactory(pluginService)
return XentialPluginFactory(
pluginService,
documentGenerationService,
)
}

@Bean
@ConditionalOnMissingBean(name = ["xentialLiquibaseMasterChangeLogLocation"])
fun xentialLiquibaseMasterChangeLogLocation(): LiquibaseMasterChangeLogLocation {
return LiquibaseMasterChangeLogLocation("config/liquibase/xential-plugin-master.xml")
}

@Bean
@ConditionalOnMissingBean
fun defaultApi(): DefaultApi {
return DefaultApi()
}

@Bean
@ConditionalOnMissingBean
fun apiClient(
@Value("plugin.xential.baseurl")
baseUrl: String,
) = ApiClient(baseUrl)

@Bean
@ConditionalOnMissingBean
fun documentGenerationService(
defaultApi: DefaultApi,
xentialTokenRepository: XentialTokenRepository
) = DocumentGenerationService(
defaultApi,
xentialTokenRepository,
)

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.ritense.valtimo.xential.model
package com.ritense.valtimo.xential.domain

import java.util.UUID

data class GenerateDocumentProperties(
val templateId: String,
val templateId: UUID,
val fileFormat: FileFormat,
val documentId: String,
val templateData: Map<String, String>
)

enum class FileFormat {
DOCX, HTML, PDF, XML
WORD, PDF
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ritense.valtimo.xential.domain

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.net.URI
import java.util.UUID

@Entity
@Table(name = "xential_tokens")
data class XentialToken (
@Id
@Column(name = "token", nullable = false, updatable = false)
val token: UUID,
@Column(name = "process_id", nullable = false, updatable = false)
val processId: UUID,
@Column(name = "resume_url", nullable = true, updatable = false)
val resumeUrl: URI?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,43 @@ import com.ritense.plugin.annotation.Plugin
import com.ritense.plugin.annotation.PluginAction
import com.ritense.plugin.annotation.PluginProperty
import com.ritense.processlink.domain.ActivityTypeWithEventName
import com.ritense.valtimo.xential.model.GenerateDocumentProperties
import com.ritense.valtimo.xential.domain.GenerateDocumentProperties
import com.ritense.valtimo.xential.domain.XentialToken
import com.ritense.valtimo.xential.repository.XentialTokenRepository
import com.ritense.valtimo.xential.service.DocumentGenerationService
import com.rotterdam.xential.api.DefaultApi
import com.rotterdam.xential.model.Sjabloondata
import org.camunda.bpm.engine.delegate.DelegateExecution
import java.util.UUID

@Plugin(
key = "xential",
title = "Xential Plugin",
description = ""
)
class XentialPlugin(
val documentGenerationService: DocumentGenerationService
) {

@PluginProperty(key = "clientId", secret = false)
private lateinit var clientId: String

@PluginProperty(key = "clientPassword", secret = true)
private lateinit var clientPassword: String

@PluginAction(
key = "generate-document",
title = "Generate document",
description = "Generate a document using xential.",
activityTypes = [ActivityTypeWithEventName.SERVICE_TASK_START]
)
fun generateDocument(execution: DelegateExecution, generateDocumentProperties: GenerateDocumentProperties) {
println("$clientId, $generateDocumentProperties")
documentGenerationService.generateDocument(
UUID.fromString(execution.processInstanceId),
generateDocumentProperties,
clientId,
clientPassword
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ package com.ritense.valtimo.xential.plugin

import com.ritense.plugin.PluginFactory
import com.ritense.plugin.service.PluginService
import com.ritense.valtimo.xential.repository.XentialTokenRepository
import com.ritense.valtimo.xential.service.DocumentGenerationService
import com.rotterdam.xential.api.DefaultApi
import org.springframework.web.client.RestClient

class XentialPluginFactory(
pluginService: PluginService,
val documentGenerationService: DocumentGenerationService
) : PluginFactory<XentialPlugin>(pluginService) {

override fun create(): XentialPlugin {
return XentialPlugin()
return XentialPlugin(documentGenerationService)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ritense.valtimo.xential.repository

import com.ritense.valtimo.xential.domain.XentialToken
import org.springframework.data.repository.CrudRepository
import java.util.UUID

interface XentialTokenRepository : CrudRepository<XentialToken, UUID>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.ritense.valtimo.xential.service

import com.ritense.valtimo.xential.domain.GenerateDocumentProperties
import com.ritense.valtimo.xential.domain.XentialToken
import com.ritense.valtimo.xential.repository.XentialTokenRepository
import com.rotterdam.xential.api.DefaultApi
import com.rotterdam.xential.model.Sjabloondata
import org.openapitools.client.infrastructure.ApiClient
import java.util.UUID

class DocumentGenerationService(
val defaultApi: DefaultApi,
val xentialTokenRepository: XentialTokenRepository,
) {

fun generateDocument(
processId: UUID,
generateDocumentProperties: GenerateDocumentProperties,
clientId: String,
clientPassword: String,
) {
val sjabloonVulData = generateDocumentProperties.templateData.entries.map { "<${it.key}>${it.value}</${it.key}>" }.joinToString()

ApiClient.username = clientId
ApiClient.password = clientPassword
val result = defaultApi.creeerDocument(
gebruikersId = clientId,
accepteerOnbekend = false,
sjabloondata = Sjabloondata(
sjabloonId = generateDocumentProperties.templateId.toString(),
bestandsFormaat = Sjabloondata.BestandsFormaat.valueOf(generateDocumentProperties.fileFormat.name),
documentkenmerk = generateDocumentProperties.documentId,
sjabloonVulData = "<root>$sjabloonVulData</root>"
)
)

val xentialToken = XentialToken(
token = UUID.fromString(result.documentCreatieSessieId),
processId = processId,
resumeUrl = result.resumeUrl
)

xentialTokenRepository.save(xentialToken)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<!--
~ Copyright 2015-2024 Ritense BV, the Netherlands.
~
~ Licensed under EUPL, Version 1.2 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" basis,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

<changeSet id="1" author="Ritense">
<preConditions onFail="CONTINUE">
<tableExists tableName="xential_tokens"/>
</preConditions>
<createTable tableName="xential_tokens">
<column name="token" type="uuid"/>
<column name="process_id" type="uuid"/>
<column name="resume_url" type="VARCHAR(2083)"/>
</createTable>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2015-2024 Ritense BV, the Netherlands.
~
~ Licensed under EUPL, Version 1.2 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" basis,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

<include file="changelog/20241010-add-xential_tokens.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>
Loading

0 comments on commit fd02bd4

Please sign in to comment.