1
1
package tools .sctrade .companion .domain .gamelog .lineprocessors ;
2
2
3
+ import java .util .Locale ;
3
4
import java .util .regex .Pattern ;
4
5
import org .slf4j .Logger ;
5
6
import org .slf4j .LoggerFactory ;
7
+ import tools .sctrade .companion .domain .commodity .CommodityListingFactory ;
8
+ import tools .sctrade .companion .domain .commodity .CommodityService ;
6
9
import tools .sctrade .companion .domain .gamelog .GameLogLineProcessor ;
10
+ import tools .sctrade .companion .domain .notification .NotificationService ;
11
+ import tools .sctrade .companion .utils .LocalizationUtil ;
7
12
8
13
public class LoadShopInventoryDataLogLineProcessor extends GameLogLineProcessor {
9
14
private final Logger logger =
10
15
LoggerFactory .getLogger (LoadShopInventoryDataLogLineProcessor .class );
11
16
12
- public LoadShopInventoryDataLogLineProcessor () {
17
+ private NotificationService notificationService ;
18
+ private CommodityListingFactory commodityListingFactory ;
19
+ private CommodityService commodityService ;
20
+
21
+ public LoadShopInventoryDataLogLineProcessor (CommodityListingFactory commodityListingFactory ,
22
+ CommodityService commodityService , NotificationService notificationService ) {
13
23
this .regex =
14
- ".+LoadShopInventoryData.+shopName\\ [(?<shopName>\\ w+)\\ ] commodityName\\ [ResourceType\\ .(?<commodityName>\\ w+)\\ ].+boxSize\\ [(?<maxBoxSize>\\ d+)\\ ] \\ [Team_NAPU\\ ]\\ [Shops\\ ]\\ [UI\\ ]" ;
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 ;
15
28
}
16
29
17
30
@ Override
@@ -20,11 +33,24 @@ protected void handle(String value) {
20
33
var matcher = pattern .matcher (value );
21
34
matcher .matches ();
22
35
36
+ var shopId = matcher .group ("shopId" );
23
37
var shopName = matcher .group ("shopName" );
24
38
var commodityName = matcher .group ("commodityName" );
25
39
var maxBoxSize = Integer .valueOf (matcher .group ("maxBoxSize" ));
26
40
27
- logger .info ("Shop {} sells {} in boxes of up to {} SCU" , shopName , commodityName , maxBoxSize );
28
- }
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 )));
29
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
+ }
30
56
}
0 commit comments