From d5d5201898cdfe9bb365c902d6f33129a2f3e19a 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 | 23 ++++++++------- src/ROCrate/ISAProfile/Investigation.fs | 29 ++++++++++--------- src/ROCrate/ISAProfile/LabProcess.fs | 22 ++++++++++---- 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 +-- .../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 +-- .../ROCrate/ISAProfile/PropertyValue.Tests.fs | 4 +-- tests/ROCrate/ISAProfile/Sample.tests.fs | 4 +-- .../ISAProfile/ScholarlyArticle.Tests.fs | 4 +-- tests/ROCrate/ISAProfile/Study.Tests.fs | 4 +-- tests/ROCrate/ROCrateObject.Tests.fs | 4 +-- 17 files changed, 77 insertions(+), 58 deletions(-) diff --git a/src/ROCrate/ISAProfile/Assay.fs b/src/ROCrate/ISAProfile/Assay.fs index 525433ff..b1148a01 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, @@ -21,11 +21,14 @@ type Assay( do DynObj.setProperty (nameof identifier) identifier this - DynObj.setOptionalProperty (nameof measurementMethod) measurementMethod this - DynObj.setOptionalProperty (nameof measurementTechnique) measurementTechnique this - DynObj.setOptionalProperty (nameof variableMeasured) variableMeasured this - DynObj.setOptionalProperty (nameof about) about this - DynObj.setOptionalProperty (nameof comment) comment this - DynObj.setOptionalProperty (nameof creator) creator this - DynObj.setOptionalProperty (nameof hasPart) hasPart this - DynObj.setOptionalProperty (nameof url) url this \ No newline at end of file + DynObj.setValueOpt this (nameof measurementMethod) measurementMethod + DynObj.setValueOpt this (nameof measurementTechnique) measurementTechnique + DynObj.setValueOpt this (nameof variableMeasured) variableMeasured + DynObj.setValueOpt this (nameof about) about + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof creator) creator + DynObj.setValueOpt this (nameof hasPart) hasPart + 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 607170fa..ed466d03 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, @@ -24,14 +24,17 @@ type Investigation( do DynObj.setProperty (nameof identifier) identifier this - DynObj.setOptionalProperty (nameof citation) citation this - DynObj.setOptionalProperty (nameof comment) comment this - DynObj.setOptionalProperty (nameof creator) creator this - DynObj.setOptionalProperty (nameof dateCreated) dateCreated this - DynObj.setOptionalProperty (nameof dateModified) dateModified this - DynObj.setOptionalProperty (nameof datePublished) datePublished this - DynObj.setOptionalProperty (nameof hasPart) hasPart this - DynObj.setOptionalProperty (nameof headline) headline this - DynObj.setOptionalProperty (nameof mentions) mentions this - DynObj.setOptionalProperty (nameof url) url this - DynObj.setOptionalProperty (nameof description) description this + DynObj.setValueOpt this (nameof citation) citation + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof creator) creator + DynObj.setValueOpt this (nameof dateCreated) dateCreated + DynObj.setValueOpt this (nameof dateModified) dateModified + DynObj.setValueOpt this (nameof datePublished) datePublished + DynObj.setValueOpt this (nameof hasPart) hasPart + DynObj.setValueOpt this (nameof headline) headline + 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 a891ff30..168558fb 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, @@ -24,7 +24,19 @@ type LabProcess( DynObj.setProperty (nameof object) object this DynObj.setProperty (nameof result) result this - DynObj.setOptionalProperty (nameof executesLabProtocol) executesLabProtocol this - DynObj.setOptionalProperty (nameof parameterValue) parameterValue this - DynObj.setOptionalProperty (nameof endTime) endTime this - DynObj.setOptionalProperty (nameof disambiguatingDescription) disambiguatingDescription this \ No newline at end of file + DynObj.setValueOpt this (nameof executesLabProtocol) executesLabProtocol + DynObj.setValueOpt this (nameof parameterValue) parameterValue + DynObj.setValueOpt this (nameof endTime) endTime + 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 d2463da7..bf1c8f27 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.setOptionalProperty (nameof headline) headline this DynObj.setOptionalProperty (nameof url) url this + 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 9e3cb8f5..aee848d6 100644 --- a/src/ROCrate/ROCrateObject.fs +++ b/src/ROCrate/ROCrateObject.fs @@ -44,15 +44,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 6dbf61ff..181436cb 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 93280fe9..de9e0c3b 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 79a955d7..8dd691b3 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 66749a47..c45328ac 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 9774e04c..431d95ef 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 efb84eb9..89f3bd12 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 46e3fb6f..a35b0f9f 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 568e3549..feb42dd4 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 ca5083a0..9669d5d0 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 c90f2363..4f464e08 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 0d40bc43..0f73eb22 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 a0747e11..6f3dc820 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" ] )