From 7d1e733fb14f3abf23c4065174390d7a57131e03 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 6 Sep 2024 17:09:11 +0200 Subject: [PATCH] #433: Add api functions for mandatory dynamic props on some classes --- src/ROCrate/ISAProfile/Assay.fs | 9 ++++++--- src/ROCrate/ISAProfile/Investigation.fs | 7 +++++-- src/ROCrate/ISAProfile/LabProcess.fs | 16 ++++++++++++++-- src/ROCrate/ISAProfile/Study.fs | 6 ++++-- src/ROCrate/ROCrateObject.fs | 7 +++---- tests/ROCrate/ISAProfile/Assay.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/Data.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/Dataset.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/Investigation.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/LabProcess.tests.fs | 4 ++-- tests/ROCrate/ISAProfile/LabProtocol.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/Person.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/PropertyValue.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/Sample.tests.fs | 4 ++-- .../ROCrate/ISAProfile/ScholarlyArticle.Tests.fs | 4 ++-- tests/ROCrate/ISAProfile/Study.Tests.fs | 4 ++-- tests/ROCrate/ROCrateObject.Tests.fs | 4 ++-- 17 files changed, 56 insertions(+), 37 deletions(-) diff --git a/src/ROCrate/ISAProfile/Assay.fs b/src/ROCrate/ISAProfile/Assay.fs index 152c9403..d8811556 100644 --- a/src/ROCrate/ISAProfile/Assay.fs +++ b/src/ROCrate/ISAProfile/Assay.fs @@ -6,8 +6,8 @@ open Fable.Core /// [] type Assay( - id, - identifier, + id: string, + identifier: string, ?about, ?comment, ?creator, @@ -28,4 +28,7 @@ type Assay( DynObj.setValueOpt this (nameof comment) comment DynObj.setValueOpt this (nameof creator) creator DynObj.setValueOpt this (nameof hasPart) hasPart - DynObj.setValueOpt this (nameof url) url \ No newline at end of file + DynObj.setValueOpt this (nameof url) url + + member this.GetIdentifier() = DynObj.tryGetTypedValue (nameof identifier) this |> Option.get + static member getIdentifier = fun (ass: Assay) -> ass.GetIdentifier() \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Investigation.fs b/src/ROCrate/ISAProfile/Investigation.fs index 2498807c..6185e741 100644 --- a/src/ROCrate/ISAProfile/Investigation.fs +++ b/src/ROCrate/ISAProfile/Investigation.fs @@ -6,8 +6,8 @@ open Fable.Core /// [] type Investigation( - id, - identifier, + id: string, + identifier: string, ?citation, ?comment, ?creator, @@ -35,3 +35,6 @@ type Investigation( DynObj.setValueOpt this (nameof mentions) mentions DynObj.setValueOpt this (nameof url) url DynObj.setValueOpt this (nameof description) description + + member this.GetIdentifier() = DynObj.tryGetTypedValue (nameof identifier) this |> Option.get + static member getIdentifier = fun (inv: Investigation) -> inv.GetIdentifier() \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/LabProcess.fs b/src/ROCrate/ISAProfile/LabProcess.fs index a92bb6b9..d3d0d517 100644 --- a/src/ROCrate/ISAProfile/LabProcess.fs +++ b/src/ROCrate/ISAProfile/LabProcess.fs @@ -6,7 +6,7 @@ open Fable.Core /// [] type LabProcess( - id, + id: string, name, agent, object, @@ -27,4 +27,16 @@ type LabProcess( DynObj.setValueOpt this (nameof executesLabProtocol) executesLabProtocol DynObj.setValueOpt this (nameof parameterValue) parameterValue DynObj.setValueOpt this (nameof endTime) endTime - DynObj.setValueOpt this (nameof disambiguatingDescription) disambiguatingDescription \ No newline at end of file + DynObj.setValueOpt this (nameof disambiguatingDescription) disambiguatingDescription + + member this.GetName() = DynObj.tryGetValue this (nameof name) |> Option.get + static member getName = fun (lp: LabProcess) -> lp.GetName() + + member this.GetAgent() = DynObj.tryGetTypedValue (nameof agent) this |> Option.get + static member getAgent = fun (lp: LabProcess) -> lp.GetAgent() + + member this.GetObject() = DynObj.tryGetTypedValue (nameof object) this |> Option.get + static member getObject = fun (lp: LabProcess) -> lp.GetObject() + + member this.GetResult() = DynObj.tryGetTypedValue (nameof result) this |> Option.get + static member getResult = fun (lp: LabProcess) -> lp.GetResult() diff --git a/src/ROCrate/ISAProfile/Study.fs b/src/ROCrate/ISAProfile/Study.fs index e8007004..44b61b59 100644 --- a/src/ROCrate/ISAProfile/Study.fs +++ b/src/ROCrate/ISAProfile/Study.fs @@ -6,8 +6,8 @@ open Fable.Core /// [] type Study( - id, - identifier, + id: string, + identifier: string, ?about, ?citation, ?comment, @@ -36,3 +36,5 @@ type Study( DynObj.setValueOpt this (nameof headline) headline DynObj.setValueOpt this (nameof url) url + member this.GetIdentifier() = DynObj.tryGetTypedValue (nameof identifier) this |> Option.get + static member getIdentifier = fun (inv: Investigation) -> inv.GetIdentifier() diff --git a/src/ROCrate/ROCrateObject.fs b/src/ROCrate/ROCrateObject.fs index 6f1acc95..d07d7285 100644 --- a/src/ROCrate/ROCrateObject.fs +++ b/src/ROCrate/ROCrateObject.fs @@ -42,15 +42,14 @@ type ROCrateObject(id:string, schemaType: string, ?additionalType) = member this.SetContext (context: #DynamicObj) = this.SetValue("@context", context) - static member setContext (context: #DynamicObj) = - fun (roc: #ROCrateObject) -> roc.SetContext(context) + static member setContext (context: #DynamicObj) = fun (roc: #ROCrateObject) -> roc.SetContext(context) member this.TryGetContext() = DynObj.tryGetTypedValue("@context") this - static member tryGetContext (roc: #ROCrateObject) = roc.TryGetContext() + static member tryGetContext () = fun (roc: #ROCrateObject) -> roc.TryGetContext() member this.RemoveContext() = this.Remove("@context") - static member removeContext (roc: #ROCrateObject) = roc.RemoveContext() \ No newline at end of file + static member removeContext () = fun (roc: #ROCrateObject) -> roc.RemoveContext() \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Assay.Tests.fs b/tests/ROCrate/ISAProfile/Assay.Tests.fs index 717b6f72..4c9002e6 100644 --- a/tests/ROCrate/ISAProfile/Assay.Tests.fs +++ b/tests/ROCrate/ISAProfile/Assay.Tests.fs @@ -92,10 +92,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/Data.Tests.fs b/tests/ROCrate/ISAProfile/Data.Tests.fs index ad8f058e..17c5ce9e 100644 --- a/tests/ROCrate/ISAProfile/Data.Tests.fs +++ b/tests/ROCrate/ISAProfile/Data.Tests.fs @@ -82,10 +82,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/Dataset.Tests.fs b/tests/ROCrate/ISAProfile/Dataset.Tests.fs index 0bd1a513..16b5e96d 100644 --- a/tests/ROCrate/ISAProfile/Dataset.Tests.fs +++ b/tests/ROCrate/ISAProfile/Dataset.Tests.fs @@ -66,10 +66,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/Investigation.Tests.fs b/tests/ROCrate/ISAProfile/Investigation.Tests.fs index 68a09d4c..b0941d8f 100644 --- a/tests/ROCrate/ISAProfile/Investigation.Tests.fs +++ b/tests/ROCrate/ISAProfile/Investigation.Tests.fs @@ -98,10 +98,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/LabProcess.tests.fs b/tests/ROCrate/ISAProfile/LabProcess.tests.fs index e68b2410..03ce19cc 100644 --- a/tests/ROCrate/ISAProfile/LabProcess.tests.fs +++ b/tests/ROCrate/ISAProfile/LabProcess.tests.fs @@ -97,10 +97,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs b/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs index 2829c9e4..5d03a32f 100644 --- a/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs +++ b/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs @@ -90,10 +90,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/Person.Tests.fs b/tests/ROCrate/ISAProfile/Person.Tests.fs index 28c16389..b9e22ee9 100644 --- a/tests/ROCrate/ISAProfile/Person.Tests.fs +++ b/tests/ROCrate/ISAProfile/Person.Tests.fs @@ -96,10 +96,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs b/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs index bbed3900..70f240ff 100644 --- a/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs +++ b/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs @@ -88,10 +88,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/Sample.tests.fs b/tests/ROCrate/ISAProfile/Sample.tests.fs index ad62735e..f050bd27 100644 --- a/tests/ROCrate/ISAProfile/Sample.tests.fs +++ b/tests/ROCrate/ISAProfile/Sample.tests.fs @@ -80,10 +80,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs b/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs index 5c8e6bdd..2a32eac2 100644 --- a/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs +++ b/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs @@ -88,10 +88,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ISAProfile/Study.Tests.fs b/tests/ROCrate/ISAProfile/Study.Tests.fs index a2e8515e..8f0b55e5 100644 --- a/tests/ROCrate/ISAProfile/Study.Tests.fs +++ b/tests/ROCrate/ISAProfile/Study.Tests.fs @@ -98,10 +98,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] ) diff --git a/tests/ROCrate/ROCrateObject.Tests.fs b/tests/ROCrate/ROCrateObject.Tests.fs index b85e8514..dd30c8db 100644 --- a/tests/ROCrate/ROCrateObject.Tests.fs +++ b/tests/ROCrate/ROCrateObject.Tests.fs @@ -66,10 +66,10 @@ let tests_static_methods = testSequenced ( ROCrateObject.setContext context mandatory_properties Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties testCase "can get context" <| fun _ -> - let ctx = ROCrateObject.tryGetContext mandatory_properties + let ctx = ROCrateObject.tryGetContext() mandatory_properties Expect.equal ctx (Some context) "context was not set correctly" testCase "can remove context" <| fun _ -> - ROCrateObject.removeContext mandatory_properties + ROCrateObject.removeContext() mandatory_properties Expect.isNone (DynObj.tryGetTypedValue "@context" mandatory_properties) "context was not removed correctly" ] )