diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/ProgramProcessor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/ProgramProcessor.java
index f9ae00154..d7451b120 100644
--- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/ProgramProcessor.java
+++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/ProgramProcessor.java
@@ -164,17 +164,16 @@ private Program getProgramWithAccessRight(String programName, int ownerId) {
}
/**
- * update a given program owned by a given user. Overwrites an existing program if mayExist == true.
+ * insert or update a given program owned by a given user. Overwrites an existing program if mayExist == true.
*
* @param programName the name of the program
* @param userId the owner of the program
- * @param robotId
- * @param programText the new program text
- * @param programTimestamp Program timestamp
- * @param mayExist true, if an existing program may be changed; false if a program may be stored only, if it does not exist in the database
+ * @param robotId the id of the robot the program was written for
+ * @param programText the program text
+ * @param programTimestamp timestamp of the last change of the program (if it already existed); null
if a new program is saved
* @param isOwner true, if the owner updates a program; false if a user with access right WRITE updates a program
*/
- public Program updateProgram(String programName, int userId, int robotId, String programText, Timestamp programTimestamp, boolean isOwner) {
+ public Program persistProgramText(String programName, int userId, int robotId, String programText, Timestamp programTimestamp, boolean isOwner) {
if ( !Util.isValidJavaIdentifier(programName) ) {
setError(Key.PROGRAM_ERROR_ID_INVALID, programName);
return null;
@@ -185,8 +184,13 @@ public Program updateProgram(String programName, int userId, int robotId, String
ProgramDao programDao = new ProgramDao(this.dbSession);
User user = userDao.get(userId);
Robot robot = robotDao.get(robotId);
- Pair result = programDao.persistProgramText(programName, user, robot, programText, programTimestamp, isOwner);
- // a bit strange, but necessary to distinguish between success and failure
+ Pair result;
+ if ( isOwner ) {
+ result = programDao.persistOwnProgram(programName, user, robot, programText, programTimestamp);
+ } else {
+ result = programDao.persistSharedProgramText(programName, user, robot, programText, programTimestamp);
+ }
+ // a bit strange, but necessary as Java has no N-tuple
if ( result.getFirst() == Key.PROGRAM_SAVE_SUCCESS ) {
setSuccess(Key.PROGRAM_SAVE_SUCCESS);
} else {
diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/dao/ProgramDao.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/dao/ProgramDao.java
index 46a7a13e3..cacd6f7e0 100644
--- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/dao/ProgramDao.java
+++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/persistence/dao/ProgramDao.java
@@ -37,58 +37,72 @@ public ProgramDao(DbSession session) {
}
/**
- * make a program object and persist it (if the program, identified by owner&name&robot, does not exist) or update it (if the program exists)
+ * persist a program object that is owned by the caller
*
* @param name the name of the program, never null
* @param user the user who owns the program, never null
- * @param robotId
- * @param programText the program text, maybe null
- * @param timestamp timestamp of the program, never null
- * @param isOwner true, if the owner updates a program; false if a user with access right WRITE updates a program
- * @return true if the program could be persisted successfully
+ * @param robotId the robot the program was written for
+ * @param programText the program text
+ * @param programTimestamp timestamp of the last change of the program (if it already existed); null
if a new program is saved
+ * @return a pair of (message-key, program). If the program is persisted successfully, the program is NOT null.
*/
- public Pair persistProgramText(String name, User user, Robot robot, String programText, Timestamp timestamp, boolean isOwner) {
+ public Pair persistOwnProgram(String name, User user, Robot robot, String programText, Timestamp timestamp) {
Assert.notNull(name);
Assert.notNull(user);
Assert.notNull(robot);
- Assert.notNull(timestamp);
-
- if ( isOwner ) {
- Program program = load(name, user, robot);
- if ( program == null ) {
- if ( timestamp.equals(new Timestamp(0)) ) {
- // the program doesn't exist, thus the expected timestamp must not be set
- program = new Program(name, user, robot);
- program.setProgramText(programText);
- this.session.save(program);
- return Pair.of(Key.PROGRAM_SAVE_SUCCESS, program); // the only legal key if success
- } else {
- // otherwise ...
- ProgramDao.LOG.error("update was requested, but no program with matching timestamp was found");
- return Pair.of(Key.PROGRAM_SAVE_ERROR_NO_PROGRAM_TO_UPDATE_FOUND, null);
- }
- } else if ( !timestamp.equals(program.getLastChanged()) ) {
- ProgramDao.LOG.error("update was requested, timestamps don't match. Has another user updated the program in the meantime?");
- return Pair.of(Key.PROGRAM_SAVE_ERROR_OPTIMISTIC_TIMESTAMP_LOCKING, null);
- } else {
+ Program program = load(name, user, robot);
+ if ( program == null ) {
+ if ( timestamp == null ) {
+ // save as && the program doesn't exist.
+ program = new Program(name, user, robot);
program.setProgramText(programText);
+ this.session.save(program);
return Pair.of(Key.PROGRAM_SAVE_SUCCESS, program); // the only legal key if success
+ } else {
+ return Pair.of(Key.PROGRAM_SAVE_ERROR_PROGRAM_TO_UPDATE_NOT_FOUND, null);
}
} else {
- Program program = loadSharedForUpdate(name, user, robot);
- if ( program == null ) {
- ProgramDao.LOG.error("update was requested, but no shared program was found");
- return Pair.of(Key.PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION, null);
- } else if ( !timestamp.equals(program.getLastChanged()) ) {
- ProgramDao.LOG.error("update was requested, timestamps don't match. Has another user updated the program in the meantime?");
- return Pair.of(Key.PROGRAM_SAVE_ERROR_OPTIMISTIC_TIMESTAMP_LOCKING, null);
- } else {
+ if ( timestamp == null ) {
+ // save as && the program exists.
+ return Pair.of(Key.PROGRAM_SAVE_AS_ERROR_PROGRAM_EXISTS, null);
+ } else if ( timestamp.equals(program.getLastChanged()) ) {
program.setProgramText(programText);
return Pair.of(Key.PROGRAM_SAVE_SUCCESS, program); // the only legal key if success
+ } else {
+ ProgramDao.LOG.error("update was requested, timestamps don't match. Has another user updated the program in the meantime?");
+ return Pair.of(Key.PROGRAM_SAVE_ERROR_OPTIMISTIC_TIMESTAMP_LOCKING, null);
}
}
}
+ /**
+ * persist a program object that the owner shared with the caller
+ *
+ * @param name the name of the program, never null
+ * @param user the user who owns the program, never null
+ * @param robotId the robot the program was written for
+ * @param programText the program text
+ * @param programTimestamp timestamp of the last change of the program (if it already existed); null
if a new program is saved
+ * @return a pair of (message-key, program). If the program is persisted successfully, the program is NOT null.
+ */
+ public Pair persistSharedProgramText(String name, User user, Robot robot, String programText, Timestamp timestamp) {
+ Assert.notNull(name);
+ Assert.notNull(user);
+ Assert.notNull(robot);
+
+ Program program = loadSharedForUpdate(name, user, robot);
+ if ( program == null ) {
+ ProgramDao.LOG.error("update was requested, but no shared program was found");
+ return Pair.of(Key.PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION, null);
+ } else if ( !timestamp.equals(program.getLastChanged()) ) {
+ ProgramDao.LOG.error("update was requested, timestamps don't match. Has another user updated the program in the meantime?");
+ return Pair.of(Key.PROGRAM_SAVE_ERROR_OPTIMISTIC_TIMESTAMP_LOCKING, null);
+ } else {
+ program.setProgramText(programText);
+ return Pair.of(Key.PROGRAM_SAVE_SUCCESS, program); // the only legal key if success
+ }
+ }
+
/**
* load a program from the database, identified by its owner, its name (both make up the "business" key of a program)
* The timestamp used for optimistic locking is not checked here. The caller is responsible to do that!
diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/Key.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/Key.java
index b363200c3..88c6d3f77 100644
--- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/Key.java
+++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/Key.java
@@ -34,9 +34,10 @@ public enum Key {
PROGRAM_GET_ONE_SUCCESS(),
PROGRAM_GET_ONE_ERROR_NOT_FOUND,
PROGRAM_GET_ONE_ERROR_NOT_LOGGED_IN,
- PROGRAM_SAVE_ERROR_NO_PROGRAM_TO_UPDATE_FOUND,
+ PROGRAM_SAVE_AS_ERROR_PROGRAM_EXISTS,
PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION,
PROGRAM_SAVE_ERROR_OPTIMISTIC_TIMESTAMP_LOCKING,
+ PROGRAM_SAVE_ERROR_PROGRAM_TO_UPDATE_NOT_FOUND,
PROGRAM_SAVE_SUCCESS,
PROGRAM_GET_ALL_SUCCESS,
PROGRAM_DELETE_SUCCESS,
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 6ce6e09aa..83822586e 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
@@ -86,13 +86,19 @@ public Response command(@OraData HttpSessionState httpSessionState, JSONObject f
AccessRightProcessor upp = new AccessRightProcessor(dbSession, httpSessionState);
UserProcessor up = new UserProcessor(dbSession, httpSessionState);
- if ( cmd.equals("saveP") ) {
+ if ( cmd.equals("saveP") || cmd.equals("saveAsP") ) {
String programName = request.getString("name");
String programText = request.getString("program");
- Long timestamp = request.getLong("timestamp");
- Timestamp programTimestamp = new Timestamp(timestamp);
- boolean isShared = request.optBoolean("shared", false);
- Program program = pp.updateProgram(programName, userId, robotId, programText, programTimestamp, !isShared);
+ Program program;
+ if ( cmd.equals("saveP") ) {
+ // update an already existing program
+ Long timestamp = request.getLong("timestamp");
+ Timestamp programTimestamp = new Timestamp(timestamp);
+ boolean isShared = request.optBoolean("shared", false);
+ program = pp.persistProgramText(programName, userId, robotId, programText, programTimestamp, !isShared);
+ } else {
+ program = pp.persistProgramText(programName, userId, robotId, programText, null, true);
+ }
if ( pp.isOk() ) {
if ( program != null ) {
response.put("lastChanged", program.getLastChanged());
@@ -115,18 +121,6 @@ public Response command(@OraData HttpSessionState httpSessionState, JSONObject f
forMessages.setSuccess(Key.COMPILERWORKFLOW_PROGRAM_GENERATION_SUCCESS);
}
Util.addResultInfo(response, forMessages);
- } else if ( cmd.equals("saveAsP") ) {
- String programName = request.getString("name");
- String programText = request.getString("program");
- Timestamp programTimestamp = new Timestamp(0);
- pp.updateProgram(programName, userId, robotId, programText, programTimestamp, true);
- if ( pp.isOk() ) {
- Program program = pp.getProgram(programName, userId, robotId);
- if ( program != null ) {
- response.put("lastChanged", program.getLastChanged());
- }
- }
- Util.addResultInfo(response, pp);
} else if ( cmd.equals("loadP") && (httpSessionState.isUserLoggedIn() || request.getString("owner").equals("Roberta")) ) {
String programName = request.getString("name");
diff --git a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/restInterfaceTest/UserRelatedRestInterfaceTest.java b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/restInterfaceTest/RestInterfaceTest.java
similarity index 91%
rename from OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/restInterfaceTest/UserRelatedRestInterfaceTest.java
rename to OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/restInterfaceTest/RestInterfaceTest.java
index 2b242331d..a02e2af4e 100644
--- a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/restInterfaceTest/UserRelatedRestInterfaceTest.java
+++ b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/restInterfaceTest/RestInterfaceTest.java
@@ -54,7 +54,7 @@
*
* @author rbudde
*/
-public class UserRelatedRestInterfaceTest {
+public class RestInterfaceTest {
private SessionFactoryWrapper sessionFactoryWrapper; // used by REST services to retrieve data base sessions
private DbSetup memoryDbSetup; // use to query the test data base, change the data base at will, etc.
@@ -188,28 +188,31 @@ private void loginLogoutPid() throws Exception {
* INVARIANT: two user exist, both user have logged in
* PRE: no program exists
* POST: "pid" owns four programs
- * - store 4 programs and check the count in the db
- * - update program 2 and check the effect in the data base
+ * - store (saveAs) 4 programs and check the count in the db
+ * - update (save) program 2 and check the effect in the data base
* - check that 4 programs are stored, check their names
+ * - check that (1) the program to save exists (2) the program in saveAs doesn't exist
*/
private void pidCreateAndUpdate4Programs() throws Exception, JSONException {
int pidId = this.sPid.getUserId();
Assert.assertTrue(this.sPid.isUserLoggedIn() && this.sMinscha.isUserLoggedIn());
Assert.assertEquals(0, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM"));
Assert.assertEquals(0, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + pidId));
- storeProgram(this.sPid, pidId, "p1", ".1.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
- storeProgram(this.sPid, pidId, "p2", ".2.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
- storeProgram(this.sPid, pidId, "p3", ".3.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
- storeProgram(this.sPid, pidId, "p4", ".4.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ saveAs(this.sPid, pidId, "p1", ".1.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ saveAs(this.sPid, pidId, "p2", ".2.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ saveAs(this.sPid, pidId, "p3", ".3.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ saveAs(this.sPid, pidId, "p4", ".4.pid", "ok", Key.PROGRAM_SAVE_SUCCESS);
Assert.assertEquals(4, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + pidId));
Assert.assertEquals(4, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM"));
- updateProgram(this.sPid, pidId, "p2", -1, ".2.pid.updated", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sPid, pidId, "p2", -1, ".2.pid.updated", "ok", Key.PROGRAM_SAVE_SUCCESS);
Assert.assertEquals(4, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + pidId));
Assert.assertEquals(4, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM"));
String program = this.memoryDbSetup.getOne("select PROGRAM_TEXT from PROGRAM where OWNER_ID = " + pidId + " and NAME = 'p2'");
Assert.assertTrue(program.contains(".2.pid.updated"));
assertProgramListingAsExpected(this.sPid, "['p1','p2','p3','p4']");
Assert.assertTrue(this.sPid.isUserLoggedIn() && this.sMinscha.isUserLoggedIn());
+ saveAs(this.sPid, pidId, "p4", ".4.pid", "error", Key.PROGRAM_SAVE_AS_ERROR_PROGRAM_EXISTS);
+ save(this.sPid, pidId, "p5", 0, ".5.pid", "error", Key.PROGRAM_SAVE_ERROR_PROGRAM_TO_UPDATE_NOT_FOUND);
}
/**
@@ -226,8 +229,8 @@ private void minschaCreate2Programs() throws Exception {
Assert.assertTrue(this.sPid.isUserLoggedIn() && this.sMinscha.isUserLoggedIn());
Assert.assertEquals(0, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + minschaId));
Assert.assertEquals(4, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + pidId));
- storeProgram(this.sMinscha, minschaId, "p1", ".1.minscha", "ok", Key.PROGRAM_SAVE_SUCCESS);
- storeProgram(this.sMinscha, minschaId, "p2", ".2.minscha", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ saveAs(this.sMinscha, minschaId, "p1", ".1.minscha", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ saveAs(this.sMinscha, minschaId, "p2", ".2.minscha", "ok", Key.PROGRAM_SAVE_SUCCESS);
Assert.assertEquals(2, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + minschaId));
Assert.assertEquals(4, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where OWNER_ID = " + pidId));
Assert.assertEquals(6, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM"));
@@ -276,10 +279,10 @@ private void pidSharesProgramsMinschaCanAccessRW() throws Exception, JSONExcepti
Assert.assertTrue(this.response.getEntity().toString().contains(".3.pid"));
Assert.assertEquals(0, this.memoryDbSetup.getOneBigIntegerAsLong("select count(*) from PROGRAM where NAME = 'pDoesntExist'"));
- updateProgram(this.sMinscha, pidId, "p2", -1, ".2.minscha.update", "error", Key.PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION);
+ save(this.sMinscha, pidId, "p2", -1, ".2.minscha.update", "error", Key.PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION);
String p2Text = this.memoryDbSetup.getOne("select PROGRAM_TEXT from PROGRAM where OWNER_ID = " + pidId + " and NAME = 'p2'");
Assert.assertTrue(p2Text.contains(".2.pid.updated"));
- updateProgram(this.sMinscha, pidId, "p3", -1, ".3.minscha.update", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sMinscha, pidId, "p3", -1, ".3.minscha.update", "ok", Key.PROGRAM_SAVE_SUCCESS);
String p3Text = this.memoryDbSetup.getOne("select PROGRAM_TEXT from PROGRAM where OWNER_ID = " + pidId + " and NAME = 'p3'");
Assert.assertTrue(p3Text.contains(".3.minscha.update"));
@@ -344,13 +347,13 @@ private void pidSharesProgram1MinschaCanDeleteTheShare() throws Exception, JSONE
Assert.assertTrue(p4Text.contains(".4.pid"));
restProgram(this.sPid, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
Assert.assertTrue(this.response.getEntity().toString().contains(".4.pid"));
- updateProgram(this.sMinscha, pidId, "p4", -1, ".4.minscha.update", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sMinscha, pidId, "p4", -1, ".4.minscha.update", "ok", Key.PROGRAM_SAVE_SUCCESS);
String p4TextUpd1 = this.memoryDbSetup.getOne("select PROGRAM_TEXT from PROGRAM where OWNER_ID = " + pidId + " and NAME = 'p4'");
Assert.assertTrue(p4TextUpd1.contains(".4.minscha.update"));
restProgram(this.sPid, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
Assert.assertTrue(this.response.getEntity().toString().contains(".4.minscha.update"));
restProgram(this.sMinscha, "{'cmd':'shareDelete';'programName':'p4';'owner':'pid'}", "ok", Key.ACCESS_RIGHT_DELETED);
- updateProgram(this.sMinscha, pidId, "p4", -1, ".4.minscha.fail", "error", Key.PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION);
+ save(this.sMinscha, pidId, "p4", -1, ".4.minscha.fail", "error", Key.PROGRAM_SAVE_ERROR_NO_WRITE_PERMISSION);
assertProgramListingAsExpected(this.sMinscha, "['p1']");
assertProgramListingAsExpected(this.sPid, "['p1','p4']");
String p4TextUpd2 = this.memoryDbSetup.getOne("select PROGRAM_TEXT from PROGRAM where OWNER_ID = " + pidId + " and NAME = 'p4'");
@@ -372,7 +375,7 @@ private void pidAndMinschaAccessConcurrently() throws Exception, JSONException {
int minschaId = this.sMinscha.getUserId();
assertProgramListingAsExpected(this.sPid, "['p1','p4']");
assertProgramListingAsExpected(this.sMinscha, "['p1']");
- updateProgram(this.sPid, pidId, "p4", -1, ".4.pId", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sPid, pidId, "p4", -1, ".4.pId", "ok", Key.PROGRAM_SAVE_SUCCESS);
restProgram(this.sPid, "{'cmd':'shareP';'programName':'p4';'userToShare':'minscha';'right':'WRITE'}", "ok", Key.ACCESS_RIGHT_CHANGED);
assertProgramListingAsExpected(this.sPid, "['p1','p4']");
assertProgramListingAsExpected(this.sMinscha, "['p1','p4']");
@@ -388,7 +391,7 @@ private void pidAndMinschaAccessConcurrently() throws Exception, JSONException {
restProgram(this.sMinscha, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
Assert.assertTrue(this.response.getEntity().toString().contains(".4.pId"));
long lastChanged1 = ((JSONObject) this.response.getEntity()).getLong("lastChanged");
- updateProgram(this.sMinscha, pidId, "p4", lastChanged1, ".4.minscha.update", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sMinscha, pidId, "p4", lastChanged1, ".4.minscha.update", "ok", Key.PROGRAM_SAVE_SUCCESS);
String p4TextUpd1 = this.memoryDbSetup.getOne("select PROGRAM_TEXT from PROGRAM where OWNER_ID = " + pidId + " and NAME = 'p4'");
Assert.assertTrue(p4TextUpd1.contains(".4.minscha.update"));
restProgram(this.sMinscha, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
@@ -402,10 +405,10 @@ private void pidAndMinschaAccessConcurrently() throws Exception, JSONException {
long minschaReadTimestamp = ((JSONObject) this.response.getEntity()).getLong("lastChanged");
restProgram(this.sPid, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
long pidReadTimestamp = ((JSONObject) this.response.getEntity()).getLong("lastChanged");
- updateProgram(this.sPid, pidId, "p4", pidReadTimestamp, ".4.pid.concurrentOk", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sPid, pidId, "p4", pidReadTimestamp, ".4.pid.concurrentOk", "ok", Key.PROGRAM_SAVE_SUCCESS);
restProgram(this.sPid, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
Assert.assertTrue(this.response.getEntity().toString().contains(".4.pid.concurrentOk"));
- updateProgram(
+ save(
this.sMinscha,
pidId,
"p4",
@@ -422,10 +425,10 @@ private void pidAndMinschaAccessConcurrently() throws Exception, JSONException {
long minschaReadTimestamp = ((JSONObject) this.response.getEntity()).getLong("lastChanged");
restProgram(this.sPid, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
long pidReadTimestamp = ((JSONObject) this.response.getEntity()).getLong("lastChanged");
- updateProgram(this.sMinscha, pidId, "p4", minschaReadTimestamp, ".4.minscha.concurrentOk", "ok", Key.PROGRAM_SAVE_SUCCESS);
+ save(this.sMinscha, pidId, "p4", minschaReadTimestamp, ".4.minscha.concurrentOk", "ok", Key.PROGRAM_SAVE_SUCCESS);
restProgram(this.sMinscha, "{'cmd':'loadP';'name':'p4';'owner':'pid'}", "ok", Key.PROGRAM_GET_ONE_SUCCESS);
Assert.assertTrue(this.response.getEntity().toString().contains(".4.minscha.concurrentOk"));
- updateProgram(
+ save(
this.sPid,
pidId,
"p4",
@@ -470,7 +473,7 @@ private void restProgram(HttpSessionState httpSession, String jsonAsString, Stri
}
/**
- * call the REST service responsible for storing NEW programs into the data base. NEW programs are never shared ... .
+ * call the REST service responsible for storing NEW programs into the data base ("saveAs"). NEW programs are never shared ... .
*
* @param httpSession the session on which behalf the call is executed
* @param owner the id of the owner of the program
@@ -480,15 +483,15 @@ private void restProgram(HttpSessionState httpSession, String jsonAsString, Stri
* @param msgOpt optional key for the message; maybe null
* @throws Exception
*/
- private void storeProgram(HttpSessionState httpSession, int owner, String name, String program, String result, Key msgOpt) throws Exception //
+ private void saveAs(HttpSessionState httpSession, int owner, String name, String program, String result, Key msgOpt) throws Exception //
{
- String jsonAsString = "{'cmd':'saveP';'shared':false;'name':'" + name + "';'timestamp':0;'program':'" + program + "'}";
+ String jsonAsString = "{'cmd':'saveAsP';'name':'" + name + "';'program':'" + program + "'}";
this.response = this.restProgram.command(httpSession, JSONUtilForServer.mkD(jsonAsString));
JSONUtilForServer.assertEntityRc(this.response, result, msgOpt);
}
/**
- * call the REST service responsible for UPDATING programs in the data base. The program may be shared ... .
+ * call the REST service responsible for UPDATING programs in the data base (save). The program may be shared ... .
*
* @param httpSession the session on which behalf the call is executed
* @param owner the id of the owner of the program
@@ -499,7 +502,7 @@ private void storeProgram(HttpSessionState httpSession, int owner, String name,
* @param msgOpt optional key for the message; maybe null
* @throws Exception
*/
- private void updateProgram(HttpSessionState httpSession, int owner, String name, long timestamp, String program, String result, Key msgOpt) throws Exception //
+ private void save(HttpSessionState httpSession, int owner, String name, long timestamp, String program, String result, Key msgOpt) throws Exception //
{
boolean shared = httpSession.getUserId() != owner;
if ( timestamp == -1 ) {