Skip to content
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
6 changes: 3 additions & 3 deletions fineract-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ configurations.driver.each {File file ->
tasks.register('createDB') {
description = "Creates the MariaDB Database. Needs database name to be passed (like: -PdbName=someDBname)"
doLast {
def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver')
def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/?allowPublicKeyRetrieval=true&useSSL=false', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JDBC URL change in build.gradle—should that be handled in a separate PR, since it’s not directly related to the JSON migration?

sql.execute('CREATE DATABASE ' + "`$dbName` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
}
}

tasks.register('dropDB') {
description = "Drops the specified MariaDB database. The database name has to be passed (like: -PdbName=someDBname)"
doLast {
def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver')
def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/?allowPublicKeyRetrieval=true&useSSL=false', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver')
sql.execute('DROP DATABASE ' + "`$dbName`")
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ tasks.register('dropMySQLDB') {

tasks.register('setBlankPassword') {
doLast {
def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver')
def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/?allowPublicKeyRetrieval=true&useSSL=false', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver')
sql.execute('USE `fineract_tenants`')
sql.execute('UPDATE fineract_tenants.tenants SET schema_server = \'localhost\', schema_server_port = \'3306\', schema_username = \'mifos\', schema_password = \'mysql\' WHERE id=1;')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.apache.fineract.template.domain;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -90,14 +90,20 @@ public static Template fromJson(final JsonCommand command) {
break;
}

final JsonArray array = command.arrayOfParameterNamed("mappers");

final List<TemplateMapper> mappersList = new ArrayList<>();

for (final JsonElement element : array) {
mappersList.add(new TemplateMapper(element.getAsJsonObject().get("mappersorder").getAsInt(),
element.getAsJsonObject().get("mapperskey").getAsString(),
element.getAsJsonObject().get("mappersvalue").getAsString()));
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed ObjectMapper is being instantiated in multiple places—should we consider reusing a shared instance (e.g., via Spring) for consistency and efficiency, or is this intentional for now?

final ObjectMapper objectMapper = new ObjectMapper();
final JsonNode rootNode = objectMapper.readTree(command.json());
final JsonNode mappersNode = rootNode.get("mappers");
if (mappersNode != null && mappersNode.isArray()) {
for (final JsonNode element : mappersNode) {
mappersList.add(new TemplateMapper(element.get("mappersorder").asInt(), element.get("mapperskey").asText(),
element.get("mappersvalue").asText()));
}
}
} catch (final Exception e) {
throw new RuntimeException("Failed to parse template mappers from JSON", e);
}

return new Template(name, text, entity, type, mappersList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package org.apache.fineract.template.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.gson.annotations.SerializedName;

@JsonSerialize(using = TemplateEntitySerializer.class)
public enum TemplateEntity {

@SerializedName("client")
CLIENT(0, "client"), @SerializedName("loan")
@JsonProperty("client")
CLIENT(0, "client"), @JsonProperty("loan")
LOAN(1, "loan");

private final int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package org.apache.fineract.template.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.gson.annotations.SerializedName;

@JsonSerialize(using = TemplateTypeSerializer.class)
public enum TemplateType {

@SerializedName("Document")
DOCUMENT(0, "Document"), @SerializedName("SMS")
@JsonProperty("Document")
DOCUMENT(0, "Document"), @JsonProperty("SMS")
SMS(2, "SMS");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.apache.fineract.template.service;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -94,14 +94,21 @@ public CommandProcessingResult updateTemplate(final Long templateId, final JsonC
}
template.setType(type);

final JsonArray array = command.arrayOfParameterNamed("mappers");
final List<TemplateMapper> mappersList = new ArrayList<>();
for (final JsonElement element : array) {
mappersList.add(new TemplateMapper(element.getAsJsonObject().get("mappersorder").getAsInt(),
element.getAsJsonObject().get("mapperskey").getAsString(),
element.getAsJsonObject().get("mappersvalue").getAsString()));
try {
final ObjectMapper objectMapper = new ObjectMapper();
final JsonNode rootNode = objectMapper.readTree(command.json());
final JsonNode mappersNode = rootNode.get("mappers");
final List<TemplateMapper> mappersList = new ArrayList<>();
if (mappersNode != null && mappersNode.isArray()) {
for (final JsonNode element : mappersNode) {
mappersList.add(new TemplateMapper(element.get("mappersorder").asInt(), element.get("mapperskey").asText(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For parsing the mappers array, would it make sense to leverage Jackson’s data binding (e.g., mapping directly to a List) instead of manual tree traversal, or is this intentional for now?

element.get("mappersvalue").asText()));
}
}
template.setMappers(mappersList);
} catch (final Exception e) {
throw new RuntimeException("Failed to parse template mappers from JSON", e);
}
template.setMappers(mappersList);

this.templateRepository.saveAndFlush(template);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.cucumber.java8.En;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -75,10 +72,8 @@ private String compile(String templateText, Map<String, Object> scope) throws IO
return tms.compile(template, scope);
}

private Map<String, Object> parse(String data) {
Gson gson = new Gson();
Type ssMap = new TypeToken<Map<String, Object>>() {}.getType();
JsonElement json = JsonParser.parseString(data);
return gson.fromJson(json, ssMap);
private Map<String, Object> parse(String data) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(data, new TypeReference<Map<String, Object>>() {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.fineract.integrationtests;

import com.google.gson.Gson;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void setup() {

@Disabled
@Test
public void test() {
public void test() throws Exception {

final HashMap<String, String> metadata = new HashMap<>();
metadata.put("user", "resource_url");
Expand All @@ -64,8 +64,8 @@ public void test() {
ArrayList<?> get = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_TEMPLATES_URL, "");
final int entriesBeforeTest = get.size();

final Integer id = Utils.performServerPost(this.requestSpec, this.responseSpec, GET_TEMPLATES_URL, new Gson().toJson(map),
"resourceId");
final Integer id = Utils.performServerPost(this.requestSpec, this.responseSpec, GET_TEMPLATES_URL,
new ObjectMapper().writeValueAsString(map), "resourceId");

final String templateUrlForId = String.format("/fineract-provider/api/v1/templates/%s?tenantIdentifier=default", id);

Expand Down
Loading