Skip to content

Commit

Permalink
mds3: temporarily support editing theme
Browse files Browse the repository at this point in the history
  • Loading branch information
RayPlante committed Feb 20, 2024
1 parent abc9e64 commit 7d7f76e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions python/nistoar/midas/dap/service/mds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ def _summarize(self, nerd: NERDResource):

_handsoff = ("@id @context publisher issued firstIssued revised annotated version " + \
"bureauCode programCode systemOfRecords primaryITInvestmentUII " + \
"doi ediid releaseHistory status theme").split()
"doi ediid releaseHistory status").split() # temporarily allow theme editing
# "doi ediid releaseHistory status theme").split()

def _update_all_nerd(self, prec: ProjectRecord, nerd: NERDResource,
data: Mapping, provact: Action, replace=False):
Expand Down Expand Up @@ -1151,6 +1152,21 @@ def _update_part_nerd(self, path: str, prec: ProjectRecord, nerd: NERDResource,
nerd.replace_res_data(res)
data = res[path]

# NOTE!!: Temporary support for updating theme
elif path == "theme":
if not isinstance(data, (list, str)):
raise InvalidUpdate(part+" data is not a list of strings", sys=self)
res = nerd.get_res_data()
old = res.get(path)

res[path] = self._moderate_keyword(data, res, doval=doval, replace=replace,
kwpropname='theme') # may raise InvalidUpdate
provact.add_subaction(Action(Action.PUT if replace else Action.PATCH,
prec.id+"#data."+path, self.who, "updating "+path,
self._jsondiff(old, res[path])))
nerd.replace_res_data(res)
data = res[path]

elif path == "landingPage":
if not isinstance(data, str):
raise InvalidUpdate("description data is not a string", sys=self)
Expand Down Expand Up @@ -1675,7 +1691,7 @@ def _moderate_description(self, val, resmd=None, doval=True, replace=True):
raise InvalidUpdate("description value is not a string or array of strings", sys=self)
return [self._moderate_text(t, resmd, doval=doval) for t in val if t]

def _moderate_keyword(self, val, resmd=None, doval=True, replace=True):
def _moderate_keyword(self, val, resmd=None, doval=True, replace=True, kwpropname='keyword'):
if val is None:
val = []
if isinstance(val, str):
Expand All @@ -1684,7 +1700,7 @@ def _moderate_keyword(self, val, resmd=None, doval=True, replace=True):
raise InvalidUpdate("keywords value is not a string or array of strings", sys=self)

# uniquify list
out = resmd.get('keyword', []) if resmd and not replace else []
out = resmd.get(kwpropname, []) if resmd and not replace else []
for v in val:
if v not in out:
out.append(self._moderate_text(v, resmd, doval=doval))
Expand Down

0 comments on commit 7d7f76e

Please sign in to comment.