fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [fineract] rrpawar96 commented on a change in pull request #1235: FINERACT-734 Creditbureau-Integration-phase3
Date Fri, 21 Aug 2020 18:47:12 GMT

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



##########
File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,303 @@
+/**
+ * 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.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.time.LocalDate;
+import java.time.ZoneId;
+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;
+    }
+
+    @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 result = null;
+        Long uniqueID = 0L;
+        try {
+            this.context.authenticatedUser();
+
+            final CreditBureauTokenCredential credittokendata = this.tokenDataRepository.getTokenCredential();
+            String userName = credittokendata.getUserName();
+            String password = credittokendata.getPassword();
+            String subscriptionId = credittokendata.getSubscriptionId();
+            String subscriptionKey = credittokendata.getSubscriptionKey();
+            String tokenDate;
+
+            CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+            LOG.info("credit bureau token : {} ", creditbureautoken);
+
+            // check the expiry date of the previous token.
+            if (creditbureautoken != null) {
+                try {
+                    Date current = new Date();
+
+                    String getDate = creditbureautoken.getTokenExpiryDate();
+                    DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss
zzz", Locale.ENGLISH);
+                    Date getExpiryDate = dateformat.parse(getDate);
+                    LOG.info("current date : {} ", current);
+                    LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+                    ZoneId zid = ZoneId.of("Asia/Rangoon");

Review comment:
       comment has been addressed

##########
File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,303 @@
+/**
+ * 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.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.time.LocalDate;
+import java.time.ZoneId;
+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;
+    }
+
+    @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 result = null;
+        Long uniqueID = 0L;
+        try {
+            this.context.authenticatedUser();
+
+            final CreditBureauTokenCredential credittokendata = this.tokenDataRepository.getTokenCredential();
+            String userName = credittokendata.getUserName();
+            String password = credittokendata.getPassword();
+            String subscriptionId = credittokendata.getSubscriptionId();
+            String subscriptionKey = credittokendata.getSubscriptionKey();
+            String tokenDate;
+
+            CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+            LOG.info("credit bureau token : {} ", creditbureautoken);
+
+            // check the expiry date of the previous token.
+            if (creditbureautoken != null) {
+                try {
+                    Date current = new Date();
+
+                    String getDate = creditbureautoken.getTokenExpiryDate();

Review comment:
       comment has been addressed

##########
File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,303 @@
+/**
+ * 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.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.time.LocalDate;
+import java.time.ZoneId;
+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;
+    }
+
+    @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 result = null;
+        Long uniqueID = 0L;
+        try {
+            this.context.authenticatedUser();
+
+            final CreditBureauTokenCredential credittokendata = this.tokenDataRepository.getTokenCredential();
+            String userName = credittokendata.getUserName();
+            String password = credittokendata.getPassword();
+            String subscriptionId = credittokendata.getSubscriptionId();
+            String subscriptionKey = credittokendata.getSubscriptionKey();
+            String tokenDate;
+
+            CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+            LOG.info("credit bureau token : {} ", creditbureautoken);
+
+            // check the expiry date of the previous token.
+            if (creditbureautoken != null) {
+                try {
+                    Date current = new Date();
+
+                    String getDate = creditbureautoken.getTokenExpiryDate();
+                    DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss
zzz", Locale.ENGLISH);
+                    Date getExpiryDate = dateformat.parse(getDate);
+                    LOG.info("current date : {} ", current);
+                    LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+                    ZoneId zid = ZoneId.of("Asia/Rangoon");
+                    final LocalDate date = LocalDate.now(zid);

Review comment:
       comment has been addressed

##########
File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,303 @@
+/**
+ * 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.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.time.LocalDate;
+import java.time.ZoneId;
+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;
+    }
+
+    @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 result = null;
+        Long uniqueID = 0L;
+        try {
+            this.context.authenticatedUser();
+
+            final CreditBureauTokenCredential credittokendata = this.tokenDataRepository.getTokenCredential();
+            String userName = credittokendata.getUserName();
+            String password = credittokendata.getPassword();
+            String subscriptionId = credittokendata.getSubscriptionId();
+            String subscriptionKey = credittokendata.getSubscriptionKey();
+            String tokenDate;
+
+            CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+            LOG.info("credit bureau token : {} ", creditbureautoken);
+
+            // check the expiry date of the previous token.
+            if (creditbureautoken != null) {
+                try {
+                    Date current = new Date();
+
+                    String getDate = creditbureautoken.getTokenExpiryDate();
+                    DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss
zzz", Locale.ENGLISH);
+                    Date getExpiryDate = dateformat.parse(getDate);
+                    LOG.info("current date : {} ", current);
+                    LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+                    ZoneId zid = ZoneId.of("Asia/Rangoon");
+                    final LocalDate date = LocalDate.now(zid);
+                    LOG.info("local date : {} ", date);
+
+                    if (getExpiryDate.before(current)) {
+                        LOG.info("The token is expired");
+                        final CreditBureauToken credittoken = this.tokenRepository.getToken();
+                        if (credittoken != null) {
+
+                            this.tokenRepository.delete(credittoken);
+                            creditbureautoken = null;
+                        }
+
+                    }
+
+                } catch (ParseException Ex) {
+                    LOG.error("Error occured.", Ex);
+                }
+            }
+
+            // if token is not available or previous token is expired then create a new token
+            if (creditbureautoken == null) {
+
+                LOG.info("-----creating new token-----");
+                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();

Review comment:
       comment has been addressed

##########
File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReportsReadPlatformServiceImpl.java
##########
@@ -0,0 +1,303 @@
+/**
+ * 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.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.time.LocalDate;
+import java.time.ZoneId;
+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;
+    }
+
+    @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 result = null;
+        Long uniqueID = 0L;
+        try {
+            this.context.authenticatedUser();
+
+            final CreditBureauTokenCredential credittokendata = this.tokenDataRepository.getTokenCredential();
+            String userName = credittokendata.getUserName();
+            String password = credittokendata.getPassword();
+            String subscriptionId = credittokendata.getSubscriptionId();
+            String subscriptionKey = credittokendata.getSubscriptionKey();
+            String tokenDate;
+
+            CreditBureauToken creditbureautoken = this.tokenRepository.getToken();
+            LOG.info("credit bureau token : {} ", creditbureautoken);
+
+            // check the expiry date of the previous token.
+            if (creditbureautoken != null) {
+                try {
+                    Date current = new Date();
+
+                    String getDate = creditbureautoken.getTokenExpiryDate();
+                    DateFormat dateformat = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss
zzz", Locale.ENGLISH);
+                    Date getExpiryDate = dateformat.parse(getDate);
+                    LOG.info("current date : {} ", current);
+                    LOG.info("getExpiryDate : {} ", getExpiryDate);
+
+                    ZoneId zid = ZoneId.of("Asia/Rangoon");
+                    final LocalDate date = LocalDate.now(zid);
+                    LOG.info("local date : {} ", date);
+
+                    if (getExpiryDate.before(current)) {
+                        LOG.info("The token is expired");
+                        final CreditBureauToken credittoken = this.tokenRepository.getToken();
+                        if (credittoken != null) {
+
+                            this.tokenRepository.delete(credittoken);
+                            creditbureautoken = null;
+                        }
+
+                    }
+
+                } catch (ParseException Ex) {
+                    LOG.error("Error occured.", Ex);
+                }
+            }
+
+            // if token is not available or previous token is expired then create a new token
+            if (creditbureautoken == null) {
+
+                LOG.info("-----creating new token-----");
+                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");
+                postConnection.setRequestProperty("mcix-subscription-key", subscriptionKey);
+                postConnection.setRequestProperty("mcix-subscription-id", subscriptionId);
+                postConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+
+                postConnection.setDoOutput(true);
+
+                OutputStream os = postConnection.getOutputStream();
+                os.write(POST_PARAMS.getBytes(StandardCharsets.UTF_8));
+                os.flush();
+                os.close();
+
+                int responseCode = postConnection.getResponseCode();
+
+                String ResponseMessage = postConnection.getResponseMessage();
+
+                if (responseCode == HttpURLConnection.HTTP_OK) {
+                    BufferedReader in = new BufferedReader(new InputStreamReader(postConnection.getInputStream(),
StandardCharsets.UTF_8));
+                    StringBuilder response = new StringBuilder();
+                    while ((readLine = in.readLine()) != null) {
+                        response.append(readLine);
+                    }
+                    in.close();
+
+                    result = response.toString();
+
+                    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);
+
+                    this.tokenRepository.save(generatedtoken);
+
+                } else {
+                    LOG.info("Request is Invalid");
+
+                }
+            }
+
+            // Search Methods
+            LOG.info("-----Search by NRC-----");
+            StringBuilder response = new StringBuilder();
+            creditbureautoken = this.tokenRepository.getToken();
+            String token = creditbureautoken.getCurrentToken();
+
+            final String POST_PARAMS = "BODY=x-www-form-urlencoded&nrc=" + searchId +
"&";
+
+            URL obj = new URL("https://mmcix.azure-api.net/qa/20200324/api/Search/SimpleSearch?nrc="
+ searchId);
+            String readLine = null;
+            LOG.info("POST_PARAMS : {} ", POST_PARAMS);
+            LOG.info("obj : {} ", obj);
+            LOG.info("subscriptionId : {} ", subscriptionId);
+            LOG.info("subscriptionKey : {} ", subscriptionKey);
+            LOG.info("token : {} ", token);
+
+            HttpURLConnection postConnection = (HttpURLConnection) obj.openConnection();

Review comment:
       comment has been addressed

##########
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:
       comment has been addressed

##########
File path: fineract-provider/src/main/resources/sql/migrations/core_db/V273__oauth_changes.sql
##########
@@ -59,3 +59,42 @@ CREATE TABLE `oauth_refresh_token` (
 )
 COLLATE='utf8mb4_general_ci'
 ENGINE=InnoDB;
+
+CREATE TABLE `m_creditbureau_tokendata` (
+  `id` INT(128) NOT NULL AUTO_INCREMENT,
+  `userNames` varchar(128) DEFAULT NULL,
+  `password` varchar(128) DEFAULT NULL,
+  `subscription_id` varchar(128) DEFAULT NULL,
+  `subscription_key` varchar(128) DEFAULT NULL,
+
+  PRIMARY KEY (`id`)
+)
+COLLATE='utf8mb4_general_ci'
+ENGINE=InnoDB;
+
+INSERT INTO `m_creditbureau_tokendata` (`id`, `userNames`, `password`, `subscription_id`,
`subscription_key`) VALUES

Review comment:
       comment has been addressed




----------------------------------------------------------------
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:
users@infra.apache.org



Mime
View raw message