Skip to content
Merged
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
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ buildscript {
'twofactor-tests',
'oauth2-tests',
'fineract-client',
'fineract-client-feign',
'fineract-avro-schemas',
'fineract-e2e-tests-core',
'fineract-e2e-tests-runner',
Expand All @@ -55,6 +56,7 @@ buildscript {
[
'fineract-avro-schemas',
'fineract-client',
'fineract-client-feign',
'fineract-core',
'fineract-cob',
'fineract-validation',
Expand Down Expand Up @@ -558,6 +560,9 @@ configure(project.fineractJavaProjects) {
if (project.path == ':fineract-client') {
excludedPaths = '.*/build/generated/java/src/main/java/.*'
}
if (project.path == ':fineract-client-feign') {
excludedPaths = '.*/build/generated/java/src/main/java/.*'
}
disable(
// TODO Remove disabled checks from this list, by fixing remaining usages
"UnusedVariable",
Expand Down
32 changes: 32 additions & 0 deletions fineract-client-feign/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
**/README.md
**/pom.xml
**/build.sbt
**/*.gradle
**/.gitignore
**/git_push.sh
**/api/*
**/gradle*
**/gradle
**/src/main/AndroidManifest.xml

# https://issues.apache.org/jira/browse/FINERACT-1231
**/feign/*.java
!**/feign/CollectionFormats.java
!**/feign/StringUtil.java

# Manual API overrides - do not regenerate
# https://issues.apache.org/jira/browse/FINERACT-1263
**/services/RunReportsApi.java
**/services/ImagesApi.java
**/services/DocumentsApiFixed.java

# Utility classes - do not regenerate
**/util/*.java
**/adapter/*.java

# Feign configuration - do not regenerate
**/feign/FineractFeignClient.java
**/feign/FineractFeignClientConfig.java
**/feign/BasicAuthRequestInterceptor.java
**/feign/ObjectMapperFactory.java
**/feign/FeignException.java
194 changes: 194 additions & 0 deletions fineract-client-feign/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
apply plugin: 'org.openapi.generator'
apply plugin: 'jacoco'
description = 'Fineract Client with Feign'

apply from: 'dependencies.gradle'

openApiMeta {
generatorName = 'Fineract-Feign'
packageName = 'org.apache.fineract.client.feign'
outputFolder = "$buildDir/meta".toString()
}

openApiValidate {
inputSpec = "file:///$swaggerFile"
recommend = true
}

tasks.register('buildJavaSdk', org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = 'java'
library = 'feign'
verbose = false
validateSpec = false
skipValidateSpec = true
inputSpec = "file:///$swaggerFile"
outputDir = "$buildDir/generated/temp-java".toString()
templateDir = "$projectDir/src/main/resources/templates/java"
groupId = 'org.apache.fineract'
apiPackage = 'org.apache.fineract.client.feign.services'
invokerPackage = 'org.apache.fineract.client.feign'
modelPackage = 'org.apache.fineract.client.models'
generateModelTests = false
generateApiTests = false
ignoreFileOverride = "$projectDir/.openapi-generator-ignore"
configOptions = [
dateLibrary : 'java8',
library : 'feign',
feignVersion : '13.6',
feignApacheHttpClient : 'true',
useFeign13 : 'true',
useFeignApacheHttpClient : 'true',
hideGenerationTimestamp : 'true',
containerDefaultToNull : 'true',
oauth2Implementation : 'none',
useJakartaEe : 'true'

]
dependsOn(':fineract-provider:resolve')
}

sourceSets {
main {
java {
srcDirs = [
new File(buildDir, "generated/java/src/main/java"),
"$projectDir/src/main/java"
]
destinationDirectory = layout.buildDirectory.dir('classes/java/main').get().asFile
}
output.resourcesDir = layout.buildDirectory.dir('resources/main').get().asFile
}
test {
java {
destinationDirectory = layout.buildDirectory.dir('classes/java/test').get().asFile
}
output.resourcesDir = layout.buildDirectory.dir('resources/test').get().asFile
}
}

tasks.withType(Jar).configureEach {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

task cleanupGeneratedJavaFiles() {
def tempDir = file("$buildDir/generated/temp-java")
def targetDir = file("$buildDir/generated/java")

inputs.dir(tempDir)
outputs.dir(targetDir)

doLast {
copy {
from tempDir
into targetDir
filter { line ->
line
.replaceAll(", \\)", ")")
.replaceAll(", , @HeaderMap", ", @HeaderMap")
.replaceAll("\\(, ", "(")
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
dependsOn("buildJavaSdk")
}

tasks.named('compileJava') {
outputs.cacheIf { true }
dependsOn(buildJavaSdk, cleanupGeneratedJavaFiles, licenseFormatMain, spotlessMiscApply)
mustRunAfter(licenseFormatMain, cleanupGeneratedJavaFiles)
}

tasks.named('sourcesJar') {
dependsOn(cleanupGeneratedJavaFiles)
mustRunAfter(cleanupGeneratedJavaFiles)

from(sourceSets.main.java.srcDirs) {
include "**/*.java"
}
}

tasks.named('licenseFormatMain') {
dependsOn(cleanupGeneratedJavaFiles)
mustRunAfter(cleanupGeneratedJavaFiles)
source = sourceSets.main.java.srcDirs
}

tasks.named('licenseMain') {
dependsOn(licenseFormatMain)
mustRunAfter(licenseFormatMain)
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs << '-parameters'
options.errorprone {
excludedPaths = '.*/build/generated/java/src/main/java/.*'
}
}

test {
useJUnitPlatform()
}

configurations {
generatedCompileClasspath.extendsFrom implementation
generatedRuntimeClasspath.extendsFrom runtimeClasspath
}

javadoc {
options.encoding = 'UTF-8'
}

spotbugsMain {
enabled = false
}

spotbugsTest {
enabled = false
}

jacoco {
toolVersion = "0.8.11"
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
csv.required = false
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/build/generated/**',
'**/org/apache/fineract/client/models/**',
'**/org/apache/fineract/client/services/**Api.class',
'**/org/apache/fineract/client/auth/**'
])
}))
}
}

test {
finalizedBy jacocoTestReport
}
49 changes: 49 additions & 0 deletions fineract-client-feign/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
dependencies {
// Feign dependencies
implementation(
'io.github.openfeign:feign-core:13.6',
'io.github.openfeign:feign-jackson:13.6',
'io.github.openfeign:feign-slf4j:13.6',
'io.github.openfeign:feign-hc5:13.6',
'io.github.openfeign:feign-okhttp:13.6',
'io.github.openfeign.form:feign-form:3.8.0',
'org.apache.httpcomponents.client5:httpclient5:5.2.1',
'com.squareup.okhttp3:okhttp:4.12.0',
'com.fasterxml.jackson.core:jackson-databind',
'com.fasterxml.jackson.datatype:jackson-datatype-jsr310',
'com.fasterxml.jackson.datatype:jackson-datatype-jdk8',
'jakarta.annotation:jakarta.annotation-api:3.0.0',
'io.swagger.core.v3:swagger-annotations-jakarta:2.2.15',
'org.apache.commons:commons-lang3:3.12.0',
'org.slf4j:slf4j-api:1.7.36',
'org.projectlombok:lombok'
)

// Test dependencies
testImplementation(
'org.junit.jupiter:junit-jupiter-api:5.11.3',
'org.junit.jupiter:junit-jupiter-engine:5.11.3',
'org.mockito:mockito-core:5.14.2',
'org.assertj:assertj-core:3.26.3',
'org.slf4j:slf4j-simple:1.7.36',
'org.wiremock:wiremock-standalone'
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.client.adapter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.IOException;
import org.apache.fineract.client.models.ExternalId;

/**
* Custom Jackson adapter for ExternalId type serialization and deserialization. This adapter ensures that ExternalId
* objects are properly serialized to their string value and deserialized from string values.
*/
public final class ExternalIdAdapter {

private ExternalIdAdapter() {}

/**
* Jackson Serializer for ExternalId. Serializes an ExternalId object to its string value, or null if the ExternalId
* or its value is null.
*/
public static class Serializer extends JsonSerializer<ExternalId> {

@Override
public void serialize(ExternalId value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value == null || value.getValue() == null) {
gen.writeNull();
} else {
gen.writeString(value.getValue());
}
}
}

/**
* Jackson Deserializer for ExternalId. Deserializes a string value to an ExternalId object, or null if the input is
* null.
*/
public static class Deserializer extends JsonDeserializer<ExternalId> {

@Override
public ExternalId deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String value = p.getValueAsString();
if (value == null) {
return null;
}
ExternalId externalId = new ExternalId();
externalId.setValue(value);
return externalId;
}
}

/**
* Creates a Jackson SimpleModule configured with the ExternalId serializer and deserializer.
*
* @return A configured SimpleModule ready to be registered with an ObjectMapper
*/
public static SimpleModule createModule() {
SimpleModule module = new SimpleModule("ExternalIdModule");
module.addSerializer(ExternalId.class, new Serializer());
module.addDeserializer(ExternalId.class, new Deserializer());
return module;
}
}
Loading
Loading