-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from DiSSCo/PrefillAnnotationClassesWithValues
Prefill annotation classes with values
- Loading branch information
Showing
13 changed files
with
233 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* Import Dependencies */ | ||
import KeycloakService from "app/Keycloak"; | ||
|
||
/* Import Utilities */ | ||
import { FormatFieldNameFromJsonPath } from "./AnnotateUtilities"; | ||
|
||
|
||
/* Utilities associated with a class annotation */ | ||
|
||
|
||
/** | ||
* Function to check for class default values and if present, return them | ||
* @param jsonPath The JSON path of the class to check | ||
* @returns Prefilled data array or object depending on provided class | ||
*/ | ||
const CheckForClassDefaultValues = (jsonPath: string) => { | ||
const className: string = FormatFieldNameFromJsonPath(jsonPath.replaceAll(/\[(\d+)\]/g, '')).split('_').slice(-1)[0].replace('$', '').replaceAll("'", ''); | ||
|
||
switch (className) { | ||
case 'ods:hasAgents': { | ||
return ClassAgents(); | ||
} | ||
case 'ods:hasGeoreference': { | ||
return ClassGeoreference(); | ||
} | ||
case 'ods:hasIdentifiers': { | ||
return ClassIdentifiers(jsonPath); | ||
} | ||
case 'ods:hasRoles': { | ||
return ClassRoles(); | ||
} | ||
}; | ||
}; | ||
|
||
/** | ||
* Function to create a prefilled agent values object | ||
* @returns Prefilled agents values array | ||
*/ | ||
const ClassAgents = () => { | ||
/* Construct agent values object */ | ||
const classValues = { | ||
"@id": KeycloakService.GetParsedToken()?.orcid, | ||
"@type": 'schema:Person', | ||
"schema:identifier": KeycloakService.GetParsedToken()?.orcid, | ||
"schema:name": `${KeycloakService.GetParsedToken()?.given_name ?? ''} ${KeycloakService.GetParsedToken()?.family_name ?? ''}` | ||
}; | ||
|
||
return classValues; | ||
}; | ||
|
||
/** | ||
* Function to create a prefilled role values object | ||
* @returns Prefilled georeferene values object | ||
*/ | ||
const ClassGeoreference = () => { | ||
/* Construct role values object */ | ||
const classValues = { | ||
"@type": 'ods:Georeference' | ||
}; | ||
|
||
return classValues; | ||
}; | ||
|
||
/** | ||
* Function to create a prefilled role values object | ||
* @returns Prefilled identifiers values array | ||
*/ | ||
const ClassIdentifiers = (jsonPath: string) => { | ||
/* Extract parent class name from JSON path */ | ||
const parentClassName: string = FormatFieldNameFromJsonPath(jsonPath.replaceAll(/\[(\d+)\]/g, '')).split('_').slice(-2)[0].replace('$', '').replaceAll("'", ''); | ||
|
||
/* Set parent specific values */ | ||
const dctermsIdentifier: string = parentClassName === 'ods:hasAgents' ? KeycloakService.GetParsedToken()?.orcid : ''; | ||
|
||
/* Construct identifier values object */ | ||
const classValues = { | ||
"@type": '', | ||
"dcterms:title": '', | ||
"dcterms:identifier": dctermsIdentifier | ||
}; | ||
|
||
return classValues; | ||
}; | ||
|
||
/** | ||
* Function to create a prefilled role values object | ||
* @returns Prefilled roles values array | ||
*/ | ||
const ClassRoles = () => { | ||
/* Construct role values object */ | ||
const classValues = { | ||
"@type": '', | ||
"schema:roleName": '' | ||
}; | ||
|
||
return classValues; | ||
}; | ||
|
||
export { | ||
CheckForClassDefaultValues | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.