4
4
import de .rwth .idsg .steve .repository .SettingsRepository ;
5
5
import de .rwth .idsg .steve .service .dto .UnidentifiedIncomingObject ;
6
6
import jooq .steve .db .tables .records .OcppTagRecord ;
7
+ import lombok .AccessLevel ;
8
+ import lombok .RequiredArgsConstructor ;
7
9
import lombok .extern .slf4j .Slf4j ;
8
10
import ocpp .cp ._2015 ._10 .AuthorizationData ;
9
11
import ocpp .cs ._2015 ._10 .AuthorizationStatus ;
@@ -30,18 +32,14 @@ public class OcppTagServiceImpl implements OcppTagService {
30
32
31
33
@ Override
32
34
public List <AuthorizationData > getAuthDataOfAllTags () {
33
- int hoursToExpire = settingsRepository .getHoursToExpire ();
34
-
35
35
return ocppTagRepository .getRecords ()
36
- .map (new AuthorisationDataMapper (hoursToExpire ));
36
+ .map (new AuthorisationDataMapper ());
37
37
}
38
38
39
39
@ Override
40
40
public List <AuthorizationData > getAuthData (List <String > idTagList ) {
41
- int hoursToExpire = settingsRepository .getHoursToExpire ();
42
-
43
41
return ocppTagRepository .getRecords (idTagList )
44
- .map (new AuthorisationDataMapper (hoursToExpire ));
42
+ .map (new AuthorisationDataMapper ());
45
43
}
46
44
47
45
@ Override
@@ -59,6 +57,10 @@ public IdTagInfo getIdTagInfo(String idTag) {
59
57
idTagInfo .setStatus (AuthorizationStatus .INVALID );
60
58
invalidOcppTagService .processNewUnidentified (idTag );
61
59
} else {
60
+
61
+ DateTime expiryDate = record .getExpiryDate ();
62
+ boolean isExpiryDateSet = expiryDate != null ;
63
+
62
64
if (record .getBlocked ()) {
63
65
log .error ("The user with idTag '{}' is BLOCKED." , idTag );
64
66
idTagInfo .setStatus (AuthorizationStatus .BLOCKED );
@@ -67,16 +69,18 @@ public IdTagInfo getIdTagInfo(String idTag) {
67
69
// log.warn("The user with idTag '{}' is ALREADY in another transaction.", idTag);
68
70
// idTagInfo.setStatus(ocpp.cs._2012._06.AuthorizationStatus.CONCURRENT_TX);
69
71
70
- } else if (record . getExpiryDate () != null && DateTime .now ().isAfter (record .getExpiryDate ())) {
72
+ } else if (isExpiryDateSet && DateTime .now ().isAfter (record .getExpiryDate ())) {
71
73
log .error ("The user with idTag '{}' is EXPIRED." , idTag );
72
74
idTagInfo .setStatus (AuthorizationStatus .EXPIRED );
73
75
74
76
} else {
75
77
log .debug ("The user with idTag '{}' is ACCEPTED." , idTag );
76
78
idTagInfo .setStatus (AuthorizationStatus .ACCEPTED );
77
79
78
- int hours = settingsRepository .getHoursToExpire ();
79
- idTagInfo .setExpiryDate (DateTime .now ().plusHours (hours ));
80
+ // If the database contains an actual expiry, use it. Otherwise, calculate an expiry for cached info
81
+ DateTime expiry = isExpiryDateSet ? expiryDate : DateTime .now ().plusHours (settingsRepository .getHoursToExpire ());
82
+
83
+ idTagInfo .setExpiryDate (expiry );
80
84
idTagInfo .setParentIdTag (record .getParentIdTag ());
81
85
}
82
86
}
@@ -87,18 +91,13 @@ public IdTagInfo getIdTagInfo(String idTag) {
87
91
// Private helpers
88
92
// -------------------------------------------------------------------------
89
93
94
+ @ RequiredArgsConstructor (access = AccessLevel .PRIVATE )
90
95
private static class AuthorisationDataMapper implements RecordMapper <OcppTagRecord , AuthorizationData > {
91
- private final DateTime nowDt ;
92
- private final DateTime cacheExpiry ;
93
96
94
- AuthorisationDataMapper (int hoursToExpire ) {
95
- this .nowDt = DateTime .now ();
96
- this .cacheExpiry = nowDt .plus (hoursToExpire );
97
- }
97
+ private final DateTime nowDt = DateTime .now ();
98
98
99
99
@ Override
100
100
public AuthorizationData map (OcppTagRecord record ) {
101
-
102
101
String idTag = record .getIdTag ();
103
102
String parentIdTag = record .getParentIdTag ();
104
103
DateTime expiryDate = record .getExpiryDate ();
@@ -119,7 +118,7 @@ public AuthorizationData map(OcppTagRecord record) {
119
118
} else {
120
119
authStatus = ocpp .cp ._2015 ._10 .AuthorizationStatus .ACCEPTED ;
121
120
// When accepted, set the additional fields
122
- idTagInfo .setExpiryDate (cacheExpiry );
121
+ idTagInfo .setExpiryDate (expiryDate );
123
122
idTagInfo .setParentIdTag (parentIdTag );
124
123
}
125
124
idTagInfo .setStatus (authStatus );
0 commit comments