Skip to content
Snippets Groups Projects
Commit cc63a403 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

added update vocabulary (work in progress)

parent 3816bc8e
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,9 @@ class Vocabulary(OpenBisObject): ...@@ -14,7 +14,9 @@ class Vocabulary(OpenBisObject):
self._set_data(data) self._set_data(data)
self.__dict__['terms'] = data['terms'] self.__dict__['terms'] = data['terms']
if terms is not None: if terms is None:
self.__dict__['terms'] = []
else:
self.__dict__['terms'] = terms self.__dict__['terms'] = terms
if self.is_new: if self.is_new:
...@@ -37,29 +39,28 @@ class Vocabulary(OpenBisObject): ...@@ -37,29 +39,28 @@ class Vocabulary(OpenBisObject):
""" """
return self.openbis.get_terms(vocabulary=self.code) return self.openbis.get_terms(vocabulary=self.code)
def add_term(self, code, label=None, description=None): def add_term(self, code, label=None, description=None):
""" Adds a term to this Vocabulary. """ Adds a term to this Vocabulary.
If Vocabulary is already persistent, it is added by adding a new VocabularyTerm object. If Vocabulary is already persistent, it is added by adding a new VocabularyTerm object.
If Vocabulary is new, the term is added to the list of terms If Vocabulary is new, the term is added to the list of terms
""" """
if self.is_new: self.__dict__['terms'].append({
self.__dict__['terms'].append({ "code": code,
"code": code, "label": label,
"label": label, "description": description
"description": description })
})
else:
pass
def save(self): def save(self):
terms = self.__dict__['terms']
for term in terms:
term["@type"]= "as.dto.vocabulary.create.VocabularyTermCreation"
if self.is_new: if self.is_new:
request = self._new_attrs('createVocabularies') request = self._new_attrs('createVocabularies')
# add the VocabularyTerm datatype if terms:
terms = self.__dict__['terms'] request['params'][1][0]['terms'] = terms
for term in terms:
term["@type"]= "as.dto.vocabulary.create.VocabularyTermCreation"
request['params'][1][0]['terms'] = terms
resp = self.openbis._post_request(self.openbis.as_v3, request) resp = self.openbis._post_request(self.openbis.as_v3, request)
if VERBOSE: print("Vocabulary successfully created.") if VERBOSE: print("Vocabulary successfully created.")
...@@ -69,6 +70,12 @@ class Vocabulary(OpenBisObject): ...@@ -69,6 +70,12 @@ class Vocabulary(OpenBisObject):
else: else:
request = self._up_attrs('updateVocabularies') request = self._up_attrs('updateVocabularies')
request['params'][1][0]['vocabularyId'] = {
"@type": "as.dto.vocabulary.id.IVocabularyId",
"vocabularyId" : self.code
}
if terms:
request['params'][1][0]['terms'] = terms
self.openbis._post_request(self.openbis.as_v3, request) self.openbis._post_request(self.openbis.as_v3, request)
if VERBOSE: print("Vocabulary successfully updated.") if VERBOSE: print("Vocabulary successfully updated.")
data = self.openbis.get_vocabulary(self.permId, only_data=True) data = self.openbis.get_vocabulary(self.permId, only_data=True)
...@@ -81,7 +88,6 @@ class VocabularyTerm(OpenBisObject): ...@@ -81,7 +88,6 @@ class VocabularyTerm(OpenBisObject):
self.__dict__['openbis'] = openbis_obj self.__dict__['openbis'] = openbis_obj
self.__dict__['a'] = AttrHolder(openbis_obj, 'VocabularyTerm') self.__dict__['a'] = AttrHolder(openbis_obj, 'VocabularyTerm')
if data is not None: if data is not None:
self._set_data(data) self._set_data(data)
...@@ -89,7 +95,6 @@ class VocabularyTerm(OpenBisObject): ...@@ -89,7 +95,6 @@ class VocabularyTerm(OpenBisObject):
for key in kwargs: for key in kwargs:
setattr(self, key, kwargs[key]) setattr(self, key, kwargs[key])
@property @property
def vocabularyCode(self): def vocabularyCode(self):
if self.is_new: if self.is_new:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment