nikpawar89 commented on a change in pull request #1235:
URL: https://github.com/apache/fineract/pull/1235#discussion_r475149812



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {

Review comment:
       mark private

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);
+                postConnection = (HttpURLConnection) 
CreditReportURL.openConnection();
+                postConnection.setRequestMethod("GET");
+
+            }
+
+            // common set of headers
+            postConnection.setRequestProperty("mcix-subscription-key", 
subscriptionKey);
+            postConnection.setRequestProperty("mcix-subscription-id", 
subscriptionId);
+            postConnection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+
+            // token header not used when creating token i.e. when token will 
be null
+            if (token != null) {
+                postConnection.setRequestProperty("Authorization", "Bearer " + 
token);
+            }
+
+            // this set of code only required for fetching uniqueID from Nrc 
fetched data (POST-SimpleSearch)
+            if (process.equals("NRC") || process.equals("token")) {
+                LOG.info("-----NRC & CREDITREPORT -----");
+                postConnection.setDoOutput(true);
+                OutputStream os = postConnection.getOutputStream();
+                os.write(post_params.getBytes(StandardCharsets.UTF_8));
+                os.flush();
+                os.close();
+
+            }
+
+            // common part of code in http connection method
+            int responseCode = postConnection.getResponseCode();
+
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                response = new StringBuilder();
+
+                LOG.info("----- RESPONSE OK-----");
+                BufferedReader in = new BufferedReader(new 
InputStreamReader(postConnection.getInputStream(), StandardCharsets.UTF_8));
+                while ((readLine = in.readLine()) != null) {
+                    response.append(readLine);
+                }
+                in.close();
+                result = response.toString();
+
+            } else {
+                LOG.info("Request is Invalid");
+            }
+
+        } catch (IOException e) {
+            LOG.error("Error occured.", e);
+        }
+    }
+
+    @SuppressWarnings({ "CatchAndPrintStackTrace", "DefaultCharset" })
+    @Override
+    @Transactional
+    @CacheEvict(value = "searchreport", key = 
"T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')")

Review comment:
       why do we need @CacheEvict

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);
+                postConnection = (HttpURLConnection) 
CreditReportURL.openConnection();
+                postConnection.setRequestMethod("GET");
+
+            }
+
+            // common set of headers
+            postConnection.setRequestProperty("mcix-subscription-key", 
subscriptionKey);
+            postConnection.setRequestProperty("mcix-subscription-id", 
subscriptionId);
+            postConnection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+
+            // token header not used when creating token i.e. when token will 
be null
+            if (token != null) {
+                postConnection.setRequestProperty("Authorization", "Bearer " + 
token);
+            }
+
+            // this set of code only required for fetching uniqueID from Nrc 
fetched data (POST-SimpleSearch)
+            if (process.equals("NRC") || process.equals("token")) {
+                LOG.info("-----NRC & CREDITREPORT -----");
+                postConnection.setDoOutput(true);
+                OutputStream os = postConnection.getOutputStream();
+                os.write(post_params.getBytes(StandardCharsets.UTF_8));
+                os.flush();
+                os.close();
+
+            }
+
+            // common part of code in http connection method
+            int responseCode = postConnection.getResponseCode();
+
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                response = new StringBuilder();
+
+                LOG.info("----- RESPONSE OK-----");
+                BufferedReader in = new BufferedReader(new 
InputStreamReader(postConnection.getInputStream(), StandardCharsets.UTF_8));
+                while ((readLine = in.readLine()) != null) {
+                    response.append(readLine);
+                }
+                in.close();
+                result = response.toString();
+
+            } else {
+                LOG.info("Request is Invalid");
+            }
+
+        } catch (IOException e) {
+            LOG.error("Error occured.", e);
+        }
+    }
+
+    @SuppressWarnings({ "CatchAndPrintStackTrace", "DefaultCharset" })
+    @Override
+    @Transactional
+    @CacheEvict(value = "searchreport", key = 
"T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')")
+    public CreditReportData retrieveAllSearchReport(final String searchId) {
+        String Name = null;
+        String Gender = null;
+        nrcId = searchId;
+        String Address = null;
+
+        this.context.authenticatedUser();
+
+        final CreditBureauTokenCredential credittokendata = 
this.tokenDataRepository.getTokenCredential();
+
+        if (credittokendata != null) {
+            userName = credittokendata.getUserName();
+            password = credittokendata.getPassword();
+            subscriptionId = credittokendata.getSubscriptionId();
+            subscriptionKey = credittokendata.getSubscriptionKey();
+
+            // validation required, incase when configuration is not stored in 
database while fetching data.
+        } else {
+
+            String configJson = "{ 'userName':'" + userName + "','password':'" 
+ password + "','subscriptionId':'" + subscriptionId
+                    + "','subscriptionKey':'" + subscriptionKey + "'}";
+
+            
this.fromApiJsonDeserializer.validateForUsingTokenConfig(configJson);
+        }
+
+        CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+        LOG.info("creditbureautoken : {} ", creditbureautoken);
+
+        // check the expiry date of the previous token.
+        if (creditbureautoken != null) {
+            Date current = new Date();
+            Date getExpiryDate = creditbureautoken.getTokenExpiryDate();
+
+            LOG.info("current date : {} ", current);
+            LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+            if (getExpiryDate.before(current)) {
+                LOG.info("The token is expired");
+                this.tokenRepository.delete(creditbureautoken);
+                creditbureautoken = null;
+            }
+        }
+        // storing token if it is valid token(not expired)
+        if (creditbureautoken != null) {
+            token = creditbureautoken.getCurrentToken();
+        }
+
+        // if token is not available or previous token is expired then create 
a new token
+        if (creditbureautoken == null) {
+
+            // using common http connection method for creating token
+            process = "token";
+            this.httpConnectionMethod();
+
+            JsonObject tokenObject = 
JsonParser.parseString(result).getAsJsonObject();
+            String expiresextra = tokenObject.get(".expires").toString();
+            String expires = expiresextra.substring(1, expiresextra.length() - 
1);
+            DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy 
kk:mm:ss zzz", Locale.ENGLISH);
+            try {
+                Date getExpiryDate = dateformat.parse(expires);
+                LOG.info("The expirydate {}", getExpiryDate);
+            } catch (ParseException Ex) {
+                LOG.error("Error occured.", Ex);
+            }
+
+            // created token will be storing it into database
+            final CommandWrapper wrapper = new 
CommandWrapperBuilder().withJson(result).build();
+            final String json = wrapper.getJson();
+            result = null;
+            JsonCommand apicommand = null;
+            boolean isApprovedByChecker = false;
+            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);
+
+            // saved new token
+            this.tokenRepository.save(generatedtoken);
+
+            // fetched
+            creditbureautoken = this.tokenRepository.getToken();
+            token = creditbureautoken.getCurrentToken();
+
+            // at this stage token is available for all cases i.e.(deleted 
expired token and saved new token)
+        }
+
+        // will use only "NRC" part of code from common http method to get 
data based on nrc
+        process = "NRC";
+        this.httpConnectionMethod();
+
+        // after fetching the data from httpconnection it will be come back 
here for fetching UniqueID from data
+        if (process.equals("NRC")) {
+
+            // to fetch the Unique ID from Result
+            JsonObject jsonObject = 
JsonParser.parseString(result).getAsJsonObject();
+            JsonArray jArray = jsonObject.getAsJsonArray("Data");
+            JsonObject jobject = jArray.get(0).getAsJsonObject();
+            String uniqueIdString = jobject.get("UniqueID").toString();
+
+            // cleaned the uniqueID value. Example id: "123" to 123
+            String TrimUniqueId = uniqueIdString.substring(1, 
uniqueIdString.length() - 1);
+
+            // unique ID is stored
+            uniqueID = Long.parseLong(TrimUniqueId);
+
+            // will use "CREDITREPORT" part of code from common http method to 
fetch creditreport based on UniqueID
+            process = "CREDITREPORT";
+            this.httpConnectionMethod();
+
+        }
+
+        // after fetching the data from httpconnection it will be come back 
here to assign data(result) to generic
+        // creditreportdata object
+
+        JsonObject reportObject = 
JsonParser.parseString(result).getAsJsonObject();
+
+        JsonObject borrowerInfo = null;
+        JsonObject CreditScore = null;
+        JsonArray ActiveLoans = null;
+        JsonArray PaidLoans = null;
+
+        // Credit Reports Stored into Generic CreditReportData
+        JsonObject data = null;
+        JsonElement element = reportObject.get("Data");
+
+        if (!(element instanceof JsonNull)) { // NOTE : "element instanceof 
JsonNull" is for handling empty values (and

Review comment:
       is there a better way to do this null check?
   using instanceof is not considered as good practice:
   https://dzone.com/articles/instanceof-considered-harmful

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;

Review comment:
       please keep the scope of variables as small as possible. Applies to all 
the variables below

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);

Review comment:
       url should be part of configuration and should not be hard coded.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);

Review comment:
       here as well

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);

Review comment:
       same here

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {

Review comment:
       I liked this approach, its just that make process as parameter to this 
method.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);
+                postConnection = (HttpURLConnection) 
CreditReportURL.openConnection();
+                postConnection.setRequestMethod("GET");
+
+            }
+
+            // common set of headers
+            postConnection.setRequestProperty("mcix-subscription-key", 
subscriptionKey);
+            postConnection.setRequestProperty("mcix-subscription-id", 
subscriptionId);
+            postConnection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+
+            // token header not used when creating token i.e. when token will 
be null
+            if (token != null) {
+                postConnection.setRequestProperty("Authorization", "Bearer " + 
token);
+            }
+
+            // this set of code only required for fetching uniqueID from Nrc 
fetched data (POST-SimpleSearch)
+            if (process.equals("NRC") || process.equals("token")) {
+                LOG.info("-----NRC & CREDITREPORT -----");
+                postConnection.setDoOutput(true);
+                OutputStream os = postConnection.getOutputStream();
+                os.write(post_params.getBytes(StandardCharsets.UTF_8));
+                os.flush();
+                os.close();
+
+            }
+
+            // common part of code in http connection method
+            int responseCode = postConnection.getResponseCode();
+
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                response = new StringBuilder();
+
+                LOG.info("----- RESPONSE OK-----");
+                BufferedReader in = new BufferedReader(new 
InputStreamReader(postConnection.getInputStream(), StandardCharsets.UTF_8));
+                while ((readLine = in.readLine()) != null) {
+                    response.append(readLine);
+                }
+                in.close();
+                result = response.toString();
+
+            } else {
+                LOG.info("Request is Invalid");
+            }
+
+        } catch (IOException e) {
+            LOG.error("Error occured.", e);
+        }
+    }
+
+    @SuppressWarnings({ "CatchAndPrintStackTrace", "DefaultCharset" })
+    @Override
+    @Transactional
+    @CacheEvict(value = "searchreport", key = 
"T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')")
+    public CreditReportData retrieveAllSearchReport(final String searchId) {
+        String Name = null;
+        String Gender = null;
+        nrcId = searchId;
+        String Address = null;
+
+        this.context.authenticatedUser();
+
+        final CreditBureauTokenCredential credittokendata = 
this.tokenDataRepository.getTokenCredential();
+
+        if (credittokendata != null) {
+            userName = credittokendata.getUserName();
+            password = credittokendata.getPassword();
+            subscriptionId = credittokendata.getSubscriptionId();
+            subscriptionKey = credittokendata.getSubscriptionKey();
+
+            // validation required, incase when configuration is not stored in 
database while fetching data.
+        } else {
+
+            String configJson = "{ 'userName':'" + userName + "','password':'" 
+ password + "','subscriptionId':'" + subscriptionId
+                    + "','subscriptionKey':'" + subscriptionKey + "'}";
+
+            
this.fromApiJsonDeserializer.validateForUsingTokenConfig(configJson);
+        }
+
+        CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+        LOG.info("creditbureautoken : {} ", creditbureautoken);
+
+        // check the expiry date of the previous token.
+        if (creditbureautoken != null) {
+            Date current = new Date();
+            Date getExpiryDate = creditbureautoken.getTokenExpiryDate();
+
+            LOG.info("current date : {} ", current);
+            LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+            if (getExpiryDate.before(current)) {
+                LOG.info("The token is expired");
+                this.tokenRepository.delete(creditbureautoken);
+                creditbureautoken = null;
+            }
+        }
+        // storing token if it is valid token(not expired)
+        if (creditbureautoken != null) {
+            token = creditbureautoken.getCurrentToken();
+        }
+
+        // if token is not available or previous token is expired then create 
a new token
+        if (creditbureautoken == null) {
+
+            // using common http connection method for creating token
+            process = "token";
+            this.httpConnectionMethod();
+
+            JsonObject tokenObject = 
JsonParser.parseString(result).getAsJsonObject();
+            String expiresextra = tokenObject.get(".expires").toString();
+            String expires = expiresextra.substring(1, expiresextra.length() - 
1);
+            DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy 
kk:mm:ss zzz", Locale.ENGLISH);

Review comment:
       keep it simple : SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy 
HH:mm:ss.SSS");

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditBureauToken.java
##########
@@ -0,0 +1,121 @@
+package org.apache.fineract.infrastructure.creditbureau.domain;
+
+/**
+ * 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.
+ */
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import 
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+@Entity
+@Table(name = "m_creditbureau_token")
+public class CreditBureauToken extends AbstractPersistableCustom {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauToken.class);
+
+    @Column(name = "username")
+    private String userName;
+
+    @Column(name = "token")
+    private String accessToken;
+
+    @Column(name = "token_type")
+    private String tokenType;
+
+    @Column(name = "expires_in")
+    private String expiresIn;
+
+    @Column(name = "issued")
+    private String issued;
+
+    @Column(name = "expires")
+    private Date expires;
+
+    public CreditBureauToken(String userName, String accessToken, String 
tokenType, String expiresIn, String issued, Date expires) {
+        this.userName = userName;
+        this.accessToken = accessToken;
+        this.tokenType = tokenType;
+        this.expiresIn = expiresIn;
+        this.issued = issued;
+        this.expires = expires;
+    }
+
+    public CreditBureauToken() {
+        this.userName = null;
+        this.accessToken = null;
+        this.tokenType = null;
+        this.expiresIn = null;
+        this.issued = null;
+        this.expires = null;
+    }
+
+    public static CreditBureauToken fromJson(final JsonCommand command) {
+        final String userName = 
command.stringValueOfParameterNamed("userName");
+        final String accessToken = 
command.stringValueOfParameterNamed("access_token");
+        final String tokenType = 
command.stringValueOfParameterNamed("token_type");
+        final String expiresIn = 
command.stringValueOfParameterNamed("expires_in");
+        final String issued = command.stringValueOfParameterNamed(".issued");
+        final String expiry = command.stringValueOfParameterNamed(".expires");
+
+        LOG.info("Expiry {}", expiry);
+
+        DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy 
kk:mm:ss zzz", Locale.ENGLISH);

Review comment:
       SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);
+                postConnection = (HttpURLConnection) 
CreditReportURL.openConnection();
+                postConnection.setRequestMethod("GET");
+
+            }
+
+            // common set of headers
+            postConnection.setRequestProperty("mcix-subscription-key", 
subscriptionKey);
+            postConnection.setRequestProperty("mcix-subscription-id", 
subscriptionId);
+            postConnection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+
+            // token header not used when creating token i.e. when token will 
be null
+            if (token != null) {
+                postConnection.setRequestProperty("Authorization", "Bearer " + 
token);
+            }
+
+            // this set of code only required for fetching uniqueID from Nrc 
fetched data (POST-SimpleSearch)
+            if (process.equals("NRC") || process.equals("token")) {

Review comment:
       Try resources could be helpful here, please check out the java doc.

##########
File path: fineract-provider/config/swagger/fineract-input.yaml
##########
@@ -0,0 +1,37 @@
+openapi: 3.0.3

Review comment:
       did you intend to add this File in commit?

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);
+                postConnection = (HttpURLConnection) 
CreditReportURL.openConnection();
+                postConnection.setRequestMethod("GET");
+
+            }
+
+            // common set of headers
+            postConnection.setRequestProperty("mcix-subscription-key", 
subscriptionKey);
+            postConnection.setRequestProperty("mcix-subscription-id", 
subscriptionId);
+            postConnection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+
+            // token header not used when creating token i.e. when token will 
be null
+            if (token != null) {
+                postConnection.setRequestProperty("Authorization", "Bearer " + 
token);
+            }
+
+            // this set of code only required for fetching uniqueID from Nrc 
fetched data (POST-SimpleSearch)
+            if (process.equals("NRC") || process.equals("token")) {
+                LOG.info("-----NRC & CREDITREPORT -----");
+                postConnection.setDoOutput(true);
+                OutputStream os = postConnection.getOutputStream();
+                os.write(post_params.getBytes(StandardCharsets.UTF_8));
+                os.flush();
+                os.close();
+
+            }
+
+            // common part of code in http connection method
+            int responseCode = postConnection.getResponseCode();
+
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                response = new StringBuilder();
+
+                LOG.info("----- RESPONSE OK-----");
+                BufferedReader in = new BufferedReader(new 
InputStreamReader(postConnection.getInputStream(), StandardCharsets.UTF_8));
+                while ((readLine = in.readLine()) != null) {
+                    response.append(readLine);
+                }
+                in.close();
+                result = response.toString();

Review comment:
       I think result should be the return type of this method.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,347 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.creditbureau.data.CreditReportData;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauReportsReadPlatformServiceImpl implements 
CreditBureauReportsReadPlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauReportsReadPlatformServiceImpl.class);
+    private final JdbcTemplate jdbcTemplate;
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+
+    @Autowired
+    public CreditBureauReportsReadPlatformServiceImpl(final 
PlatformSecurityContext context, final RoutingDataSource dataSource,
+            final FromJsonHelper fromApiJsonHelper, final 
TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer) {
+        this.context = context;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+        this.tokenRepository = tokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+    }
+
+    String nrcId = null;
+    Long uniqueID = 0L;
+    String userName = "";
+    String password = "";
+    String subscriptionId = "";
+    String subscriptionKey = "";
+
+    StringBuilder response = new StringBuilder();
+    HttpURLConnection postConnection;
+    String tokenDate;
+    String token = null;
+    String process = null;
+    String result = null;
+
+    public void httpConnectionMethod() {
+        try {
+            String readLine = null;
+            String post_params = null;
+
+            if (process.equals("token")) {
+                LOG.info("-----creating new token-----");
+                post_params = "\n" + "BODY=x-www-form-urlencoded&\r\n" + 
"grant_type=password&\r\n" + "userName=" + userName + "&\r\n"
+                        + "password=" + password + "&\r\n";
+
+                URL tokenurl = new 
URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+                readLine = null;
+                postConnection = (HttpURLConnection) tokenurl.openConnection();
+                postConnection.setRequestMethod("POST");
+
+            } else if (process.equals("NRC")) {
+                // Search Methods
+                LOG.info("-----Search by NRC-----");
+                post_params = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
+
+                URL NrcURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="; + 
nrcId);
+                postConnection = (HttpURLConnection) NrcURL.openConnection();
+                postConnection.setRequestMethod("POST");
+            }
+
+            else if (process.equals("CREDITREPORT")) {
+                LOG.info("-----Search by CREDIT_REPORT-----");
+                URL CreditReportURL = new 
URL("https://mmcix.azure-api.net/qa/20200324/api/Dashboard/GetCreditReport?uniqueId=";
 + uniqueID);
+                postConnection = (HttpURLConnection) 
CreditReportURL.openConnection();
+                postConnection.setRequestMethod("GET");
+
+            }
+
+            // common set of headers
+            postConnection.setRequestProperty("mcix-subscription-key", 
subscriptionKey);
+            postConnection.setRequestProperty("mcix-subscription-id", 
subscriptionId);
+            postConnection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+
+            // token header not used when creating token i.e. when token will 
be null
+            if (token != null) {
+                postConnection.setRequestProperty("Authorization", "Bearer " + 
token);
+            }
+
+            // this set of code only required for fetching uniqueID from Nrc 
fetched data (POST-SimpleSearch)
+            if (process.equals("NRC") || process.equals("token")) {
+                LOG.info("-----NRC & CREDITREPORT -----");
+                postConnection.setDoOutput(true);
+                OutputStream os = postConnection.getOutputStream();
+                os.write(post_params.getBytes(StandardCharsets.UTF_8));
+                os.flush();
+                os.close();
+
+            }
+
+            // common part of code in http connection method
+            int responseCode = postConnection.getResponseCode();
+
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                response = new StringBuilder();
+
+                LOG.info("----- RESPONSE OK-----");
+                BufferedReader in = new BufferedReader(new 
InputStreamReader(postConnection.getInputStream(), StandardCharsets.UTF_8));
+                while ((readLine = in.readLine()) != null) {
+                    response.append(readLine);
+                }
+                in.close();
+                result = response.toString();
+
+            } else {
+                LOG.info("Request is Invalid");
+            }
+
+        } catch (IOException e) {
+            LOG.error("Error occured.", e);
+        }
+    }
+
+    @SuppressWarnings({ "CatchAndPrintStackTrace", "DefaultCharset" })
+    @Override
+    @Transactional
+    @CacheEvict(value = "searchreport", key = 
"T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')")
+    public CreditReportData retrieveAllSearchReport(final String searchId) {
+        String Name = null;
+        String Gender = null;
+        nrcId = searchId;
+        String Address = null;
+
+        this.context.authenticatedUser();
+
+        final CreditBureauTokenCredential credittokendata = 
this.tokenDataRepository.getTokenCredential();
+
+        if (credittokendata != null) {
+            userName = credittokendata.getUserName();
+            password = credittokendata.getPassword();
+            subscriptionId = credittokendata.getSubscriptionId();
+            subscriptionKey = credittokendata.getSubscriptionKey();
+
+            // validation required, incase when configuration is not stored in 
database while fetching data.
+        } else {
+
+            String configJson = "{ 'userName':'" + userName + "','password':'" 
+ password + "','subscriptionId':'" + subscriptionId
+                    + "','subscriptionKey':'" + subscriptionKey + "'}";
+
+            
this.fromApiJsonDeserializer.validateForUsingTokenConfig(configJson);
+        }
+
+        CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+        LOG.info("creditbureautoken : {} ", creditbureautoken);
+
+        // check the expiry date of the previous token.
+        if (creditbureautoken != null) {
+            Date current = new Date();
+            Date getExpiryDate = creditbureautoken.getTokenExpiryDate();
+
+            LOG.info("current date : {} ", current);
+            LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+            if (getExpiryDate.before(current)) {
+                LOG.info("The token is expired");
+                this.tokenRepository.delete(creditbureautoken);
+                creditbureautoken = null;
+            }
+        }
+        // storing token if it is valid token(not expired)
+        if (creditbureautoken != null) {
+            token = creditbureautoken.getCurrentToken();
+        }
+
+        // if token is not available or previous token is expired then create 
a new token
+        if (creditbureautoken == null) {
+
+            // using common http connection method for creating token
+            process = "token";
+            this.httpConnectionMethod();
+
+            JsonObject tokenObject = 
JsonParser.parseString(result).getAsJsonObject();
+            String expiresextra = tokenObject.get(".expires").toString();
+            String expires = expiresextra.substring(1, expiresextra.length() - 
1);
+            DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy 
kk:mm:ss zzz", Locale.ENGLISH);
+            try {
+                Date getExpiryDate = dateformat.parse(expires);
+                LOG.info("The expirydate {}", getExpiryDate);
+            } catch (ParseException Ex) {
+                LOG.error("Error occured.", Ex);
+            }
+
+            // created token will be storing it into database
+            final CommandWrapper wrapper = new 
CommandWrapperBuilder().withJson(result).build();
+            final String json = wrapper.getJson();
+            result = null;
+            JsonCommand apicommand = null;
+            boolean isApprovedByChecker = false;
+            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);
+
+            // saved new token
+            this.tokenRepository.save(generatedtoken);
+
+            // fetched
+            creditbureautoken = this.tokenRepository.getToken();
+            token = creditbureautoken.getCurrentToken();
+
+            // at this stage token is available for all cases i.e.(deleted 
expired token and saved new token)
+        }
+
+        // will use only "NRC" part of code from common http method to get 
data based on nrc
+        process = "NRC";
+        this.httpConnectionMethod();
+
+        // after fetching the data from httpconnection it will be come back 
here for fetching UniqueID from data
+        if (process.equals("NRC")) {
+
+            // to fetch the Unique ID from Result
+            JsonObject jsonObject = 
JsonParser.parseString(result).getAsJsonObject();

Review comment:
       Get result as return type of httpConnectionMethod() and validate if it 
is null.
   Processing it directly is a potential NPE.

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauTokenWritePlatformServiceImpl.java
##########
@@ -0,0 +1,178 @@
+/**
+ * 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.creditbureau.service;
+
+import com.google.gson.JsonElement;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import 
org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import 
org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauToken;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenCredential;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauTokenRepository;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepository;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenDataRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper;
+import 
org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class CreditBureauTokenWritePlatformServiceImpl implements 
CreditBureauTokenWritePlatformService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CreditBureauTokenWritePlatformServiceImpl.class);
+    private final PlatformSecurityContext context;
+    private final FromJsonHelper fromApiJsonHelper;
+    private final CreditBureauTokenRepository creditBureauTokenRepository;
+    private final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
+    private final CreditBureauTokenReadPlatformService 
readPlatformServiceCreditBureauToken;
+    private final PortfolioCommandSourceWritePlatformService 
commandsSourceWritePlatformService;
+    private final CreditBureauToken creditBureauToken;
+    private final TokenDataRepository tokendatRepository;
+    private final TokenRepositoryWrapper tokenRepository;
+    private final TokenDataRepositoryWrapper tokenDataRepository;
+    private static String tokenstr;
+    private final JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    public CreditBureauTokenWritePlatformServiceImpl(final 
PlatformSecurityContext context,
+            final CreditBureauTokenRepository creditBureauTokenRepository, 
final TokenRepositoryWrapper tokenRepository,
+            final TokenDataRepositoryWrapper tokenDataRepository, final 
TokenDataRepository tokendatRepository,
+            final CreditBureauTokenCommandFromApiJsonDeserializer 
fromApiJsonDeserializer, final FromJsonHelper fromApiJsonHelper,
+            final CreditBureauTokenReadPlatformService 
readPlatformServiceCreditBureauToken,
+            final PortfolioCommandSourceWritePlatformService 
commandsSourceWritePlatformService, final CreditBureauToken creditBureauToken,
+            final RoutingDataSource dataSource) {
+        this.context = context;
+        this.creditBureauTokenRepository = creditBureauTokenRepository;
+        this.tokenDataRepository = tokenDataRepository;
+        this.tokenRepository = tokenRepository;
+        this.tokendatRepository = tokendatRepository;
+        this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+        this.fromApiJsonHelper = fromApiJsonHelper;
+        this.readPlatformServiceCreditBureauToken = 
readPlatformServiceCreditBureauToken;
+        this.commandsSourceWritePlatformService = 
commandsSourceWritePlatformService;
+        this.creditBureauToken = creditBureauToken;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+    }
+
+    @SuppressWarnings({ "CatchAndPrintStackTrace", "DefaultCharset" })
+    @Override
+    @Transactional
+    @CacheEvict(value = "credittoken", key = 
"T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')")
+    public CommandProcessingResult createCreditBureauToken(JsonCommand 
command) {
+        try {
+            this.context.authenticatedUser();
+
+            // fetch the token credentials for using it in header
+            final CreditBureauTokenCredential credittokendata = 
this.tokenDataRepository.getTokenCredential();
+
+            String userName = credittokendata.getUserName();
+            String password = credittokendata.getPassword();
+            String subscriptionId = credittokendata.getSubscriptionId();
+            String subscriptionKey = credittokendata.getSubscriptionKey();
+
+            final String POST_PARAMS = "\n" + 
"BODY=x-www-form-urlencoded&\r\n" + "grant_type=password&\r\n" + "userName=" + 
userName
+                    + "&\r\n" + "password=" + password + "&\r\n";
+
+            URL obj = new URL("https://mmcix.azure-api.net/qa/20200324/Token";);
+            String readLine = null;
+
+            HttpURLConnection postConnection = (HttpURLConnection) 
obj.openConnection();
+            postConnection.setRequestMethod("POST");

Review comment:
       i don't see a method.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to