PID Assignment
As an SMS user, I want to assign PIDs to platforms and devices. If an instance is already created, based on Update Device access rules - I would like to have a button or similar UI element to click to request a PID creation to the backend. In the frontend, I get a feedback that a PID has been created and the handle is displayed in the PID field. Updating and deleting PIDs does not need to be done in the frontend - that is done automatically by the backend.
ToDo's / Acceptance:
-
To be compatible with the PIDINST specification, the manufacturer must be a mandatory field from now on, even if no PID will be created. -
a new button/check-box has been added to device&platforms edit mode tab basic data-PID field | freetext editing is no more possible - The button/check-box is only active/editable if the entitiy does not already have a PID
- If visibility private is selected then it should not be possible to create a PID (checkbox is disabled, hint "PIDs are not available for private visibility")
- A hint text with the information ("Informations about the entity including the full name and email of the owner is stored at PID-service outside the SMS")
-
if the device/platform is new created two requests to SMS backend have to be triggerd, first create the entity than tigger the PID-(ID&Type)-Endpoint. -
if the device/platform is been updated two requests to SMS backend have to be triggerd, first update the entity than tigger the PID-(ID&Type)-Endpoint. -
Handle the SMS-Backend-PID response - a view refresh hast to be triggered - showing the PID-Handle (Link the PID-Handle to the full URL of PID-Service and PID-Handle, so the user is able to review the stored information of entitie) - clicking on the link should be opened in a new tab.
-
clicking on the PID copies the PID-URL to the clipboard. A tooltip provides feedback to the user. - example: the following is old and can be ingored, just keep it in history for GFZ solution
~~We want to assign PIDs for our platforms & devices.
For this we got code that @haxter uses for assigning the PIDs in GIPP:
##
# authors: Gerard Munoz and Martin Haxter
# description: script to generate PIDs. It gets the instrument inforamtion from gipp website via json request.
##
import requests
import json
import uuid
from pyhandle.handleclient import PyHandleClient
from pyhandle.clientcredentials import PIDClientCredentials
import datetime
# Gerhard: I disable warning, because python is complaining about https connections, I disable verification and warning.
# Since I trust the gipp websites, I can do this safely.
# Martin's comment: I fixed the certifiacates off the https connections.
import warnings
warnings.filterwarnings("ignore")
#Function to add the generated PIDs to a log file
def AddToLog(logFile,arg1,arg2):
with open(logFile,'a+') as log:
timestamp = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
log.write('{0:s};{1:s};{2:s}\n'.format(arg1,arg2,timestamp))
#Initalize the pyhandle client (check the location and content of the certificate!!!!)
cred = PIDClientCredentials.load_from_JSON('./certificate.json')
client = PyHandleClient('rest').instantiate_with_credentials(cred)
#If necessary change the location of the log!!
logPath = './logs'
logFile = logPath+'/PID.log'
#Generate the log file if it does not exist (if it does, just open and close it, so do nothing)
open(logFile,'a+').close()
#For looping throug the device types
#Assign a type for the PID entry based on the SQL-database type
typeDict = {
"Trillium 120PA" : "3-component broad band seismometer",
"Trillium 120QA" : "3-component broad band seismometer",
"3Komponenten, 4,5Hz" : "3-component geophone",
"Trillium Compact" : "3-component broad band seismometer",
"CMG-3ESPC" : "3-component intermediate band seismometer",
"CMG-40T" : "3-component intermediate band seismometer",
"CMG-3ESPD" : "3-component broad band seismometer",
"CMG-3T" : "3-component broad band seismometer",
"3CH-1Hz" : "3-component geophone",
"Earth Data PR6-24" : "3-channel data recorder",
"Earth Data EDR-210" : "3-channel data recorder",
"Omnirecs/DIGOS Cube1" : "1-channel data recorder",
"Omnirecs/DIGOS Cube 3 int" : "3-channel data recorder",
"Omnirecs/DIGOS Cube 3 ext" : "3-channel data recorder"
}
#For content negotiation set header to return JSON
headers = {'Accept': 'application/json'}
#Find all the devices of that type
url = 'https://gipp.gfz-potsdam.de/instruments/index?limit=10000'
#Read the content of the database for the device in json format
response = requests.get(url,headers=headers)
items = json.loads(response.content) #Load the json content
#Inner loop for all devices of the type
for item in items:
code = item['Instrument']['code']
#Check whether the instrument already has a PID assigned in the database
if not (item['Instrument']['pid']):
instrumentBaseUrl = 'https://gipp.gfz-potsdam.de/instruments/code/{:s}'.format(code) #Form the landing page url
type = typeDict[item['Instrumentcategory']['name']] #Translate the type from the database to the PID values
keywords = {
'location' : instrumentBaseUrl,
'identifierType' : 'instrument',
'Manufacturer' : item['Instrumentcategory']['manufacturer'],
'Name' : item['Instrumentcategory']['name'],
'InstrumentType' : type,
'VariableMeasured' : 'data logger',
'Code' : code,
'Status' : 'OK'
}
#Create the PID handle
handle = str(uuid.uuid4()).upper()
prefix = '11708' # GFZ prefix of the handle consortium
handle = '{0:s}/{1:s}'.format(prefix,handle)
with open(logFile,'r+') as log:
allLines = list(log) #Read the csv file as a list
matchLine = next((s for s in allLines if code in s), None) #Check if the code matches any of the lines (list elements)
if matchLine:
PIDLog = matchLine.split(";")[0]
print('Instrument',code,'already has a PID (from log file):',PIDLog)
else:
print('Creating PID for instrument',code,':',handle)
AddToLog(logFile,handle,code)
record = client.register_handle(handle=handle,overwrite=True,**keywords)
else:
print( 'Instrument ',code,' already has a PID: ',item['Instrument']['pid'])
From my current point of view it would make sense to provide this as a service itself - so that others programs also on GFZ (and maybe also on UFZ) can use this service to register PIDs.~~