soa config
This commit is contained in:
@@ -54,6 +54,15 @@ public class DataSeeder implements CommandLineRunner {
|
|||||||
|
|
||||||
List<SoaMappingConfig> configs = new ArrayList<>();
|
List<SoaMappingConfig> configs = new ArrayList<>();
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// KOTRAN GLOBAL: Header Standar (Selalu ikut di semua Kotran)
|
||||||
|
// ==========================================
|
||||||
|
configs.add(createConfig("GLOBAL", "RequestHeader.MessageSender", "String", "'TPS_CORE'", null, 1));
|
||||||
|
configs.add(createConfig("GLOBAL", "RequestHeader.MessageType", "String", "'JSON'", null, 1));
|
||||||
|
configs.add(createConfig("GLOBAL", "RequestHeader.ChannelId", "String", "'116'", null, 1));
|
||||||
|
// Global Date: Dieksekusi secara dinamis setiap kali request terjadi
|
||||||
|
configs.add(createConfig("GLOBAL", "RequestHeader.GlobalTimestamp", "String", "new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format(new java.util.Date())", null, 1));
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// KOTRAN 1001: Standar Mapping & Simple Math
|
// KOTRAN 1001: Standar Mapping & Simple Math
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -70,7 +79,6 @@ public class DataSeeder implements CommandLineRunner {
|
|||||||
configs.add(createConfig("1002", "TLBF_EQV_AMT", "Number", "#payment.currency == 'USD' ? (#transaction.amount * 15000) : #transaction.amount", null, 1));
|
configs.add(createConfig("1002", "TLBF_EQV_AMT", "Number", "#payment.currency == 'USD' ? (#transaction.amount * 15000) : #transaction.amount", null, 1));
|
||||||
// Concatenation string
|
// Concatenation string
|
||||||
configs.add(createConfig("1002", "TLBF_REF", "String", "'REF-' + #transaction.id", null, 1));
|
configs.add(createConfig("1002", "TLBF_REF", "String", "'REF-' + #transaction.id", null, 1));
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// KOTRAN 1003: NPE Handling & Default Values
|
// KOTRAN 1003: NPE Handling & Default Values
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -47,18 +48,26 @@ public class MappingEngineService {
|
|||||||
context.setVariable("payment", payment);
|
context.setVariable("payment", payment);
|
||||||
// Jika ke depan ada object baru (misal Customer), cukup tambahkan: context.setVariable("customer", customerData);
|
// Jika ke depan ada object baru (misal Customer), cukup tambahkan: context.setVariable("customer", customerData);
|
||||||
|
|
||||||
// 4. Fetch Mapping Rules
|
// 4. Fetch Mapping Rules (Perubahan untuk Global Config)
|
||||||
List<SoaMappingConfig> configs = configRepo.findByKotranAndStatusOrderByTargetFieldNmAsc(kotran, "ACTIVE");
|
// Ambil rule GLOBAL (header statis)
|
||||||
|
List<SoaMappingConfig> globalConfigs = configRepo.findByKotranAndStatusOrderByTargetFieldNmAsc("GLOBAL", "ACTIVE");
|
||||||
|
|
||||||
if (configs.isEmpty()) {
|
// Ambil rule spesifik sesuai Kotran yang direquest
|
||||||
|
List<SoaMappingConfig> specificConfigs = configRepo.findByKotranAndStatusOrderByTargetFieldNmAsc(kotran, "ACTIVE");
|
||||||
|
|
||||||
|
if (specificConfigs.isEmpty()) {
|
||||||
throw new RuntimeException("Konfigurasi tidak ditemukan untuk Kotran: " + kotran);
|
throw new RuntimeException("Konfigurasi tidak ditemukan untuk Kotran: " + kotran);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gabungkan rule: Global dievaluasi duluan, baru ditimpa/ditambah oleh Specific
|
||||||
|
List<SoaMappingConfig> allConfigs = new ArrayList<>(globalConfigs);
|
||||||
|
allConfigs.addAll(specificConfigs);
|
||||||
|
|
||||||
// Menggunakan LinkedHashMap agar urutan field JSON sesuai urutan konfigurasi di Database
|
// Menggunakan LinkedHashMap agar urutan field JSON sesuai urutan konfigurasi di Database
|
||||||
Map<String, Object> payload = new LinkedHashMap<>();
|
Map<String, Object> payload = new LinkedHashMap<>();
|
||||||
|
|
||||||
// 5. Evaluation Loop
|
// 5. Evaluation Loop
|
||||||
for (SoaMappingConfig config : configs) {
|
for (SoaMappingConfig config : allConfigs) {
|
||||||
Object evaluatedValue = null;
|
Object evaluatedValue = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -94,7 +103,7 @@ public class MappingEngineService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Mapping selesai. Total config field yang diproses: {}", configs.size());
|
log.info("Mapping selesai. Total config field yang diproses: {}", allConfigs.size());
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,5 +10,4 @@ spring:
|
|||||||
jpa:
|
jpa:
|
||||||
database-platform: org.hibernate.dialect.OracleDialect
|
database-platform: org.hibernate.dialect.OracleDialect
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: update
|
ddl-auto: update
|
||||||
show-sql: true
|
|
||||||
Reference in New Issue
Block a user