Skip to content

Commit 8ad33a9

Browse files
committed
loosen id tag expiration constraints (Closes steve-community#48)
reason: until now, we always used current time + some hours (set in UI) for id tag expiration, regardless of an expiry date the database had for this id tag. the idea behind was to better control two possible situations: - no expiry date: set an explicit one to prevent the station caching it, such that after some time, it _has_ to ask Steve. - expiry date too far in the future: since business rules, contracts, conditions and therefore expiration of id tags might change, we wanted to prevent the stations from storing id tags for too long in the white list. both of these ideas resulted from the thinking that Steve is the single point of truth and that we did not trust charging station implementations. therefore, we always preferred a charging station asking us frequently about the id tag status. with this commit, this constraint is loosened.
1 parent 3b8b05e commit 8ad33a9

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/main/java/de/rwth/idsg/steve/service/OcppTagServiceImpl.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import de.rwth.idsg.steve.repository.SettingsRepository;
55
import de.rwth.idsg.steve.service.dto.UnidentifiedIncomingObject;
66
import jooq.steve.db.tables.records.OcppTagRecord;
7+
import lombok.AccessLevel;
8+
import lombok.RequiredArgsConstructor;
79
import lombok.extern.slf4j.Slf4j;
810
import ocpp.cp._2015._10.AuthorizationData;
911
import ocpp.cs._2015._10.AuthorizationStatus;
@@ -30,18 +32,14 @@ public class OcppTagServiceImpl implements OcppTagService {
3032

3133
@Override
3234
public List<AuthorizationData> getAuthDataOfAllTags() {
33-
int hoursToExpire = settingsRepository.getHoursToExpire();
34-
3535
return ocppTagRepository.getRecords()
36-
.map(new AuthorisationDataMapper(hoursToExpire));
36+
.map(new AuthorisationDataMapper());
3737
}
3838

3939
@Override
4040
public List<AuthorizationData> getAuthData(List<String> idTagList) {
41-
int hoursToExpire = settingsRepository.getHoursToExpire();
42-
4341
return ocppTagRepository.getRecords(idTagList)
44-
.map(new AuthorisationDataMapper(hoursToExpire));
42+
.map(new AuthorisationDataMapper());
4543
}
4644

4745
@Override
@@ -59,6 +57,10 @@ public IdTagInfo getIdTagInfo(String idTag) {
5957
idTagInfo.setStatus(AuthorizationStatus.INVALID);
6058
invalidOcppTagService.processNewUnidentified(idTag);
6159
} else {
60+
61+
DateTime expiryDate = record.getExpiryDate();
62+
boolean isExpiryDateSet = expiryDate != null;
63+
6264
if (record.getBlocked()) {
6365
log.error("The user with idTag '{}' is BLOCKED.", idTag);
6466
idTagInfo.setStatus(AuthorizationStatus.BLOCKED);
@@ -67,16 +69,18 @@ public IdTagInfo getIdTagInfo(String idTag) {
6769
// log.warn("The user with idTag '{}' is ALREADY in another transaction.", idTag);
6870
// idTagInfo.setStatus(ocpp.cs._2012._06.AuthorizationStatus.CONCURRENT_TX);
6971

70-
} else if (record.getExpiryDate() != null && DateTime.now().isAfter(record.getExpiryDate())) {
72+
} else if (isExpiryDateSet && DateTime.now().isAfter(record.getExpiryDate())) {
7173
log.error("The user with idTag '{}' is EXPIRED.", idTag);
7274
idTagInfo.setStatus(AuthorizationStatus.EXPIRED);
7375

7476
} else {
7577
log.debug("The user with idTag '{}' is ACCEPTED.", idTag);
7678
idTagInfo.setStatus(AuthorizationStatus.ACCEPTED);
7779

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);
8084
idTagInfo.setParentIdTag(record.getParentIdTag());
8185
}
8286
}
@@ -87,18 +91,13 @@ public IdTagInfo getIdTagInfo(String idTag) {
8791
// Private helpers
8892
// -------------------------------------------------------------------------
8993

94+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
9095
private static class AuthorisationDataMapper implements RecordMapper<OcppTagRecord, AuthorizationData> {
91-
private final DateTime nowDt;
92-
private final DateTime cacheExpiry;
9396

94-
AuthorisationDataMapper(int hoursToExpire) {
95-
this.nowDt = DateTime.now();
96-
this.cacheExpiry = nowDt.plus(hoursToExpire);
97-
}
97+
private final DateTime nowDt = DateTime.now();
9898

9999
@Override
100100
public AuthorizationData map(OcppTagRecord record) {
101-
102101
String idTag = record.getIdTag();
103102
String parentIdTag = record.getParentIdTag();
104103
DateTime expiryDate = record.getExpiryDate();
@@ -119,7 +118,7 @@ public AuthorizationData map(OcppTagRecord record) {
119118
} else {
120119
authStatus = ocpp.cp._2015._10.AuthorizationStatus.ACCEPTED;
121120
// When accepted, set the additional fields
122-
idTagInfo.setExpiryDate(cacheExpiry);
121+
idTagInfo.setExpiryDate(expiryDate);
123122
idTagInfo.setParentIdTag(parentIdTag);
124123
}
125124
idTagInfo.setStatus(authStatus);

0 commit comments

Comments
 (0)