From 282912731356e1cb414070e197e57fb18626eeb0 Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Thu, 22 Aug 2019 14:02:43 +0200
Subject: [PATCH] added abstraction class OpenBisObject

---
 pybis/src/python/pybis/experiment.py | 68 +++-------------------------
 pybis/src/python/pybis/project.py    | 12 -----
 pybis/src/python/pybis/space.py      | 12 -----
 3 files changed, 6 insertions(+), 86 deletions(-)

diff --git a/pybis/src/python/pybis/experiment.py b/pybis/src/python/pybis/experiment.py
index 6cd6eca92fd..8a97b290441 100644
--- a/pybis/src/python/pybis/experiment.py
+++ b/pybis/src/python/pybis/experiment.py
@@ -4,40 +4,14 @@ from .openbis_object import OpenBisObject
 from .definitions import openbis_definitions
 from .utils import VERBOSE
 
-class Experiment(OpenBisObject):
-    """ 
+class Experiment(
+    OpenBisObject,
+    entity='experiment',
+    single_item_method_name='get_experiment'
+):
+    """Handling experiment (collection) entities in openBIS 
     """
 
-    def __init__(self, openbis_obj, type, project=None, data=None, props=None, code=None, **kwargs):
-        self.__dict__['openbis'] = openbis_obj
-        self.__dict__['type'] = type
-        ph = PropertyHolder(openbis_obj, type)
-        self.__dict__['p'] = ph
-        self.__dict__['props'] = ph
-        self.__dict__['a'] = AttrHolder(openbis_obj, 'Experiment', type)
-
-        if data is not None:
-            self._set_data(data)
-
-        if project is not None:
-            setattr(self, 'project', project)
-
-        if props is not None:
-            for key in props:
-                setattr(self.p, key, props[key])
-
-        if code is not None:
-            self.code = code
-
-        if kwargs is not None:
-            defs = openbis_definitions('Experiment')
-            for key in kwargs:
-                if key in defs['attrs']:
-                    setattr(self, key, kwargs[key])
-                else:
-                    raise ValueError("{attr} is not a known attribute for an Experiment".format(attr=key))
-
-
     def _set_data(self, data):
         # assign the attribute data to self.a by calling it
         # (invoking the AttrHolder.__call__ function)
@@ -94,36 +68,6 @@ class Experiment(OpenBisObject):
 
     set_props = set_properties
 
-    def save(self):
-        for prop_name, prop in self.props._property_names.items():
-            if prop['mandatory']:
-                if getattr(self.props, prop_name) is None or getattr(self.props, prop_name) == "":
-                    raise ValueError("Property '{}' is mandatory and must not be None".format(prop_name))
-
-        if self.is_new:
-            request = self._new_attrs()
-            props = self.p._all_props()
-            request["params"][1][0]["properties"] = props
-            resp = self.openbis._post_request(self.openbis.as_v3, request)
-
-            if VERBOSE: print("Experiment successfully created.")
-            new_exp_data = self.openbis.get_experiment(resp[0]['permId'], only_data=True)
-            self._set_data(new_exp_data)
-            return self
-        else:
-            request = self._up_attrs()
-            props = self.p._all_props()
-            request["params"][1][0]["properties"] = props
-            self.openbis._post_request(self.openbis.as_v3, request)
-            if VERBOSE: print("Experiment successfully updated.")
-            new_exp_data = self.openbis.get_experiment(self.permId, only_data=True)
-            self._set_data(new_exp_data)
-
-    def delete(self, reason):
-        if self.permId is None:
-            return None
-        self.openbis.delete_entity(entity='Experiment', id=self.permId, reason=reason)
-        if VERBOSE: print("Experiment {} successfully deleted.".format(self.permId))
 
     def get_datasets(self, **kwargs):
         if self.permId is None:
diff --git a/pybis/src/python/pybis/project.py b/pybis/src/python/pybis/project.py
index 6e4644103a4..1d022b4dbed 100644
--- a/pybis/src/python/pybis/project.py
+++ b/pybis/src/python/pybis/project.py
@@ -9,18 +9,6 @@ class Project(
     single_item_method_name='get_project'
 ):
 
-    def __init__(self, openbis_obj, data=None, **kwargs):
-        self.__dict__['openbis'] = openbis_obj
-        self.__dict__['a'] = AttrHolder(openbis_obj, 'project')
-
-        if data is not None:
-            self.a(data)
-            self.__dict__['data'] = data
-
-        if kwargs is not None:
-            for key in kwargs:
-                setattr(self, key, kwargs[key])
-
     def _modifiable_attrs(self):
         return
 
diff --git a/pybis/src/python/pybis/space.py b/pybis/src/python/pybis/space.py
index 9b7ad2f1e8d..c88a7748848 100644
--- a/pybis/src/python/pybis/space.py
+++ b/pybis/src/python/pybis/space.py
@@ -11,18 +11,6 @@ class Space(
     """ managing openBIS spaces
     """
 
-    def __init__(self, openbis_obj, data=None, **kwargs):
-        self.__dict__['openbis'] = openbis_obj
-        self.__dict__['a'] = AttrHolder(openbis_obj, 'space' )
-
-        if data is not None:
-            self.a(data)
-            self.__dict__['data'] = data
-
-        if kwargs is not None:
-            for key in kwargs:
-                setattr(self, key, kwargs[key])
-
     def __dir__(self):
         """all the available methods and attributes that should be displayed
         when using the autocompletion feature (TAB) in Jupyter
-- 
GitLab