|
| 1 | +package tools.sctrade.companion.domain.gamelog.lineprocessors; |
| 2 | + |
| 3 | +import java.util.Locale; |
| 4 | +import java.util.regex.Pattern; |
| 5 | +import org.slf4j.Logger; |
| 6 | +import org.slf4j.LoggerFactory; |
| 7 | +import tools.sctrade.companion.domain.commodity.CommodityListingFactory; |
| 8 | +import tools.sctrade.companion.domain.commodity.CommodityService; |
| 9 | +import tools.sctrade.companion.domain.gamelog.GameLogLineProcessor; |
| 10 | +import tools.sctrade.companion.domain.notification.NotificationService; |
| 11 | +import tools.sctrade.companion.utils.LocalizationUtil; |
| 12 | + |
| 13 | +public class LoadShopInventoryDataLogLineProcessor extends GameLogLineProcessor { |
| 14 | + private final Logger logger = |
| 15 | + LoggerFactory.getLogger(LoadShopInventoryDataLogLineProcessor.class); |
| 16 | + |
| 17 | + private NotificationService notificationService; |
| 18 | + private CommodityListingFactory commodityListingFactory; |
| 19 | + private CommodityService commodityService; |
| 20 | + |
| 21 | + public LoadShopInventoryDataLogLineProcessor(CommodityListingFactory commodityListingFactory, |
| 22 | + CommodityService commodityService, NotificationService notificationService) { |
| 23 | + this.regex = |
| 24 | + ".+LoadShopInventoryData.+shopId\\[(?<shopId>\\d+)\\] shopName\\[(?<shopName>[\\w-]+)\\] commodityName\\[ResourceType\\.(?<commodityName>[\\w-]+)\\].+boxSize\\[(?<maxBoxSize>\\d+)\\] \\[Team_NAPU\\]\\[Shops\\]\\[UI\\]"; |
| 25 | + this.commodityListingFactory = commodityListingFactory; |
| 26 | + this.commodityService = commodityService; |
| 27 | + this.notificationService = notificationService; |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + protected void handle(String value) { |
| 32 | + var pattern = Pattern.compile(regex); |
| 33 | + var matcher = pattern.matcher(value); |
| 34 | + matcher.matches(); |
| 35 | + |
| 36 | + var shopId = matcher.group("shopId"); |
| 37 | + var shopName = matcher.group("shopName"); |
| 38 | + var commodityName = matcher.group("commodityName"); |
| 39 | + var maxBoxSize = Integer.valueOf(matcher.group("maxBoxSize")); |
| 40 | + |
| 41 | + logger.info("Shop {}#{} sells {} in boxes of up to {} SCU", shopName, shopId, commodityName, |
| 42 | + maxBoxSize); |
| 43 | + notificationService |
| 44 | + .info(String.format(Locale.ROOT, LocalizationUtil.get("infoLocationDetectedFromLogs"), |
| 45 | + String.format(Locale.ROOT, "%s#%s", shopName, shopId))); |
| 46 | + |
| 47 | + var commodityListing = |
| 48 | + commodityListingFactory.build(shopId, shopName, commodityName, maxBoxSize); |
| 49 | + |
| 50 | + try { |
| 51 | + commodityService.process(commodityListing); |
| 52 | + } catch (InterruptedException e) { |
| 53 | + logger.error("Could not send {} for processing", commodityListing, e); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments