From d710efbdacb8f6bf0fe0f4de243679d881dc861f Mon Sep 17 00:00:00 2001
From: pkupczyk <piotr.kupczyk@id.ethz.ch>
Date: Fri, 4 Dec 2020 14:40:42 +0100
Subject: [PATCH] V3_API : delete persons : SSDM-10395 - JavaScript part

---
 .../openbis-v3-api-test/html/test/common.js   |  9 ++++++++
 .../openbis-v3-api-test/html/test/dtos.js     |  3 +++
 .../html/test/openbis-execute-operations.js   |  4 ++++
 .../html/test/test-delete.js                  |  5 +++++
 .../person/delete/DeletePersonsOperation.js   | 21 +++++++++++++++++++
 .../delete/DeletePersonsOperationResult.js    | 21 +++++++++++++++++++
 .../person/delete/PersonDeletionOptions.js    | 19 +++++++++++++++++
 .../public/resources/api/v3/openbis.js        | 11 ++++++++++
 8 files changed, 93 insertions(+)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperation.js
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperationResult.js
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/PersonDeletionOptions.js

diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js
index e2b7354192b..f670c0e9e41 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js
@@ -87,6 +87,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.RoleAssignmentDeletionOptions = dtos.RoleAssignmentDeletionOptions;
 		this.SemanticAnnotationDeletionOptions = dtos.SemanticAnnotationDeletionOptions;
 		this.QueryDeletionOptions = dtos.QueryDeletionOptions;
+		this.PersonDeletionOptions = dtos.PersonDeletionOptions;
 		this.PersonPermId = dtos.PersonPermId;
 		this.Me = dtos.Me;
 		this.EntityTypePermId = dtos.EntityTypePermId;
@@ -349,6 +350,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.DeleteOperationExecutionsOperation = dtos.DeleteOperationExecutionsOperation;
 		this.DeleteSemanticAnnotationsOperation = dtos.DeleteSemanticAnnotationsOperation;
 		this.DeleteQueriesOperation = dtos.DeleteQueriesOperation;
+		this.DeletePersonsOperation = dtos.DeletePersonsOperation;
 
 		this.RevertDeletionsOperation = dtos.RevertDeletionsOperation;
 		this.ConfirmDeletionsOperation = dtos.ConfirmDeletionsOperation;
@@ -1055,6 +1057,13 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 			return facade.deleteQueries([ id ], options);
 		}.bind(this);
 
+		this.deletePerson = function(facade, id) {
+			var c = this;
+			var options = new dtos.PersonDeletionOptions();
+			options.setReason("test reason");
+			return facade.deletePersons([ id ], options);
+		}.bind(this);
+
 		this.getObjectProperty = function(object, propertyName) {
 			var propertyNames = propertyName.split('.');
 			for ( var pn in propertyNames) {
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
index b45e82922ce..93bd2e36e72 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
@@ -430,6 +430,9 @@ var sources = [
 	'as/dto/person/create/PersonCreation',
 	'as/dto/person/create/CreatePersonsOperation',
 	'as/dto/person/create/CreatePersonsOperationResult',
+	'as/dto/person/delete/DeletePersonsOperation',
+	'as/dto/person/delete/DeletePersonsOperationResult',
+	'as/dto/person/delete/PersonDeletionOptions',
 	'as/dto/person/get/GetPersonsOperation',
 	'as/dto/person/get/GetPersonsOperationResult',
 	'as/dto/person/id/Me',
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
index 531a946371c..a5194a57a03 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
@@ -568,6 +568,10 @@ define([ 'jquery', 'openbis', 'test/common' ], function($, openbis, common) {
 			return this._executeDeleteOperation(new c.DeleteQueriesOperation(ids, deletionOptions));
 		}
 
+		this.deletePersons = function(ids, deletionOptions) {
+			return this._executeDeleteOperation(new c.DeletePersonsOperation(ids, deletionOptions));
+		}
+
 		this.searchDeletions = function(criteria, fetchOptions) {
 			return this._executeSearchOperation(new c.SearchDeletionsOperation(criteria, fetchOptions));
 		}
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js
index 147a608ba8b..167a79fb79c 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js
@@ -307,6 +307,11 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 			testDeleteWithoutTrash(c, c.createQuery, c.findQuery, c.deleteQuery);
 		});
 
+		QUnit.test("deletePersons()", function(assert) {
+			var c = new common(assert, openbis);
+			testDeleteWithoutTrash(c, c.createPerson, c.findPerson, c.deletePerson);
+		});
+
 	}
 
 	return function() {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperation.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperation.js
new file mode 100644
index 00000000000..87304884b31
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperation.js
@@ -0,0 +1,21 @@
+define(['stjs', 'as/dto/common/delete/DeleteObjectsOperation'], function (
+  stjs,
+  DeleteObjectsOperation
+) {
+  var DeletePersonsOperation = function (objectIds, options) {
+    DeleteObjectsOperation.call(this, objectIds, options)
+  }
+  stjs.extend(
+    DeletePersonsOperation,
+    DeleteObjectsOperation,
+    [DeleteObjectsOperation],
+    function (constructor, prototype) {
+      prototype['@type'] = 'as.dto.person.delete.DeletePersonsOperation'
+      prototype.getMessage = function () {
+        return 'DeletePersonsOperation'
+      }
+    },
+    {}
+  )
+  return DeletePersonsOperation
+})
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperationResult.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperationResult.js
new file mode 100644
index 00000000000..7e9a22c00a2
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/DeletePersonsOperationResult.js
@@ -0,0 +1,21 @@
+define([
+  'stjs',
+  'as/dto/common/delete/DeleteObjectsWithoutTrashOperationResult'
+], function (stjs, DeleteObjectsWithoutTrashOperationResult) {
+  var DeletePersonsOperationResult = function () {
+    DeleteObjectsWithoutTrashOperationResult.call(this)
+  }
+  stjs.extend(
+    DeletePersonsOperationResult,
+    DeleteObjectsWithoutTrashOperationResult,
+    [DeleteObjectsWithoutTrashOperationResult],
+    function (constructor, prototype) {
+      prototype['@type'] = 'as.dto.person.delete.DeletePersonsOperationResult'
+      prototype.getMessage = function () {
+        return 'DeletePersonsOperationResult'
+      }
+    },
+    {}
+  )
+  return DeletePersonsOperationResult
+})
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/PersonDeletionOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/PersonDeletionOptions.js
new file mode 100644
index 00000000000..0067ee73fd4
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/person/delete/PersonDeletionOptions.js
@@ -0,0 +1,19 @@
+define(['stjs', 'as/dto/deletion/AbstractObjectDeletionOptions'], function (
+  stjs,
+  AbstractObjectDeletionOptions
+) {
+  var PersonDeletionOptions = function () {
+    AbstractObjectDeletionOptions.call(this)
+  }
+  stjs.extend(
+    PersonDeletionOptions,
+    AbstractObjectDeletionOptions,
+    [AbstractObjectDeletionOptions],
+    function (constructor, prototype) {
+      prototype['@type'] = 'as.dto.person.delete.PersonDeletionOptions'
+      constructor.serialVersionUID = 1
+    },
+    {}
+  )
+  return PersonDeletionOptions
+})
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 e9e2b9d2fff..772c118bd95 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
@@ -1882,6 +1882,17 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria
 			});
 		}
 
+		this.deletePersons = function(ids, deletionOptions) {
+			var thisFacade = this;
+			return thisFacade._private.ajaxRequest({
+				url : openbisUrl,
+				data : {
+					"method" : "deletePersons",
+					"params" : [ thisFacade._private.sessionToken, ids, deletionOptions ]
+				}
+			});
+		}
+
 		this.searchDeletions = function(criteria, fetchOptions) {
 			var thisFacade = this;
 			return thisFacade._private.ajaxRequest({
-- 
GitLab