use of org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken in project fineract by apache.
the class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl method createToken.
@Transactional
@Override
public CreditBureauToken createToken(Long bureauID) {
CreditBureauToken creditBureauToken = this.tokenRepositoryWrapper.getToken();
// check the expiry date of the previous token.
if (creditBureauToken != null) {
Date current = new Date();
Date getExpiryDate = creditBureauToken.getTokenExpiryDate();
if (getExpiryDate.before(current)) {
this.tokenRepositoryWrapper.delete(creditBureauToken);
creditBureauToken = null;
}
}
if (creditBureauToken != null) {
creditBureauToken = this.tokenRepositoryWrapper.getToken();
}
String userName = getCreditBureauConfiguration(bureauID.intValue(), CreditBureauConfigurations.USERNAME.toString());
String password = getCreditBureauConfiguration(bureauID.intValue(), CreditBureauConfigurations.PASSWORD.toString());
String subscriptionId = getCreditBureauConfiguration(bureauID.intValue(), CreditBureauConfigurations.SUBSCRIPTIONID.toString());
String subscriptionKey = getCreditBureauConfiguration(bureauID.intValue(), CreditBureauConfigurations.SUBSCRIPTIONKEY.toString());
if (creditBureauToken == null) {
String url = getCreditBureauConfiguration(bureauID.intValue(), CreditBureauConfigurations.TOKENURL.toString());
String process = "token";
String nrcId = null;
Long uniqueID = 0L;
String result = this.okHttpConnectionMethod(userName, password, subscriptionKey, subscriptionId, url, null, null, null, uniqueID, nrcId, process);
// created token will be storing it into database
final CommandWrapper wrapper = new CommandWrapperBuilder().withJson(result).build();
final String json = wrapper.getJson();
JsonCommand apicommand = null;
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json);
apicommand = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(), wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId(), wrapper.getCreditBureauId(), wrapper.getOrganisationCreditBureauId());
this.fromApiJsonDeserializer.validateForCreate(apicommand.json());
final CreditBureauToken generatedtoken = CreditBureauToken.fromJson(apicommand);
final CreditBureauToken credittoken = this.tokenRepositoryWrapper.getToken();
if (credittoken != null) {
this.tokenRepositoryWrapper.delete(credittoken);
}
this.tokenRepositoryWrapper.save(generatedtoken);
creditBureauToken = this.tokenRepositoryWrapper.getToken();
}
return creditBureauToken;
}
use of org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken in project fineract by apache.
the class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl method getCreditReportFromThitsaWorks.
@Transactional
@Override
public CreditBureauReportData getCreditReportFromThitsaWorks(final JsonCommand command) {
this.context.authenticatedUser();
String nrcId = command.stringValueOfParameterNamed("NRC");
String bureauID = command.stringValueOfParameterNamed("creditBureauID");
Integer creditBureauId = Integer.parseInt(bureauID);
String token = null;
String userName = getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.USERNAME.toString());
String password = getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.PASSWORD.toString());
String subscriptionId = getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.SUBSCRIPTIONID.toString());
String subscriptionKey = getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.SUBSCRIPTIONKEY.toString());
CreditBureauToken creditbureautoken = createToken(creditBureauId.longValue());
token = creditbureautoken.getCurrentToken();
// will use only "NRC" part of code from common http method to get data based on nrc
String process = "NRC";
String url = getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.SEARCHURL.toString());
String nrcUrl = url + nrcId;
String searchResult = this.okHttpConnectionMethod(userName, password, subscriptionKey, subscriptionId, nrcUrl, token, null, null, 0L, nrcId, process);
if (process.equals("NRC")) {
Long uniqueID = this.extractUniqueId(searchResult);
process = "CreditReport";
url = getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.CREDITREPORTURL.toString());
String creditReportUrl = url + uniqueID;
searchResult = this.okHttpConnectionMethod(userName, password, subscriptionKey, subscriptionId, creditReportUrl, token, null, null, uniqueID, null, process);
}
// after getting the result(creditreport) from httpconnection-response it will assign creditreport to generic
// creditreportdata object
JsonObject reportObject = JsonParser.parseString(searchResult).getAsJsonObject();
// Credit Reports Stored into Generic CreditReportData
JsonObject jsonData = null;
JsonElement element = reportObject.get("Data");
if (!(element instanceof JsonNull)) {
// NOTE : "element instanceof JsonNull" is for handling empty values (and
// assigning null) while fetching data from results
jsonData = (JsonObject) element;
}
JsonObject borrowerInfos = null;
String borrowerInfo = null;
element = jsonData.get("BorrowerInfo");
if (!(element instanceof JsonNull)) {
borrowerInfos = (JsonObject) element;
Gson gson = new Gson();
borrowerInfo = gson.toJson(borrowerInfos);
}
String Name = borrowerInfos.get("Name").toString();
String Gender = borrowerInfos.get("Gender").toString();
String Address = borrowerInfos.get("Address").toString();
String creditScore = "CreditScore";
creditScore = getJsonObjectToString(creditScore, element, jsonData);
String activeLoans = "ActiveLoans";
JsonArray activeLoansArray = getJsonObjectToArray(activeLoans, element, jsonData);
String[] activeLoanStringArray = null;
if (activeLoansArray != null) {
activeLoanStringArray = convertArrayintoStringArray(activeLoansArray);
}
String writeOffLoans = "WriteOffLoans";
JsonArray writeOffLoansArray = getJsonObjectToArray(writeOffLoans, element, jsonData);
String[] writeoffLoanStringArray = null;
if (writeOffLoansArray != null) {
writeoffLoanStringArray = convertArrayintoStringArray(writeOffLoansArray);
}
return CreditBureauReportData.instance(Name, Gender, Address, creditScore, borrowerInfo, activeLoanStringArray, writeoffLoanStringArray);
}
use of org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken in project fineract by apache.
the class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl method addCreditReport.
@Override
@Transactional
public String addCreditReport(Long bureauId, File creditReport, FormDataContentDisposition fileDetail) {
Integer creditBureauId = bureauId.intValue();
String userName = this.getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.USERNAME.toString());
String password = this.getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.PASSWORD.toString());
String subscriptionId = this.getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.SUBSCRIPTIONID.toString());
String subscriptionKey = this.getCreditBureauConfiguration(creditBureauId, CreditBureauConfigurations.SUBSCRIPTIONKEY.toString());
CreditBureauToken creditbureautoken = this.createToken(creditBureauId.longValue());
String token = creditbureautoken.getCurrentToken();
CreditBureauConfiguration addReportURL = this.configDataRepository.getCreditBureauConfigData(creditBureauId, "addCreditReporturl");
String url = addReportURL.getValue();
String process = "UploadCreditReport";
String responseMessage = this.okHttpConnectionMethod(userName, password, subscriptionKey, subscriptionId, url, token, creditReport, fileDetail, 0L, null, process);
return responseMessage;
}
Aggregations