Search in sources :

Example 1 with CreditBureauToken

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;
}
Also used : CommandWrapperBuilder(org.apache.fineract.commands.service.CommandWrapperBuilder) JsonCommand(org.apache.fineract.infrastructure.core.api.JsonCommand) JsonElement(com.google.gson.JsonElement) CommandWrapper(org.apache.fineract.commands.domain.CommandWrapper) CreditBureauToken(org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with 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);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) CreditBureauToken(org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken) JsonNull(com.google.gson.JsonNull) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with CreditBureauToken

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;
}
Also used : CreditBureauConfiguration(org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfiguration) CreditBureauToken(org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CreditBureauToken (org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken)3 Transactional (org.springframework.transaction.annotation.Transactional)3 JsonElement (com.google.gson.JsonElement)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonNull (com.google.gson.JsonNull)1 JsonObject (com.google.gson.JsonObject)1 Date (java.util.Date)1 CommandWrapper (org.apache.fineract.commands.domain.CommandWrapper)1 CommandWrapperBuilder (org.apache.fineract.commands.service.CommandWrapperBuilder)1 JsonCommand (org.apache.fineract.infrastructure.core.api.JsonCommand)1 CreditBureauConfiguration (org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfiguration)1