def process(): response.headers["Content-Type"] = "application/json" package_id = request.params.get('package_id') hasAccess(package_id) if hasAppliedDoi(package_id): return {'error':True, 'message':'Cannot edit resource of package with applied DOI'} sheet_id = request.params.get('sheet_id') resource_id = request.params.get('resource_id') ids = request.params.get('resource_ids') if sheet_id == "": sheet_id = None try: options = json.loads(request.params.get('options')) except: options = {} # option, if a resource id and a datasheet id are passed, then the full 'merged' view will be return # only allow specified options safeOptions = {} for option in parseOptions: if option in options: safeOptions[option] = options[option] # see if we are editing multiple files or just one result = [] if ids is not None: ids = json.loads(ids) for resource_id in ids: workspace.prepareFile(package_id, resource_id, sheet_id, safeOptions) result.append(query.getResource(resource_id)) else: workspace.prepareFile(package_id, resource_id, sheet_id, safeOptions) result = query.getResource(resource_id, sheet_id) # update the dataset, so the metadata timestamp changes context = {'model': model, 'user': c.user} pkg = logic.get_action('package_show')(context, {'id': package_id}) # use this counter to poke the dataset. This will update the last modified timestamps # required for 'updated since last pushed UI' resourceUpdateCount = utils.getPackageExtra('resourceUpdateCount', pkg) if resourceUpdateCount is None: resourceUpdateCount = 1 else: resourceUpdateCount = int(resourceUpdateCount) + 1 utils.setPackageExtra('resourceUpdateCount', resourceUpdateCount, pkg) pkg = logic.get_action('package_update')(context, pkg) result = { 'metadata_modified' : pkg.get('metadata_modified'), 'result' : result } return jsonStringify(result)
def setCitation(pkg): citation = [] title = pkg.get('title') authors = pkg.get('author') year = getPackageExtra('Year', pkg) doi = getPackageExtra('EcoSIS DOI', pkg) if doi is None or doi == '': doi = getPackageExtra('Citation DOI', pkg) if authors is not None: authors = authors.split(',') authors = map(unicode.strip, authors) if len(authors) == 1: citation.append(authors[0]) elif len(authors) == 2: citation.append(' and '.join(authors)) elif len(authors) > 2: last = authors.pop() citation.append('%s and %s' % (', '.join(authors), last)) if year is not None: citation.append(year) if title is not None: citation.append(title) citation.append('Data set. Available on-line [http://ecosis.org] from the Ecosystem Spectral Information System (EcoSIS)') if doi is not None: citation.append(doi) citation = '. '.join(citation) setPackageExtra('Citation', citation, pkg)
def handleDoiUpdate(currentPackage, newPackage): oldDoi = getDoiStatus(currentPackage) newDoi = getDoiStatus(newPackage) # No changes if oldDoi.get('status').get('value') == newDoi.get('status').get('value') and oldDoi.get('status').get('error') != True: if oldDoi.get('value') == newDoi.get('value'): # check this package doesn't have a DOI # Perhaps just not let them make it private? # if not canUpdate(oldDoi): # return { # 'error': True, # 'message' : 'You cannot update a package once the DOI as been applied' # } # else: return {'success': True} # the one thing a USER can do is request approval if oldDoi.get('status').get('value') in (None, DOI_STATUS['PENDING_REVISION']): if newDoi.get('status').get('value') == DOI_STATUS['PENDING_APPROVAL'] and newDoi.get('value') is None: # set the requesting user status = { 'value' : DOI_STATUS['PENDING_APPROVAL'], 'requested_by' : c.user } setPackageExtra('EcoSIS DOI Status', json.dumps(status), newPackage) # alert the admins of the request sendAdminNotification(newPackage) return {'success': True} # user is canceling request if newDoi.get('status').get('value') is None: setPackageExtra('EcoSIS DOI Status', '{}', newPackage) return {'success': True} if not isAdmin(): return { 'error' : True, 'message' : 'You do not have access to update DOI values' } resp = {} if newDoi.get('status').get('value') == DOI_STATUS['PENDING_REVISION'] and oldDoi.get('status').get('value') != DOI_STATUS['PENDING_REVISION']: resp = sendUserNotification(newPackage, False) elif newDoi.get('status').get('value') == DOI_STATUS['ACCEPTED'] and oldDoi.get('status').get('value') != DOI_STATUS['ACCEPTED']: resp = sendUserNotification(newPackage, True) resp['success'] = True return resp
def clearDoi(): response.headers["Content-Type"] = "application/json" if not isAdmin(): return { 'error' : True, 'message' : 'Nope.' } id = request.params.get('id') context = {'model': model, 'user': c.user} pkg = logic.get_action('package_show')(context, {'id': id}) # check EcoSIS DOI status setPackageExtra('EcoSIS DOI Status', '{}', pkg) setPackageExtra('EcoSIS DOI', '', pkg) pkg = logic.get_action('package_update')(context, pkg) return json.dumps({'success': True})
def applyDoi(pkg): # get the current package DOI status doiStatus = getDoiStatus(pkg) # make sure it's set to accepted if doiStatus.get('status').get('value') != DOI_STATUS["ACCEPTED"]: return # set the new status to REQUESTING DOI setPackageExtra('EcoSIS DOI Status', json.dumps({'value':DOI_STATUS["REQUESTING"]}), pkg) # update the dataset context = {'model': model, 'user': c.user} logic.get_action('package_update')(context, pkg) # Request DOI from EZID doiResponse = requestDoi(pkg) # If request failed, reset DOI status, return new error if doiResponse.get('status') != 'success': status = { 'value': DOI_STATUS["ACCEPTED"], 'error' : True, 'message': 'Failed to request DOI from service', 'serverResponseStatus' : doiResponse.get('status') } setPackageExtra('EcoSIS DOI Status', json.dumps(status), pkg) logic.get_action('package_update')(context, pkg) return status # set the returned DOI ARK and new DOI Status status = { 'value' : DOI_STATUS["APPLIED"], 'ark' : doiResponse.get('ark'), 'applied' : datetime.datetime.utcnow().isoformat() } setPackageExtra('EcoSIS DOI Status', json.dumps(status), pkg) setPackageExtra('EcoSIS DOI', doiResponse.get('doi'), pkg) # now that it's applied, re-push to search so updates are visible push = Push() push.run(pkg) # final dataset update with new DOI status logic.get_action('package_update')(context, pkg) return {'success': True}