Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(picocli): picocli added to the project #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.jetbrains.kotlin.jvm").version("1.4.20")
id("com.bonitasoft.gradle.bonita-formatting").version("0.1.53")
id("org.jetbrains.kotlin.kapt").version("1.5.31")
application
}

Expand All @@ -19,8 +20,19 @@ dependencies {
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.14.0")
implementation("org.awaitility:awaitility-kotlin:4.0.3")
implementation("org.nield:kotlin-statistics:1.2.1")
implementation("info.picocli:picocli:4.6.2")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
kapt("info.picocli:picocli-codegen:4.6.2")
}

kapt {
arguments {
arg("project", "${project.group}/${project.name}")
arg("disable.proxy.config")
arg("disable.reflect.config")
arg("disable.resource.config")
}
}

application {
Expand Down
41 changes: 26 additions & 15 deletions src/main/kotlin/org/bonitasoft/example/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,38 @@ import org.bonitasoft.engine.identity.User
import org.bonitasoft.engine.profile.ProfileMemberCreator
import org.bonitasoft.engine.search.SearchOptionsBuilder
import org.bonitasoft.engine.util.APITypeManager
import org.bonitasoft.example.datasets.Dataset
import org.bonitasoft.example.datasets.DevDatasetGenerator
import org.bonitasoft.example.datasets.PerformanceDatasetGenerator
import org.bonitasoft.example.processes.ProcessWithMessageEventSubProcess
import picocli.CommandLine
import java.net.URL
import java.util.concurrent.Callable
import kotlin.system.exitProcess

class App {
@CommandLine.Command(name = "dataset", mixinStandardHelpOptions = true, version = ["dataset 0.0.1"],
description = ["Generate bonita datasets"])
class BonitaDatasetCLI : Callable<Int> {

fun run(url: String) {
@CommandLine.Parameters(paramLabel = "Dataset", description = ["The dataset ID you want to generate"])
lateinit var datasetID: Dataset

APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, mapOf(
"server.url" to url,
"application.name" to ""
))
val apiClient = APIClient().apply { login("install", "install") }
@CommandLine.Option(names = ["-h", "--url"], paramLabel = "Bonita URL", description = ["Destination Bonita URL where dataset will be generated"], interactive = true)
var bonitaURL: String = "http://localhost:8080"

// Organization().deploy(apiClient)
DeployAdminApplicationTestData().accept(apiClient)
// val businessArchive = ProcessWithMessageEventSubProcess().build()
// BusinessArchiveFactory.writeBusinessArchiveToFile(businessArchive, File("ProcessWithMessageEventSubProcess.bar"))
@CommandLine.Option(names = ["-a", "--app"], paramLabel = "Bonita App Name", description = ["Bonita App name where dataset will be generated"], interactive = true)
var appName: String = "bonita"


override fun call(): Int {
when(datasetID){
Dataset.DEV -> DevDatasetGenerator().run(bonitaURL, appName);
Dataset.PERF -> PerformanceDatasetGenerator().run(bonitaURL, appName);
}
return 0;
}
}

}

infix fun <T> org.bonitasoft.engine.api.APIClient.safeExec(executable: org.bonitasoft.engine.api.APIClient.() -> T): T? {
return try {
Expand Down Expand Up @@ -73,6 +86,4 @@ fun ProfileAPI.addMembershipToProfile(group: Group, role: Role, profileName: Str
createProfileMember(getProfileByName(profileName), -1L, group.id, role.id)
}

fun main(args: Array<String>) {
App().run(args.getOrElse(0) { "http://localhost:8080" })
}
fun main(args: Array<String>) : Unit = exitProcess(CommandLine(BonitaDatasetCLI()).execute(*args))
19 changes: 19 additions & 0 deletions src/main/kotlin/org/bonitasoft/example/datasets/Dataset.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2020 Bonitasoft S.A.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.bonitasoft.example.datasets

enum class Dataset {
DEV,PERF
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020 Bonitasoft S.A.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.bonitasoft.example.datasets

interface DatasetGenerator {

// run dataSet generation
fun run(url: String, appName: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020 Bonitasoft S.A.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.bonitasoft.example.datasets

class DevDatasetGenerator() : DatasetGenerator {
override fun run(url: String, appName: String) {
println("dev dataset generation ...");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2020 Bonitasoft S.A.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.bonitasoft.example.datasets

import org.bonitasoft.engine.api.APIClient
import org.bonitasoft.engine.api.ApiAccessType
import org.bonitasoft.engine.util.APITypeManager
import org.bonitasoft.example.DeployAdminApplicationTestData
import org.bonitasoft.example.NewOrganization
import org.bonitasoft.web.client.BonitaClient
import org.bonitasoft.web.client.feign.BonitaFeignClientBuilder

class PerformanceDatasetGenerator() : DatasetGenerator {
override fun run(url: String,appName: String) {
println("perf dataset generation ...")
APITypeManager.setAPITypeAndParams(
ApiAccessType.HTTP, mapOf(
"server.url" to url,
"application.name" to appName
))
val apiClient = APIClient().apply { login("install", "install") }
//val apiClient = BonitaClient.builder<BonitaFeignClientBuilder>(url).build()

//login
//val session = apiClient.login("install","install");
// Log Bonita server version
//println("Bonita version: "+ session.getVersion());

DeployAdminApplicationTestData().accept(apiClient)

//logout
//apiClient.logout();
}
}