feat: Allow not changed password
This commit is contained in:
@@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
@RequiredArgsConstructor
|
||||
public class BootService {
|
||||
private final static int PASSWD = 1;
|
||||
private final static int INTERVAL_SEC = 10;
|
||||
public final static int INTERVAL_SEC = 10;
|
||||
|
||||
private final SessionService sessionService;
|
||||
private final TriggerService triggerService;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yablochkov.ocppstub;
|
||||
|
||||
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
|
||||
import eu.chargetime.ocpp.model.core.*;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@@ -18,32 +19,36 @@ public class ConfigService {
|
||||
@Lazy
|
||||
@Autowired private ServerCoreProfile coreProfile;
|
||||
|
||||
public void sengConfig(UUID sessionIndex) {
|
||||
public boolean sengConfig(UUID sessionIndex) {
|
||||
log.info("Sending configuration");
|
||||
ChangeConfigurationRequest configurationRequest = coreProfile
|
||||
.createChangeConfigurationRequest("AuthorizationKey", DEFAULT_KEY);
|
||||
|
||||
try {
|
||||
server.send(sessionIndex, configurationRequest)
|
||||
.thenApply(confirmation -> {
|
||||
log.debug("Get confirmation");
|
||||
if (confirmation instanceof ChangeConfigurationConfirmation) {
|
||||
log.debug("Confirmation type is ChangeConfigurationConfirmation");
|
||||
ConfigurationStatus status = ((ChangeConfigurationConfirmation) confirmation).getStatus();
|
||||
if (status == ConfigurationStatus.Accepted) {
|
||||
log.debug("Confirmation status is accepted");
|
||||
return Void.TYPE;
|
||||
}
|
||||
}
|
||||
log.error("Charge point don't confirm password change");
|
||||
throw new RuntimeException("CP don't confirm pass change");
|
||||
})
|
||||
.thenRunAsync(() -> {
|
||||
log.info("Closing session {}", sessionIndex);
|
||||
server.closeSession(sessionIndex);
|
||||
});
|
||||
var feature = server.send(sessionIndex,
|
||||
configurationRequest)
|
||||
.thenApply(confirmation -> {
|
||||
log.debug("Get confirmation");
|
||||
if (confirmation instanceof ChangeConfigurationConfirmation) {
|
||||
log.debug("Confirmation type is ChangeConfigurationConfirmation");
|
||||
ConfigurationStatus status = ((ChangeConfigurationConfirmation) confirmation).getStatus();
|
||||
if (status == ConfigurationStatus.Accepted) {
|
||||
log.debug("Confirmation status is accepted");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
log.error("Charge point don't confirm password change");
|
||||
throw new RuntimeException("CP don't confirm pass change");
|
||||
})
|
||||
.thenApply((state) -> {
|
||||
log.info("Closing session {}", sessionIndex);
|
||||
server.closeSession(sessionIndex);
|
||||
return state;
|
||||
});
|
||||
return feature.toCompletableFuture().get();
|
||||
} catch (Exception e) {
|
||||
log.error("Exception on ChangeConfiguration", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.yablochkov.ocppstub;
|
||||
|
||||
import static com.yablochkov.ocppstub.BootService.INTERVAL_SEC;
|
||||
|
||||
import eu.chargetime.ocpp.ServerEvents;
|
||||
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
|
||||
import eu.chargetime.ocpp.model.SessionInformation;
|
||||
import eu.chargetime.ocpp.model.core.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -32,7 +35,11 @@ public class EventHandler implements ServerCoreEventHandler, ServerEvents {
|
||||
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
|
||||
BootNotificationConfirmation response = bootService.handle(sessionIndex, request);
|
||||
if (response.getStatus() == RegistrationStatus.Pending) {
|
||||
configService.sengConfig(sessionIndex);
|
||||
boolean isConfigSet = configService.sengConfig(sessionIndex);
|
||||
if (!isConfigSet) {
|
||||
log.error("Config not set, skip this step");
|
||||
return new BootNotificationConfirmation(ZonedDateTime.now(), INTERVAL_SEC, RegistrationStatus.Accepted);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user