Skip to content

Commit

Permalink
Inkomoko uat (#96)
Browse files Browse the repository at this point in the history
* Cglt 141 (#89)

* CGLT-141:Added API to pull loan portfolio data

* CGLT-141: Improved GSON serialisation by adding annotations

* CGLT-141: Ensured null values are added

* CGLT-145: Ignoring ssl cert for odoo journal posting

* FSI-124: Allow rescheduling loan with paid/waived penalties

* Cglt 146 (#93)

* CGLT-146: Modified odoo callback to handle responses better

* CGLT-146: change log syntax error

* CGLT-146: persist odoo changes to DB

* FSI-124: Fix loan reschedule approval

---------

Co-authored-by: ntnduku <[email protected]>
Co-authored-by: Deepika1095 <[email protected]>
Co-authored-by: Niceta Nduku <[email protected]>
Co-authored-by: Frank Nkuyahaga <[email protected]>
  • Loading branch information
5 people authored Nov 7, 2024
1 parent fb8f80d commit 61587b0
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public class JournalEntry extends AbstractAuditableCustom {
@Column(name = "odoo_ack")
private boolean odooAck;

@Column(name = "odoo_response")
private String odooResponse;

@Column(name = "is_oddo_posted")
private boolean isOddoPosted;

Expand Down Expand Up @@ -260,6 +263,14 @@ public void setOddoPosted(boolean isOddoPosted) {
this.isOddoPosted = isOddoPosted;
}

public String getOdooResponse() {
return odooResponse;
}

public void setOdooResponse(String odooResponse) {
this.odooResponse = odooResponse;
}

public void setOdooAck(boolean odooAck) {
this.odooAck= odooAck;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final in

@Override
public Collection<AuditData> retrieveAuditEntries(final SQLBuilder extraCriteria, final boolean includeJson) {
return retrieveEntries("audit", extraCriteria, " order by aud.id DESC ",
includeJson);
return retrieveEntries("audit", extraCriteria, " order by aud.id DESC ", includeJson);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;

Expand All @@ -41,7 +43,7 @@ public interface OdooService {
public void postCustomerUpdatedDetailsToOddo() throws JobExecutionException;

JsonObject createJournalEntryToOddo(List<JournalEntry> entry, Long loanTransactionId, Long transactionType, Boolean isReversed, String loanAccount)
throws IOException;
throws IOException, NoSuchAlgorithmException, KeyManagementException;

String updateJournalEntryWithOdooStatus(String stringRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -37,6 +39,10 @@
import java.util.concurrent.Executors;
import java.util.regex.Pattern;
import javax.annotation.PostConstruct;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -332,7 +338,7 @@ public void updateClientWithOdooUpdateStatus(boolean status, Client client) {

@Override
public JsonObject createJournalEntryToOddo(List<JournalEntry> list, Long loanTransactionId, Long transactionType, Boolean isReversed, String loanAccountNo)
throws IOException {
throws IOException, NoSuchAlgorithmException, KeyManagementException {

final Integer uid = loginToOddo();
if (uid > 0) {
Expand Down Expand Up @@ -390,37 +396,96 @@ public JsonObject createJournalEntryToOddo(List<JournalEntry> list, Long loanTra
}

@Override
public String updateJournalEntryWithOdooStatus(String stringRequest){
public String updateJournalEntryWithOdooStatus(String stringRequest) {

JsonObject odooRequest = JsonParser.parseString(stringRequest).getAsJsonObject();
LOG.info("Received Odoo Journal entry response " + stringRequest);

JsonObject odooRequest = JsonParser.parseString(stringRequest).getAsJsonObject();
JsonObject response = new JsonObject();

String odooJournalId = getStringField(odooRequest, "journal_entry_no");
String responseCode = getStringField(odooRequest, "responseCode");
String responseMessage = getStringField(odooRequest, "responseCode");


String transactionId = getStringField(odooRequest, "cbs_journal_entry_id");

if (odooJournalId != null) {
List<JournalEntry> journalEntries = this.journalEntryRepository.findJournalEntriesByLoanTransactionId("L"+transactionId);

for (JournalEntry je : journalEntries){
je.setOddoPosted(true);
je.setOdooJournalId(odooJournalId);
if (transactionId != null) {
List<JournalEntry> journalEntries = this.journalEntryRepository.findJournalEntriesByLoanTransactionId("L" + transactionId);


if (responseCode.equals("POSTED") || responseCode.equals("REVERSED") || responseCode.equals("EXISTING")) {

String odooJournalId = getStringField(odooRequest, "journal_entry_no");

if (odooJournalId != null) {

for (JournalEntry je : journalEntries) {
je.setOddoPosted(true);
je.setOdooJournalId(odooJournalId);
je.setOdooResponse(responseCode);
this.journalEntryRepository.saveAndFlush(je);
}
}

} else {
LOG.info("Loan Transaction Not Posted to Odoo - Code:{} - Message: {} ", responseCode, responseMessage);
for (JournalEntry je : journalEntries) {
je.setOdooResponse(responseCode + ":" + responseMessage);
this.journalEntryRepository.saveAndFlush(je);
}
}
}

response.addProperty("success", true);
response.addProperty("message", "Successful");
response.addProperty( "ack", true);
response.addProperty("success", true);
response.addProperty("message", "Successful");
response.addProperty( "ack", true);

return response.toString();
} else {
LOG.info("Odoo response has no cbs transactionId");

response.addProperty("success", false);
response.addProperty("message", "cbs_journal_entry_id not found");
response.addProperty("data", stringRequest);
response.addProperty( "ack", true);
}

return response.toString();
}

private JsonObject sendRequest(String payload) throws IOException {
OkHttpClient httpClient = new OkHttpClient();

private JsonObject sendRequest(String payload) throws IOException, NoSuchAlgorithmException, KeyManagementException {

// Trust all certificates
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType){}

@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType){}

@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[]{}; }
}
};

// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

// Create OkHttpClient that ignores SSL validation
OkHttpClient httpClient = new OkHttpClient.Builder()
.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0])
.hostnameVerifier((hostname, session) -> true)
.build();

RequestBody requestBody = RequestBody.create(MediaType.parse(FORM_URL_CONTENT_TYPE), payload);
Request request = new Request.Builder().url(celeryUrl + "/api/cbs_journal_entry").post(requestBody)
.addHeader("Content-Type", "application/json").build();
Request request = new Request.Builder()
.url(celeryUrl + "/api/cbs_journal_entry")
.post(requestBody)
.addHeader("Content-Type", "application/json")
.build();

Response response = httpClient.newCall(request).execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public static boolean exportXLSX(final MultivaluedMap<String, String> queryParam
return exportXLSX;
}

public static boolean exportAPI(MultivaluedMap<String, String> queryParams) {

boolean exportAPI = false;
if (queryParams.getFirst("exportAPI") != null) {
final String exportAPIValue = queryParams.getFirst("exportAPI");
exportAPI = "true".equalsIgnoreCase(exportAPIValue);
}
return exportAPI;
}

public static boolean parameterType(final MultivaluedMap<String, String> queryParams) {
boolean parameterType = false;
if (queryParams.getFirst("parameterType") != null) {
Expand Down Expand Up @@ -187,4 +197,6 @@ public static Map<String, String> asMap(final MultivaluedMap<String, String> que

return map;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class GenericResultsetData {

private final List<ResultsetColumnHeaderData> columnHeaders;
private final List<ResultsetRowData> data;

@Setter
private Integer count;

Expand All @@ -45,6 +46,10 @@ public List<ResultsetRowData> getData() {
return this.data;
}

public Integer getCount() {
return count;
}

public String getColTypeOfColumnNamed(final String columnName) {

String colType = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.infrastructure.dataqueries.data;

import lombok.Data;

import java.util.List;


@Data
public class LoanPortfolioData {

private List<LoanPortfolioRowData> data;
private Integer count;

}
Loading

0 comments on commit 61587b0

Please sign in to comment.