Skip to content

Commit 2973b44

Browse files
committed
Implemented new Harmony Core customizations for improved relation validation.
1 parent fcc8454 commit 2973b44

8 files changed

+412
-6
lines changed

HarmonyCoreExtensions/CustomRelationSpec.dbl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,19 @@
4040
;;
4141
;;*****************************************************************************
4242

43+
import Newtonsoft.Json
44+
import Newtonsoft.Json.Converters
45+
4346
namespace HarmonyCoreExtensions
4447

48+
public enum RelationValidationMode
49+
Unspecified
50+
None
51+
ValuePresent
52+
Always
53+
CustomCode
54+
endenum
55+
4556
public class CustomRelationSpec
4657

4758
;;; <summary>
@@ -70,10 +81,18 @@ namespace HarmonyCoreExtensions
7081
public readwrite property RelationName, string
7182

7283
;;; <summary>
73-
;;; If data is present in the FromKey, is a match to a record REQUIRED in "ToStructure"
84+
;;; DEPRECATED
85+
;;; If data is present in the FromKey, is a match to a record REQUIRED in "ToStructure".
86+
;;; If present and true, and ValidationMode is not present, ValidationMode will be set to "Always"
7487
;;; </summary>
7588
public readwrite property RequiresMatch, boolean
7689

90+
{JsonConverter(^typeof(StringEnumConverter))}
91+
;;; <summary>
92+
;;; What type of validation should be performed for this relation?
93+
;;; </summary>
94+
public readwrite property ValidationMode, RelationValidationMode
95+
7796
;;; <summary>
7897
;;; The encoded lookup for the back relation if one is present
7998
;;; </summary>
@@ -83,6 +102,12 @@ namespace HarmonyCoreExtensions
83102
;;; The relation type, A, B, C, D, E
84103
;;; </summary>
85104
public readwrite property RelationType, string
105+
106+
;;; <summary>
107+
;;; The name of a custom relation validator.
108+
;;; </summary>
109+
public readwrite property CustomValidatorName, string
110+
86111
endclass
87112

88113
endnamespace

HarmonyCoreExtensions/HarmonyCoreExtensions.synproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@
8888
<Compile Include="ParameterBridgeType.dbl" />
8989
<Compile Include="Properties\AssemblyInfo.dbl" />
9090
<Compile Include="RelationName.dbl" />
91-
<Compile Include="RequiresMatch.dbl" />
91+
<Compile Include="RelationRequiresMatch.dbl" />
9292
<Compile Include="ReturnValueBridgeType.dbl" />
9393
<Compile Include="SegmentHasCustomDataType.dbl" />
9494
<Compile Include="ToMany.dbl" />
9595
<Compile Include="ToOne.dbl" />
96+
<Compile Include="RelationValidationAlways.dbl" />
97+
<Compile Include="RelationValidationCustomCode.dbl" />
98+
<Compile Include="RelationValidationNone.dbl" />
99+
<Compile Include="RelationValidationValuePresent.dbl" />
96100
</ItemGroup>
97101
<ItemGroup>
98102
<Folder Include="Properties" />

HarmonyCoreExtensions/Helpers.dbl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace HarmonyCoreExtensions
7979
foreach customRelation in customRelationSpecs
8080
begin
8181
data relationLookup = string.Format("{0}-{1}-{2}-{3}", customRelation.FromStructure, customRelation.ToStructure, customRelation.FromKey, customRelation.ToKey)
82-
data madeRelation = MakeRelation(customRelation.FromStructure, customRelation.ToStructure, customRelation.FromKey, customRelation.ToKey, customRelation.RequiresMatch)
82+
data madeRelation = MakeRelation(customRelation.FromStructure, customRelation.ToStructure, customRelation.FromKey, customRelation.ToKey, customRelation.RequiresMatch, customRelation.ValidationMode)
8383

8484
if(!string.IsNullOrWhitespace(customRelation.BackRelation))
8585
madeRelation.BackRelation = customRelation.BackRelation
@@ -149,7 +149,7 @@ namespace HarmonyCoreExtensions
149149
required in fromKey, @string
150150
required in toKey, @string
151151
proc
152-
mreturn MakeRelation(fromStructure,toStructure,fromKey,toKey,true)
152+
mreturn MakeRelation(fromStructure,toStructure,fromKey,toKey,false,RelationValidationMode.None)
153153
endmethod
154154

155155
;;; <summary>
@@ -167,6 +167,7 @@ namespace HarmonyCoreExtensions
167167
required in fromKey, @string
168168
required in toKey, @string
169169
required in aRequiresMatch, boolean
170+
required in aValidationMode, RelationValidationMode
170171
proc
171172
data fromRealStructure = Context.Structures.FirstOrDefault(lambda(str) { str.Name == fromStructure })
172173
if (fromRealStructure == ^null)
@@ -198,6 +199,7 @@ namespace HarmonyCoreExtensions
198199
madeRelation.FromStructure = fromStructure
199200
madeRelation.ToStructure = toStructure
200201
madeRelation.RequiresMatch = aRequiresMatch
202+
madeRelation.ValidationMode = aValidationMode
201203
SynthesizeRelationInfo(fromRealStructure, toRealStructure, realFromKey, realToKey, madeRelation)
202204
mreturn madeRelation
203205
endmethod
@@ -407,6 +409,29 @@ namespace HarmonyCoreExtensions
407409
mreturn targetRelation.RequiresMatch
408410
endmethod
409411

412+
;;; <summary>
413+
;;; What is the ValidationMode of the relation?
414+
;;; </summary>
415+
;;; <param name="context"></param>
416+
;;; <param name="fromStructure"></param>
417+
;;; <param name="fromkey"></param>
418+
;;; <param name="tostr"></param>
419+
;;; <param name="tokey"></param>
420+
;;; <returns>True if matching data is required</returns>
421+
public static method ValidationMode, RelationValidationMode
422+
required in context, @CodeGenContext
423+
required in fromStructure, @RpsStructure
424+
required in fromkey, @RpsKey
425+
required in tostr, @RpsStructure
426+
required in tokey, @RpsKey
427+
proc
428+
data targetRelation = GetRelationSpec(context, fromStructure, toStr, fromkey, tokey, false)
429+
;;Figure out a default based on the value of the DEPRECATED property RequiresMatch
430+
data notPresentDefault, RelationValidationMode, targetRelation.RequiresMatch ? RelationValidationMode.Always : RelationValidationMode.None
431+
;;Return the value. If not specified, use the default based on RequiresMatch.
432+
mreturn targetRelation.ValidationMode != RelationValidationMode.Unspecified ? targetRelation.ValidationMode : notPresentDefault
433+
endmethod
434+
410435
endclass
411436

412437
endnamespace

HarmonyCoreExtensions/RequiresMatch.dbl renamed to HarmonyCoreExtensions/RelationRequiresMatch.dbl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;*****************************************************************************
22
;;
3-
;; Title: RequiresMatch.dbl
3+
;; Title: RelationRequiresMatch.dbl
44
;;
55
;; Type: Class
66
;;
@@ -47,7 +47,7 @@ import CodeGen.RepositoryAPI
4747

4848
namespace HarmonyCoreExtensions
4949

50-
public class RequiresMatch implements IExpressionToken
50+
public class RelationRequiresMatch implements IExpressionToken
5151

5252
public property TokenName, String
5353
method get
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
;;*****************************************************************************
2+
;;
3+
;; Title: RelationValidationAlways.dbl
4+
;;
5+
;; Type: Class
6+
;;
7+
;; Description: A custom relation loop expression token for use with Harmony Core
8+
;;
9+
;; Date: 27th April 2020
10+
;;
11+
;; Author: Steve Ives, Synergex Professional Services Group
12+
;; http://www.synergex.com
13+
;;
14+
;;*****************************************************************************
15+
;;
16+
;; Copyright (c) 2020, Synergex International, Inc.
17+
;; All rights reserved.
18+
;;
19+
;; Redistribution and use in source and binary forms, with or without
20+
;; modification, are permitted provided that the following conditions are met:
21+
;;
22+
;; * Redistributions of source code must retain the above copyright notice,
23+
;; this list of conditions and the following disclaimer.
24+
;;
25+
;; * Redistributions in binary form must reproduce the above copyright notice,
26+
;; this list of conditions and the following disclaimer in the documentation
27+
;; and/or other materials provided with the distribution.
28+
;;
29+
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30+
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31+
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32+
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
33+
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34+
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35+
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36+
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37+
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38+
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39+
;; POSSIBILITY OF SUCH DAMAGE.
40+
;;
41+
;;*****************************************************************************
42+
43+
import System
44+
import System.Collections.Generic
45+
import CodeGen.Engine
46+
import CodeGen.RepositoryAPI
47+
48+
namespace HarmonyCoreExtensions
49+
50+
public class RelationValidationAlways implements IExpressionToken
51+
52+
public property TokenName, String
53+
method get
54+
proc
55+
mreturn "VALIDATION_ALWAYS"
56+
endmethod
57+
endproperty
58+
59+
public property Description, String
60+
method get
61+
proc
62+
mreturn "Determines if the 'ValidationMode' of a relationship is set to 'Always' in the customization file."
63+
endmethod
64+
endproperty
65+
66+
public property Validity, TokenValidity
67+
method get
68+
proc
69+
mreturn TokenValidity.RelationLoop
70+
endmethod
71+
endproperty
72+
73+
public method Evaluate, boolean
74+
tkn, @Token
75+
template, @FileNode
76+
loops, @IEnumerable<LoopNode>
77+
proc
78+
lambda doEvaluate(context, fromStructure, relation, index, fromkey, tostr, tokey)
79+
begin
80+
data result, boolean, Helpers.ValidationMode(context,fromStructure,fromkey,tostr,tokey) == RelationValidationMode.Always
81+
mreturn result
82+
end
83+
mreturn ExpressionEvaluator.EvaluateRelationLoopExpression(tkn, template, loops, doEvaluate)
84+
endmethod
85+
86+
endclass
87+
88+
endnamespace
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
;;*****************************************************************************
2+
;;
3+
;; Title: RelationValidationCustomCode.dbl
4+
;;
5+
;; Type: Class
6+
;;
7+
;; Description: A custom relation loop expression token for use with Harmony Core
8+
;;
9+
;; Date: 27th April 2020
10+
;;
11+
;; Author: Steve Ives, Synergex Professional Services Group
12+
;; http://www.synergex.com
13+
;;
14+
;;*****************************************************************************
15+
;;
16+
;; Copyright (c) 2020, Synergex International, Inc.
17+
;; All rights reserved.
18+
;;
19+
;; Redistribution and use in source and binary forms, with or without
20+
;; modification, are permitted provided that the following conditions are met:
21+
;;
22+
;; * Redistributions of source code must retain the above copyright notice,
23+
;; this list of conditions and the following disclaimer.
24+
;;
25+
;; * Redistributions in binary form must reproduce the above copyright notice,
26+
;; this list of conditions and the following disclaimer in the documentation
27+
;; and/or other materials provided with the distribution.
28+
;;
29+
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30+
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31+
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32+
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
33+
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34+
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35+
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36+
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37+
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38+
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39+
;; POSSIBILITY OF SUCH DAMAGE.
40+
;;
41+
;;*****************************************************************************
42+
43+
import System
44+
import System.Collections.Generic
45+
import CodeGen.Engine
46+
import CodeGen.RepositoryAPI
47+
48+
namespace HarmonyCoreExtensions
49+
50+
public class RelationValidationCustomCode implements IExpressionToken
51+
52+
public property TokenName, String
53+
method get
54+
proc
55+
mreturn "VALIDATION_CUSTOM_CODE"
56+
endmethod
57+
endproperty
58+
59+
public property Description, String
60+
method get
61+
proc
62+
mreturn "Determines if the 'ValidationMode' of a relationship is set to 'CustomCode' in the customization file."
63+
endmethod
64+
endproperty
65+
66+
public property Validity, TokenValidity
67+
method get
68+
proc
69+
mreturn TokenValidity.RelationLoop
70+
endmethod
71+
endproperty
72+
73+
public method Evaluate, boolean
74+
tkn, @Token
75+
template, @FileNode
76+
loops, @IEnumerable<LoopNode>
77+
proc
78+
lambda doEvaluate(context, fromStructure, relation, index, fromkey, tostr, tokey)
79+
begin
80+
data result, boolean, Helpers.ValidationMode(context,fromStructure,fromkey,tostr,tokey) == RelationValidationMode.CustomCode
81+
mreturn result
82+
end
83+
mreturn ExpressionEvaluator.EvaluateRelationLoopExpression(tkn, template, loops, doEvaluate)
84+
endmethod
85+
86+
endclass
87+
88+
endnamespace

0 commit comments

Comments
 (0)