Last active
June 22, 2017 15:01
-
-
Save ensonic/bca9f695b18194ef28068b9ab401e17f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 49afe68a05ac4894c5fefa8e313375ef87d8bde9 Mon Sep 17 00:00:00 2001 | |
From: Stefan Sauer <[email protected]> | |
Date: Thu, 22 Jun 2017 16:57:08 +0200 | |
Subject: [PATCH] Compare with FirmwareName instead of robot name. | |
RobotName is initialized from 'brickname' and can be changed on the robot (for the ev3 at least). | |
See #528 | |
--- | |
.../robotCommunication/RobotCommunicationData.java | 3 +++ | |
.../roberta/robotCommunication/RobotCommunicator.java | 4 +--- | |
.../roberta/javaServer/restServices/all/ClientAdmin.java | 8 ++++---- | |
.../javaServer/restServices/all/ClientConfiguration.java | 8 ++++---- | |
.../roberta/javaServer/restServices/all/ClientPing.java | 2 +- | |
.../javaServer/restServices/all/ClientProgram.java | 10 +++++----- | |
.../javaServer/restServices/all/ClientToolbox.java | 4 ++-- | |
.../roberta/javaServer/restServices/all/ClientUser.java | 2 +- | |
.../iais/roberta/persistence/util/HttpSessionState.java | 16 ++++++++-------- | |
9 files changed, 29 insertions(+), 28 deletions(-) | |
diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicationData.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicationData.java | |
index d7a9114e1..1de588f2f 100644 | |
--- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicationData.java | |
+++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicationData.java | |
@@ -43,12 +43,15 @@ public class RobotCommunicationData { | |
private String programName; | |
public RobotCommunicationData( | |
+ // the per session token | |
String token, | |
+ // the robot group?, such as 'ev3' ... | |
String robot, | |
String robotIdentificator, | |
String robotName, | |
String battery, | |
String menuversion, | |
+ // the robot variant, such as 'ev3dev' | |
String firmwarename, | |
String firmwareversion) { | |
this.token = token; | |
diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicator.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicator.java | |
index 4f2699830..77eca65ac 100644 | |
--- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicator.java | |
+++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/robotCommunication/RobotCommunicator.java | |
@@ -102,9 +102,7 @@ public class RobotCommunicator { | |
if ( state == null ) { | |
LOG.info("token " + token + " is not waiting for. Typing error of the user?"); | |
return Key.TOKEN_SET_ERROR_NO_ROBOT_WAITING; | |
- } else if ( !(state.getRobot().equals(robot) | |
- || state.getRobotName().toLowerCase().equals(robot) | |
- || (state.getRobot() + state.getFirmwareName()).equals(robot)) ) { | |
+ } else if ( !(state.getRobot().equals(robot) || state.getFirmwareName().equals(robot) || (state.getRobot() + state.getFirmwareName()).equals(robot)) ) { | |
LOG.info("token " + token + " belongs to a robot of type " + state.getRobot() + ", client is set to " + robot); | |
return Key.TOKEN_SET_ERROR_WRONG_ROBOTTYPE; | |
} else { | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java | |
index dae69ab4a..746cf7586 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientAdmin.java | |
@@ -48,7 +48,7 @@ public class ClientAdmin { | |
AliveData.rememberClientCall(); | |
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber())); | |
MDC.put("userId", String.valueOf(httpSessionState.getUserId())); | |
- MDC.put("robotName", String.valueOf(httpSessionState.getRobotName())); | |
+ MDC.put("robotName", String.valueOf(httpSessionState.getRobot())); | |
new ClientLogger().log(LOG, fullRequest); | |
JSONObject response = new JSONObject(); | |
try { | |
@@ -80,7 +80,7 @@ public class ClientAdmin { | |
Util.addSuccessInfo(response, Key.INIT_SUCCESS); | |
} else if ( cmd.equals("setToken") ) { | |
String token = request.getString("token"); | |
- Key tokenAgreement = this.brickCommunicator.aTokenAgreementWasSent(token, httpSessionState.getRobotName()); | |
+ Key tokenAgreement = this.brickCommunicator.aTokenAgreementWasSent(token, httpSessionState.getRobot()); | |
switch ( tokenAgreement ) { | |
case TOKEN_SET_SUCCESS: | |
httpSessionState.setToken(token); | |
@@ -118,7 +118,7 @@ public class ClientAdmin { | |
String robot = request.getString("robot"); | |
if ( robot != null && RobertaProperties.getRobotWhitelist().contains(robot) ) { | |
Util.addSuccessInfo(response, Key.ROBOT_SET_SUCCESS); | |
- if ( httpSessionState.getRobotName() != robot ) { | |
+ if ( httpSessionState.getRobot() != robot ) { | |
// disconnect previous robot | |
// TODO consider keeping it so that we can switch between robot and simulation | |
// see: https://github.com/OpenRoberta/robertalab/issues/43 | |
@@ -129,7 +129,7 @@ public class ClientAdmin { | |
} else { | |
httpSessionState.setToken(RandomUrlPostfix.generate(12, 12, 3, 3, 3)); | |
} | |
- httpSessionState.setRobotName(robot); | |
+ httpSessionState.setRobot(robot); | |
IRobotFactory robotFactory = httpSessionState.getRobotFactory(); | |
response.put("robot", robot); | |
JSONObject program; | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientConfiguration.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientConfiguration.java | |
index f76839069..6289e205c 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientConfiguration.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientConfiguration.java | |
@@ -47,13 +47,13 @@ public class ClientConfiguration { | |
AliveData.rememberClientCall(); | |
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber())); | |
MDC.put("userId", String.valueOf(httpSessionState.getUserId())); | |
- MDC.put("robotName", String.valueOf(httpSessionState.getRobotName())); | |
+ MDC.put("robotName", String.valueOf(httpSessionState.getRobot())); | |
new ClientLogger().log(ClientConfiguration.LOG, fullRequest); | |
int userId = httpSessionState.getUserId(); | |
final String robotName = | |
- httpSessionState.getRobotFactory(httpSessionState.getRobotName()).getGroup() != "" | |
- ? httpSessionState.getRobotFactory(httpSessionState.getRobotName()).getGroup() | |
- : httpSessionState.getRobotName(); | |
+ httpSessionState.getRobotFactory(httpSessionState.getRobot()).getGroup() != "" | |
+ ? httpSessionState.getRobotFactory(httpSessionState.getRobot()).getGroup() | |
+ : httpSessionState.getRobot(); | |
UserProcessor up = new UserProcessor(dbSession, httpSessionState); | |
JSONObject response = new JSONObject(); | |
try { | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientPing.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientPing.java | |
index 840db6c56..b16bc1719 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientPing.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientPing.java | |
@@ -51,7 +51,7 @@ public class ClientPing { | |
AliveData.rememberClientCall(); | |
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber())); | |
MDC.put("userId", String.valueOf(httpSessionState.getUserId())); | |
- MDC.put("robotName", String.valueOf(httpSessionState.getRobotName())); | |
+ MDC.put("robotName", String.valueOf(httpSessionState.getRobot())); | |
int logLen = new ClientLogger().log(LOG, fullRequest); | |
int counter = pingCounterForLogging.incrementAndGet(); | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientProgram.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientProgram.java | |
index cee3f7e25..e98bf61bb 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientProgram.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientProgram.java | |
@@ -83,13 +83,13 @@ public class ClientProgram { | |
AliveData.rememberClientCall(); | |
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber())); | |
MDC.put("userId", String.valueOf(httpSessionState.getUserId())); | |
- MDC.put("robotName", String.valueOf(httpSessionState.getRobotName())); | |
+ MDC.put("robotName", String.valueOf(httpSessionState.getRobot())); | |
new ClientLogger().log(ClientProgram.LOG, fullRequest); | |
int userId = httpSessionState.getUserId(); | |
String robot = | |
- httpSessionState.getRobotFactory(httpSessionState.getRobotName()).getGroup() != "" | |
- ? httpSessionState.getRobotFactory(httpSessionState.getRobotName()).getGroup() | |
- : httpSessionState.getRobotName(); | |
+ httpSessionState.getRobotFactory(httpSessionState.getRobot()).getGroup() != "" | |
+ ? httpSessionState.getRobotFactory(httpSessionState.getRobot()).getGroup() | |
+ : httpSessionState.getRobot(); | |
JSONObject response = new JSONObject(); | |
DbSession dbSession = this.sessionFactoryWrapper.getSession(); | |
try { | |
@@ -259,7 +259,7 @@ public class ClientProgram { | |
BlocklyProgramAndConfigTransformer.transform(robotFactory, programText, configurationText); | |
messageKey = programAndConfigTransformer.getErrorMessage(); | |
// TODO: this is quick fix not to check the program for arduino | |
- if ( !(httpSessionState.getRobotName().equals("ardu") || httpSessionState.getRobotName().equals("nao")) && messageKey == null ) { | |
+ if ( !(httpSessionState.getRobot().equals("ardu") || httpSessionState.getRobot().equals("nao")) && messageKey == null ) { | |
RobotProgramCheckVisitor programChecker = robotFactory.getRobotProgramCheckVisitor(programAndConfigTransformer.getBrickConfiguration()); | |
messageKey = programConfigurationCompatibilityCheck(response, programAndConfigTransformer.getTransformedProgram(), programChecker); | |
} else { | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientToolbox.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientToolbox.java | |
index e27254fc4..ffa7e773b 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientToolbox.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientToolbox.java | |
@@ -46,7 +46,7 @@ public class ClientToolbox { | |
AliveData.rememberClientCall(); | |
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber())); | |
MDC.put("userId", String.valueOf(httpSessionState.getUserId())); | |
- MDC.put("robotName", String.valueOf(httpSessionState.getRobotName())); | |
+ MDC.put("robotName", String.valueOf(httpSessionState.getRobot())); | |
new ClientLogger().log(LOG, fullRequest); | |
JSONObject response = new JSONObject(); | |
try { | |
@@ -66,7 +66,7 @@ public class ClientToolbox { | |
userId = user.getId(); | |
} | |
} | |
- Toolbox toolbox = tp.getToolbox(toolboxName, userId, httpSessionState.getRobotName()); | |
+ Toolbox toolbox = tp.getToolbox(toolboxName, userId, httpSessionState.getRobot()); | |
if ( toolbox != null ) { | |
response.put("data", toolbox.getToolboxText()); | |
} | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientUser.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientUser.java | |
index bd4e75e30..66a3b5eda 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientUser.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/javaServer/restServices/all/ClientUser.java | |
@@ -59,7 +59,7 @@ public class ClientUser { | |
AliveData.rememberClientCall(); | |
MDC.put("sessionId", String.valueOf(httpSessionState.getSessionNumber())); | |
MDC.put("userId", String.valueOf(httpSessionState.getUserId())); | |
- MDC.put("robotName", String.valueOf(httpSessionState.getRobotName())); | |
+ MDC.put("robotName", String.valueOf(httpSessionState.getRobot())); | |
new ClientLogger().log(ClientUser.LOG, fullRequest); | |
final int userId = httpSessionState.getUserId(); | |
JSONObject response = new JSONObject(); | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/HttpSessionState.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/HttpSessionState.java | |
index 9252e2141..b76476f0e 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/HttpSessionState.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/persistence/util/HttpSessionState.java | |
@@ -11,7 +11,7 @@ public class HttpSessionState { | |
public final static int NO_USER = -1; | |
private int userId = HttpSessionState.NO_USER; | |
- private String robotName; | |
+ private String robot; | |
private String token = "1Q2W3E4R"; | |
private String programName; | |
private String program; | |
@@ -24,7 +24,7 @@ public class HttpSessionState { | |
public HttpSessionState(RobotCommunicator robotCommunicator, Map<String, IRobotFactory> robotPluginMap, long sessionNumber) { | |
this.robotPluginMap = robotPluginMap; | |
- this.robotName = RobertaProperties.getDefaultRobot(); | |
+ this.robot = RobertaProperties.getDefaultRobot(); | |
this.sessionNumber = sessionNumber; | |
} | |
@@ -51,13 +51,13 @@ public class HttpSessionState { | |
this.configuration = null; | |
} | |
- public String getRobotName() { | |
- return this.robotName; | |
+ public String getRobot() { | |
+ return this.robot; | |
} | |
- public void setRobotName(String robotName) { | |
- Assert.notNull(robotName); | |
- this.robotName = robotName; | |
+ public void setRobot(String robot) { | |
+ Assert.notNull(robot); | |
+ this.robot = robot; | |
} | |
public String getToken() { | |
@@ -109,7 +109,7 @@ public class HttpSessionState { | |
} | |
public IRobotFactory getRobotFactory() { | |
- return this.robotPluginMap.get(this.robotName); | |
+ return this.robotPluginMap.get(this.robot); | |
} | |
public IRobotFactory getRobotFactory(String robotName) { | |
-- | |
2.13.1.611.g7e3b11ae1-goog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment