Skip to content

Commit

Permalink
[CAT-109] Kotlin GraphQL Rewrite (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
goatrocks authored Nov 1, 2021
1 parent c7bc671 commit 64d8b29
Show file tree
Hide file tree
Showing 138 changed files with 46,774 additions and 23,893 deletions.
37 changes: 37 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
kind: pipeline
type: kubernetes
name: default

steps:
- name: build
image: gradle:jdk8
commands:
- ./gradlew build

- name: stage
image: gradle:jdk8
commands:
- echo "signing.keyId=$${sonatype_gpg_keyid}" > gradle.properties
- echo "signing.password=$${sonatype_gpg_password}" >> gradle.properties
- echo "signing.secretKeyRingFile=${HOME}/.gradle/secring.gpg" >> gradle.properties
- echo "sonatypeUsername=$${sonatype_username}" >> gradle.properties
- echo "sonatypePassword=$${sonatype_password}" >> gradle.properties
- echo ${sonatype_gpg_key} | base64 -d > ~/.gradle/secring.gpg
- ./gradlew publishToSonatype

- name: deploy
image: gradle:jdk8
when:
event:
- promote
target:
- production
commands:
- echo "signing.keyId=$${sonatype_gpg_keyid}" > gradle.properties
- echo "signing.password=$${sonatype_gpg_password}" >> gradle.properties
- echo "signing.secretKeyRingFile=${HOME}/.gradle/secring.gpg" >> gradle.properties
- echo "sonatypeUsername=$${sonatype_username}" >> gradle.properties
- echo "sonatypePassword=$${sonatype_password}" >> gradle.properties

- ./gradlew closeAndReleaseStagingRepository

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ gradle-app.setting

# Ignore Gradle Peoperties
gradle.properties

indico_api_token.txt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>com.indico</groupId>
<artifactId>indico-client-java</artifactId>
<version>4.0.2</version>
<version>4.0.6</version>
</dependency>
```

Expand All @@ -44,7 +44,7 @@ IndicoConfig config = new IndicoConfig.Builder()
.build();
```
You configure the IndicoConfig class via an embedded Builder that has methods to set the various config parameters such as
host, tokenPath, etc.
host, tokenPath, connection timeout, etc.

### API Client

Expand Down
196 changes: 120 additions & 76 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,109 +1,153 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("com.apollographql.apollo:apollo-gradle-plugin:1.2.2")
}
}
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
import com.expediagroup.graphql.plugin.gradle.config.GraphQLSerializer

plugins {
id 'java-library'
id 'maven'
id 'signing'
id 'eclipse'
id 'idea'
id "java"
id 'org.jetbrains.kotlin.jvm' version '1.5.31'
id "signing"
id "maven-publish"
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
id 'com.expediagroup.graphql' version '5.2.0'

}

apply plugin: 'com.apollographql.android'
group 'com.indico'

repositories {
jcenter()
mavenCentral()
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
archivesBaseName = "indico-client-java"
version = "4.12.0"


task sourceJar(type: Jar) {
classifier "sources"
from sourceSets.main.allJava
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier "javadoc"
from javadoc.destinationDir
}

artifacts {
archives javadocJar, sourcesJar
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}

signing {
sign configurations.archives

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.5.31"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation("io.ktor:ktor-client-okhttp:1.6.1")
testImplementation('org.junit.jupiter:junit-jupiter:5.5.2')
implementation("com.expediagroup:graphql-kotlin-ktor-client:5.2.0")
implementation("com.expediagroup:graphql-kotlin-client-jackson:5.2.0")
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation('org.apache.logging.log4j:log4j-1.2-api:2.14.1')
api('org.json:json:20190722')
compileOnly("org.jetbrains:annotations:13.0")
testCompileOnly("org.jetbrains:annotations:13.0")
}

group = "com.indico"
archivesBaseName = "indico-client-java"
version = "4.11.3"

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
//use with update-schema.sh to refresh graphql schema
graphqlIntrospectSchema {
outputFile = file("${project.projectDir}/src/main/graphql/schema.graphql")
endpoint = "https://app.indico.io/graph/api/graphql"
headers = ["Authorization" : "Bearer " + project.getProperties().getOrDefault('graphQlToken', "")]
}

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
graphqlGenerateClient {
// Boolean flag indicating whether or not selection of deprecated fields is allowed.
allowDeprecatedFields = true
packageName = "com.indico.graphql"
schemaFile = file("${project.projectDir}/src/main/resources/schema.graphql")
serializer = GraphQLSerializer.JACKSON
useOptionalInputWrapper = true

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
}

pom.project {
name 'Indico IPA Client'
packaging 'jar'
description 'Java client to the Indico IPA platform'
url 'http://indico.com'
scm {
connection 'scm:github.com:IndicoDataSolutions/indico-client-java.git'
developerConnection 'scm:github.com:IndicoDataSolutions/indico-client-java.git'
url 'https://github.com/IndicoDataSolutions/indico-client-java'
}
licenses {
license {
name 'MIT'
url 'https://github.com/IndicoDataSolutions/indico-client-java/blob/master/LICENSE'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}


// ossrh requires javadoc and sources https://central.sonatype.org/pages/requirements.html
java {
withJavadocJar()
withSourcesJar()
}


void sign(Project project) {
project.signing {
required { project.gradle.taskGraph.hasTask("publish") }
def signingKeyId = project.findProperty("signingKeyId")
def signingKey = project.findProperty("signingKey")
def signingPassword = project.findProperty("signingPassword")
if (signingKeyId) {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
} else if (signingKey) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign publishing.publications.maven
}
}

project.plugins.withType(MavenPublishPlugin).all {
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications.withType(MavenPublication).all { mavenPublication ->
mavenPublication.pom {
name = "${project.group}:${project.name}"
description = name
url = "https://github.com/indico/indico-client-java"
licenses {
license {
name = "MIT"
url = "https://github.com/IndicoDataSolutions/indico-client-java/blob/master/LICENSE"
}
developers {
developer {
id 'Indico'
name 'Indico Engineering'
email '[email protected]'
}
}
developers {
developer {
id = "indico"
name = "Indico Engineering"
email = "[email protected]"
}
}
scm {
connection = "scm:git:https://github.com/indico/indico-client-java.git"
developerConnection = "scm:git:ssh://github.com/indico/indico-client-java.git"
url = "https://github.com/indico/indico-client-java"
}
sign(project)
}
}
}

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
nexusPublishing {
repositories {
sonatype()
}
connectTimeout = Duration.ofMinutes(3)
clientTimeout = Duration.ofMinutes(3)
}

dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.5.2')
testImplementation('org.mock-server:mockserver-netty:5.8.0')
implementation('com.apollographql.apollo:apollo-runtime:1.2.2')
implementation('org.apache.logging.log4j:log4j-1.2-api:2.14.1')
api('org.json:json:20190722')
compileOnly("org.jetbrains:annotations:13.0")
testCompileOnly("org.jetbrains:annotations:13.0")
}

apollo {
outputPackageName = "com.indico"
}
publishing {

test {
useJUnitPlatform()
repositories {
maven {
name = "local"
def releasesRepoUrl = "$buildDir/repos/releases"
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
url = version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
14 changes: 10 additions & 4 deletions examples/GetTrainingModelProgress.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package examples;

import com.indico.IndicoClient;
import com.indico.IndicoConfig;
import com.indico.IndicoKtorClient;
import com.indico.entity.Model;
import com.indico.entity.ModelGroup;
import com.indico.exceptions.IndicoBaseException;
import com.indico.query.ModelGroupQuery;
import com.indico.query.TrainingModelWithProgressQuery;
import java.io.IOException;
Expand All @@ -14,16 +18,18 @@ public static void main(String args[]) throws IOException {
.tokenPath("__TOKEN_PATH__")
.build();

try (IndicoClient client = new IndicoClient(config)) {
int modelGroupId = 1;

try (IndicoClient client = new IndicoKtorClient(config)) {
ModelGroupQuery modelGroupQuery = client.modelGroupQuery();
TrainingModelWithProgressQuery trainingModelWithProgress = client.trainingModelWithProgressQuery();
ModelGroup modelGroup = modelGroupQuery.id(__MODEL_GROUP_ID__).query();
Model model = trainingModelWithProgress.id(__MODEL_GROUP_ID__).query();
ModelGroup modelGroup = modelGroupQuery.id(modelGroupId).query();
Model model = trainingModelWithProgress.id(modelGroupId).query();
System.out.println(modelGroup.name);
System.out.println("training status : " + model.status);
System.out.println("percent complete : " + model.trainingProgress.percentComplete);

} catch (Exception e) {
} catch (IndicoBaseException e) {
e.printStackTrace();
}
}
Expand Down
37 changes: 0 additions & 37 deletions examples/GraphQL.java

This file was deleted.

6 changes: 4 additions & 2 deletions examples/SQSExample.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package examples;

import com.indico.IndicoClient;
import com.indico.IndicoConfig;
import com.indico.IndicoKtorClient;
import org.json.JSONObject;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sqs.SqsClient;
Expand Down Expand Up @@ -39,7 +41,7 @@ public static void main(String[] args) throws InterruptedException, IOException
.connectTimeout(0)
.build();

IndicoClient indicoClient = new IndicoClient(config);
IndicoClient indicoClient = new IndicoKtorClient(config);
//submit item(s) for processing
submit_workflow(indicoClient);

Expand All @@ -59,7 +61,7 @@ public static void main(String[] args) throws InterruptedException, IOException
//fetch receipt handle and body
String rh = m.receiptHandle();
//handle the fact that certain SQS queues
//may escpae JSON even with raw value setting
//may escape JSON even with raw value setting
if(m.body().startsWith("\"")) {
StringBuilder sb = new StringBuilder(m.body());
sb.deleteCharAt(0);
Expand Down
Loading

0 comments on commit 64d8b29

Please sign in to comment.