ucd-library / aggie-experts

Publicly reported feedback and issues for Aggie Experts
https://ucd-library.github.io/aggie-experts/
MIT License
1 stars 2 forks source link

Develop MIV APIs #339

Open qjhart opened 8 months ago

qjhart commented 8 months ago

Reviewing the rc.experts log file, MIV seems to still use the sparql query match from the last query. This uses three parameters, cas,since,until. The query flattens the data into a more concise summary.

Comparison

Using the query on cas=quinn, here is an grant returned.

     {
       "@graph" : [ {
         "@id" : "grant:102424",
         "cas" : "quinn",
         "end_date" : "2015-04-30",
         "null:grant_amount" : 783000,
         "role_label" : [ "ucdrp:GrantCoPrincipalInvestigatorRole", "vivo:CoPrincipalInvestigatorRole" ],
         "sponsor_id" : "NNX11AF93G",
         "sponsor_name" : "NASA/MISCELLANEOUS CENTERS",
         "start_date" : "2011-05-01",
         "title" : "NEAR REAL TIME SCIENCE PROCESSING ALGORITHM FOR LIVE FUEL MOISTURE CONTENT FOR THE MODIS DIRECT READOUT SYSTEM",
         "type" : "C"
       }, {
         "@id" : "grant:102424﷑c484218383a7dba823b38fbc6b1c9bcc",
         "casId" : "fzustin",
         "name" : "USTIN, SUSAN L",
         "role" : "PI"
       }, {
         "@id" : "grant:102424﷑d4e91bb0663b0bff910bee7be520a039",
         "casId" : "sashak",
         "name" : "KOLTUNOV, ALEXANDER",
         "role" : "COPI"
       }
]}

We have created and API endpoint that approximates this format. The endpoint is: /api/miv/grants?userId={id}&since=[date]&until=[date]. where userId is IAM's standard variable for cas. The equivalent grant is:

"@graph":[
{
"@id": "ark:/87287/d7gt0q/grant/K382939-102424",
"title": "NEAR REAL TIME SCIENCE PROCESSING ALGORITHM FOR LIVE FUEL MOISTURE CONTENT FOR THE MODIS DIRECT READOUT SYSTEM",
"end_date": "2015-04-30",
"start_date": "2011-05-01",
"grant_amount": "783000",
"sponsor_id": "NNX11AF93G",
"sponsor_name": "NASA/MISCELLANEOUS CENTERS",
"type": [
"Grant",
"Grant_Research"
],
"role_label": [
"GrantRole",
"CoPrincipalInvestigatorRole"
]
},
{
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_role_586b332a4702f921115e6560a936b4b5",
"name": "KOLTUNOV, ALEXANDER",
"role": "CoPrincipalInvestigatorRole"
},
{
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_role_b66911c899cd3447cee58cf14392df0a",
"name": "HART, QUINN J",
"role": "CoPrincipalInvestigatorRole"
},
{
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_role_572cba88db679c9931b4efcbde6e686d",
"name": "USTIN, SUSAN L",
"role": "CoPrincipalInvestigatorRole"
},
{
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#pi_role",
"name": "USTIN, SUSAN L",
"role": "PrincipalInvestigatorRole"
}
]

Issues

There are the following differences that need to be addressed:

Identifier

Because there are now two source for grants (kfs for archive, enterprise for current) we have two diffferent identifiers. We used arks: to differentiate them, but you can see the last part is the original kfs number, so we can replicate the grant:number for the old ones, and decide on what to do for the new ones.

Also, active grants (~6K) we're moved to the Aggie Enterprise, and in our system, we removed those from the kfs, and they have a new identifier

type

Aggie Enterprise didn't transfer the single character grant type. Here is a table of the KFS, AE and combined grant types:

Type (KFS) Label (KFS) Type (AE) Combined_Label
A INSTRUCTION 40-Instruction Grant_Instruction
C RESEARCH 44-Research Grant_Research
F SERVICE/OTHER 62-Public Service/Other Grant_Service
G ACADEMIC SUPPORT 43-Academic Support Grant_AcademicSupport
H STUDENT SERVICES 68-Student Services Grant_StudentService
S SCHOLARSHIPS 78-Student Financial Aid Grant_Scholarship
X DEFAULT Grant_Default
Capital Projects Grant_CapitalProject
45-Research (AES) Grant_Research

Need some guidance on what MIV would like to see.

CoPIs

The PI is represented as both a PI, and a CO-PI. This is because we know the PI designation at UCD, but we don't know if the sponsor has a different PI, or Co-Pis for the grant.

In addition, the Co-PIs don't have their associated cas ids, because we try to include all, regardless of their affiliation.

Authorization

In addition to the backend change, we have standardized the library's auth[z] mechanism. Currently, there is a long living jwt token that MIV uses to authenticate. In the new system. MIV will have a service account with a never expiring password, and that service account will get a token to use for calling the MIV api. This token will be relatively short lived (1 hr). We anticipate MIV getting a token for every request. Here's an example:

token=$(httpie  https://sandbox.experts.library.ucdavis.edu/auth/keycloak-oidc/service-account/token Content-type:application/json <<< "{\"username\":\"miv\",\"secret\":\"${secret}\"}" | jq -r .access_token)
httpie  https://sandbox.experts.library.ucdavis.edu/api/miv/grants userId==quinn Authorization:"Bearer ${token}"
qjhart commented 7 months ago

This data is all available in the expert's complete API record, but it is more verbose:

{
"assignedBy": {
"@type": "FundingOrganization",
"name": "NASA/MISCELLANEOUS CENTERS",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#funder"
},
"dateTimeInterval": {
"start": {
"dateTime": "2011-05-01",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#start_date",
"dateTimePrecision": "vivo:yearMonthDayPrecision"
},
"end": {
"dateTime": "2015-04-30",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#end_date",
"dateTimePrecision": "vivo:yearMonthDayPrecision"
},
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#interval"
},
"@type": [
"Grant",
"Grant_Research"
],
"name": "NEAR REAL TIME SCIENCE PROCESSING ALGORITHM FOR LIVE FUEL MOISTURE CONTENT FOR THE MODIS DIRECT READOUT SYSTEM",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424",
"relatedBy": [
{
"relates": [
{
"@type": "vivo:Person",
"name": "KOLTUNOV, ALEXANDER",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_586b332a4702f921115e6560a936b4b5"
},
"ark:/87287/d7gt0q/grant/K382939-102424"
],
"@type": "CoPrincipalInvestigatorRole",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_role_586b332a4702f921115e6560a936b4b5"
},
{
"relates": [
{
"@type": "vivo:Person",
"name": "HART, QUINN J",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_b66911c899cd3447cee58cf14392df0a"
},
"ark:/87287/d7gt0q/grant/K382939-102424"
],
"@type": "CoPrincipalInvestigatorRole",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_role_b66911c899cd3447cee58cf14392df0a"
},
{
"relates": [
{
"@type": "vivo:Person",
"name": "USTIN, SUSAN L",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_572cba88db679c9931b4efcbde6e686d"
},
"ark:/87287/d7gt0q/grant/K382939-102424"
],
"@type": "CoPrincipalInvestigatorRole",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#co_pi_role_572cba88db679c9931b4efcbde6e686d"
},
{
"inheres_in": "expert/66356b7eec24c51f01e757af2b27ebb8",
"relates": [
"ark:/87287/d7gt0q/grant/K382939-102424",
"expert/66356b7eec24c51f01e757af2b27ebb8"
],
"@type": [
"GrantRole",
"CoPrincipalInvestigatorRole"
],
"@id": "ark:/87287/d7mh2m/relationship/13749424",
"is-visible": true
},
{
"relates": [
{
"@type": "vivo:Person",
"name": "USTIN, SUSAN L",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#pi"
},
"ark:/87287/d7gt0q/grant/K382939-102424"
],
"@type": "PrincipalInvestigatorRole",
"@id": "ark:/87287/d7gt0q/grant/K382939-102424#pi_role"
}
],
"sponsorAwardId": "NNX11AF93G"
}
qjhart commented 7 months ago

I added another endpoint example, https://sandbox.experts.library.ucdavis.edu/api/miv/raw_grants?userId=quinn This allows searching on the date, but responds with a matching list of the grants, but unmodified from how they are in the standard document. If you are familiar with jq you can pretty much create the current record from the raw with:

http https://sandbox.experts.library.ucdavis.edu/api/miv/raw_grants?userId=quinn Authorization:"Bearer $jwt" |\
 jq '.[] | {"@id","title":.name,"end_date":.dateTimeInterval.end.dateTime,"start_date":.dateTimeInterval.start.dateTime,"grant_amount":.totalAwardAmount,"sponsor_id":.sponsorAwardId,"sponsor_name":.assignedBy.name,"type":.["@type"],"role_label":(.relatedBy[] | select(.inheres_in) | .["@type"])}'