Subversion Repositories SmartDukaan

Rev

Rev 37395 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23724 amit.gupta 1
package com.smartdukaan.cron.monitored;
23723 amit.gupta 2
 
23794 govind 3
import java.io.IOException;
23723 amit.gupta 4
import java.util.HashMap;
5
import java.util.Map;
6
 
23755 amit.gupta 7
import org.apache.logging.log4j.LogManager;
8
import org.apache.logging.log4j.Logger;
23723 amit.gupta 9
import org.springframework.beans.factory.annotation.Autowired;
23794 govind 10
import org.springframework.beans.factory.annotation.Value;
23723 amit.gupta 11
import org.springframework.stereotype.Component;
12
 
13
import com.spice.profitmandi.common.enumuration.SchemeType;
23794 govind 14
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
15
import com.spice.profitmandi.common.model.RechargeCredential;
23723 amit.gupta 16
import com.spice.profitmandi.common.web.client.RestClient;
23731 amit.gupta 17
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23794 govind 18
import com.spice.profitmandi.service.recharge.RechargeService;
19
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
23723 amit.gupta 20
 
21
@Component
37472 amit 22
/**
23
 * Reads the two prepaid balances -- SMS credits and the ThinkWalnut recharge wallet --
24
 * and pushes them into {@link BalanceGauges}.
25
 *
26
 * ⚠ NOTHING CALLS THIS. There is no @Scheduled method and no other caller anywhere in
27
 * the codebase, which is why both gauges read -1 ("not read yet") on every scrape. The
28
 * micrometer bridge works; the trigger was never written. Either give it a @Scheduled
29
 * entry in ScheduledSkeleton or delete this and its gauges -- do not leave it half-wired.
30
 *
31
 * Formerly NagiosMonitorTasks: the Nagios server and every NRPE daemon are gone, so the
32
 * name described a transport that no longer exists.
33
 */
34
public class BalanceMonitorTasks {
23723 amit.gupta 35
 
37472 amit 36
	private static final Logger log = LogManager.getLogger(BalanceMonitorTasks.class);
23723 amit.gupta 37
 
23794 govind 38
	@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
39
	private String thinkWalnutDigitalRechargeTransactionMobileUrl;
40
 
41
	@Value("${think.walnut.digital.recharge.transaction.dth.url}")
42
	private String thinkWalnutDigitalRechargeTransactionDthUrl;
43
 
44
	@Value("${think.walnut.digital.recharge.enquiry.url}")
45
	private String thinkWalnutDigitalRechargeEnquiryUrl;
46
 
47
	@Value("${think.walnut.digital.recharge.balance.url}")
48
	private String thinkWalnutDigitalRechargeBalanceUrl;
49
 
50
	@Value("${think.walnut.digital.recharge.username}")
51
	private String thinkWalnutDigitalRechargeUserName;
52
 
53
	@Value("${think.walnut.digital.recharge.password}")
54
	private String thinkWalnutDigitalRechargePassword;
55
 
56
	@Value("${think.walnut.digital.recharge.auth.key}")
57
	private String thinkWalnutDigitalRechargeAuthKey;
58
 
23723 amit.gupta 59
	@Autowired
23794 govind 60
	private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
24121 govind 61
 
23794 govind 62
	@Autowired
23723 amit.gupta 63
	private RestClient restClient;
23794 govind 64
 
65
	@Autowired
66
	ItemRepository itemRepository;
24121 govind 67
 
23731 amit.gupta 68
	@Autowired
23794 govind 69
	private RechargeService rechargeService;
23723 amit.gupta 70
 
23794 govind 71
	@Autowired
37395 amit 72
	private BalanceGauges balanceGauges;
23794 govind 73
 
24121 govind 74
 
23723 amit.gupta 75
	public void reportSmsCount() throws Throwable {
76
		String htmlpage;
23794 govind 77
		int currentSmsCount = 0;
24879 govind 78
		String uri = "/MessagingGateway/GetSMSBalance";
23723 amit.gupta 79
		Map<String, String> params = new HashMap<>();
24879 govind 80
		params.put("Username", "srlsaholic");
81
		params.put("Password", "sr18mar");
23723 amit.gupta 82
		String response = restClient.post(SchemeType.HTTP, "103.15.179.45", 8085, uri, params, new HashMap<>());
83
		// System.out.println("response Html"+response);
84
		if (response.length() > 0) {
24879 govind 85
			htmlpage = response.substring(response.indexOf("=")+1);
86
			 System.out.println(htmlpage);
24891 amit.gupta 87
			currentSmsCount = Integer.parseInt(htmlpage.trim());
23794 govind 88
			log.info("Got successfully parsed {}", currentSmsCount);
37395 amit 89
			balanceGauges.setSmsBalance(currentSmsCount);
24121 govind 90
 
23723 amit.gupta 91
		}
24121 govind 92
 
23723 amit.gupta 93
	}
24121 govind 94
 
95
	public void currentThinkWalnutBalace() throws ProfitMandiBusinessException, IOException {
23794 govind 96
		RechargeCredential thinkWalnutDigitalRechargeCredential = new RechargeCredential();
97
		thinkWalnutDigitalRechargeCredential.setRechargeUrl(thinkWalnutDigitalRechargeBalanceUrl);
98
		thinkWalnutDigitalRechargeCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
99
		thinkWalnutDigitalRechargeCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
100
		thinkWalnutDigitalRechargeCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
24121 govind 101
		float thinkWalnutBalance = thinkWalnutDigitalRechargeProviderService
102
				.doCheckBalanceRequest(thinkWalnutDigitalRechargeCredential);
103
		log.info("ThinkWalnut Balance {}", thinkWalnutBalance);
37395 amit 104
		balanceGauges.setRechargeWalletBalance(thinkWalnutBalance);
24121 govind 105
 
23794 govind 106
	}
23723 amit.gupta 107
}