From e4d5520557e51fc6ab92b86bf628e086c226081b Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Mon, 21 Dec 2015 14:35:10 +0000
Subject: [PATCH] SSDM-2903 : V3 AS API - fix inconsistencies between Java and
 JS DTOs found by automated test

SVN: 35388
---
 .../openbis-v3-api-test/html/test/test-dto.js    |  2 +-
 .../openbis-v3-api-test/html/test/test-login.js  |  1 +
 .../common/openBIS-server/etc/service.properties |  2 +-
 .../server/asapi/v3/ApplicationServerApi.java    |  3 ++-
 .../api/v3/dto/service/ExecutionOptions.js       |  2 +-
 .../openbis/public/resources/api/v3/openbis.js   | 16 ++++++++--------
 6 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-dto.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-dto.js
index ec85a751157..2c1d7e92ab5 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-dto.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-dto.js
@@ -59,7 +59,7 @@ define([ 'test/common' ], function(common) {
 
 			require([ 'dto/common/search/' + criteriaClassName ], function(Criteria) {
 				var criteria = new Criteria(name, type);
-				criteria.equalTo(42);
+				criteria.thatEquals(42);
 				assertAttributes(assert, criteria, name, type, "NumberEqualToValue", 42);
 				done();
 			});
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-login.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-login.js
index 7243d6e0ca0..962baaf75b2 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-login.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-login.js
@@ -36,6 +36,7 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common' ], function($, _, open
 				return facade.loginAsAnonymousUser().then(function() {
 					return facade.searchSpaces(criteria, fetchOptions).then(function(spaces) {
 						c.assertTrue(spaces.getTotalCount() == 1)
+						c.finish();						
 					});
 				});
 			}).fail(function(error) {
diff --git a/js-test/servers/common/openBIS-server/etc/service.properties b/js-test/servers/common/openBIS-server/etc/service.properties
index 14b5d5affec..3c35ceaa768 100644
--- a/js-test/servers/common/openBIS-server/etc/service.properties
+++ b/js-test/servers/common/openBIS-server/etc/service.properties
@@ -100,7 +100,7 @@ ldap.timeToWaitAfterFailure=
 # Anonymous login configuration (optional)
 # ---------------------------------------------------------------------------
 # Login of the existing user whose settings will be used for anonymous login 
-#user-for-anonymous-login = <user-login>
+user-for-anonymous-login = observer
 
 # ---------------------------------------------------------------------------
 # Client configuration
diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java
index b4ad6161b05..eada9e5de19 100644
--- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java
+++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java
@@ -219,7 +219,7 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi>
 
     @Autowired
     private ISearchServiceMethodExecutor searchServiceExecutor;
-    
+
     @Autowired
     private IDeleteSpaceMethodExecutor deleteSpaceExecutor;
 
@@ -274,6 +274,7 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi>
     }
 
     @Override
+    @Transactional
     public String loginAsAnonymousUser()
     {
         SessionContextDTO session = tryAuthenticateAnonymously();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/dto/service/ExecutionOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/dto/service/ExecutionOptions.js
index a6f18d7074a..7b97bafd871 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/dto/service/ExecutionOptions.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/dto/service/ExecutionOptions.js
@@ -9,7 +9,7 @@ define([ "stjs"], function(stjs) {
 		prototype.withParameter = function(parameterName, value) {
 			this.parameters[parameterName] = value;
 		}
-		proptotype.getParameters = function() {
+		prototype.getParameters = function() {
 			return this.parameters;
 		}
 	}, {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js
index 0c6073ea8a7..1fe8aa379bd 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js
@@ -48,12 +48,12 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 			return dfd.promise();
 		};
 
-		this.loginCommon = function(user, response) {
+		this.loginCommon = function(user, isAnonymousUser, response) {
 			var thisPrivate = this;
 			var dfd = $.Deferred();
 
 			response.done(function(sessionToken) {
-				if (sessionToken && sessionToken.indexOf(user) > -1) {
+				if (sessionToken && (isAnonymousUser || sessionToken.indexOf(user) > -1)) {
 					thisPrivate.sessionToken = sessionToken;
 					dfd.resolve(sessionToken);
 				} else {
@@ -82,7 +82,7 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 
 		this.login = function(user, password) {
 			var thisFacade = this;
-			return thisFacade._private.loginCommon(user, thisFacade._private.ajaxRequest({
+			return thisFacade._private.loginCommon(user, false, thisFacade._private.ajaxRequest({
 				url : openbisUrl,
 				data : {
 					"method" : "login",
@@ -93,7 +93,7 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 
 		this.loginAs = function(user, password, asUserId) {
 			var thisFacade = this;
-			return thisFacade._private.loginCommon(asUserId, thisFacade._private.ajaxRequest({
+			return thisFacade._private.loginCommon(asUserId, false, thisFacade._private.ajaxRequest({
 				url : openbisUrl,
 				data : {
 					"method" : "loginAs",
@@ -104,11 +104,11 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 
 		this.loginAsAnonymousUser = function() {
 			var thisFacade = this;
-			return thisFacade._private.loginCommon(user, thisFacade._private.ajaxRequest({
+			return thisFacade._private.loginCommon(null, true, thisFacade._private.ajaxRequest({
 				url : openbisUrl,
 				data : {
 					"method" : "loginAsAnonymousUser",
-					"params" : [  ]
+					"params" : []
 				}
 			}));
 		}
@@ -378,7 +378,7 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 				}
 			});
 		}
-		
+
 		this.searchServices = function(criteria, fetchOptions) {
 			var thisFacade = this;
 			return thisFacade._private.ajaxRequest({
@@ -488,7 +488,7 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) {
 				}
 			});
 		}
-		
+
 		this.executeService = function(serviceId, parameters) {
 			var thisFacade = this;
 			return thisFacade._private.ajaxRequest({
-- 
GitLab