Skip to content

Commit

Permalink
fixed rm validation with complete OPT
Browse files Browse the repository at this point in the history
  • Loading branch information
ppazos committed Feb 27, 2023
1 parent ee1c399 commit 2069dd9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 1.8.21
version = 1.8.22
group = com.cabolabs
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,29 @@ class OperationalTemplate {
// attr name -> type
Map rm_attrs = rm_attributes_not_in_opt[obn.rmTypeName]

def path_sep, aom_type, atnc, obnc

rm_attrs.each { attr, type ->

// avoid if the attr is aready on the OPT
// for instance, a null_flavour could be in the OPT
if (!obn.attributes.find{ it.rmAttributeName == attr })
{
def aom_type = (type == 'String' ? 'C_PRIMITIVE_OBJECT' : 'C_COMPLEX_OBJECT')
aom_type = (type == 'String' ? 'C_PRIMITIVE_OBJECT' : 'C_COMPLEX_OBJECT')

// avoid // on root paths
def path_sep = "/"
path_sep = "/"
if (obn.path == "/") path_sep = ""

def atn = new AttributeNode(
atnc = new AttributeNode(
rmAttributeName: attr,
type: 'C_SINGLE_ATTRIBUTE',
parent: obn,
path: obn.path +path_sep+ attr,
dataPath: obn.dataPath +path_sep+ attr,
templatePath: obn.templatePath +path_sep+ attr,
templateDataPath: obn.templateDataPath +path_sep+ attr,
existence: new IntervalInt(
existence: new IntervalInt( // TODO: check the RM to see the RM existence for this attribute
upperIncluded: true,
lowerIncluded: true,
upperUnbounded: false,
Expand All @@ -291,27 +293,35 @@ class OperationalTemplate {
)
)

def obnc = new ObjectNode(
obnc = new ObjectNode(
owner: this,
rmTypeName: type,
type: aom_type,
templatePath: obn.templatePath +path_sep+ attr, // same paths as the attr since this has no nodeId
path: obn.path +path_sep+ attr,
dataPath: obn.dataPath +path_sep+ attr,
templateDataPath: obn.templateDataPath +path_sep+ attr,
parent: atn
parent: atnc,
occurrences: new IntervalInt( // TODO: check the RM to see the default RM occurrences for this object
upperIncluded: true,
lowerIncluded: true,
upperUnbounded: false,
lowerUnbounded: false,
lower: 0,
upper: 1
)
// TODO: default_values
)
obnc.text = obnc.parent.parent.text +'.'+ obnc.parent.rmAttributeName
obnc.description = obnc.parent.parent.description +'.'+ obnc.parent.rmAttributeName

atn.children << obnc
atnc.children << obnc

// supports many alternative nodes with the same path
if (!this.nodes[obnc.templatePath]) this.nodes[obnc.templatePath] = []
this.nodes[obnc.templatePath] << obnc

obn.attributes << atn
obn.attributes << atnc
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class RmValidator2 {

String template_id = rm_object.archetype_details.template_id.value

// TEST: complete, RM validation fails (fixed)
//this.opt_manager.load(template_id, namespace, true)

def opt = this.opt_manager.getOpt(template_id, namespace)

if (!opt)
Expand Down Expand Up @@ -2207,20 +2210,9 @@ class RmValidator2 {
}
else // data is null
{

if (!c_attr.existence)
{
println "attr "+ attribute_name +" existence is null???"
println o.attributes*.rmAttributeName
println c_attr.rmAttributeName
println c_attr.type
println c_attr.templatePath
println c_attr.templateDataPath
}

// existence: the only way of violating existence is with 1..1 so
// it's checked only if the value is null
if (!c_attr.existence.has(0))
if (c_attr.existence && !c_attr.existence.has(0))
{
report.addError(
object.dataPath +'/'+ attribute_name,
Expand All @@ -2234,7 +2226,11 @@ class RmValidator2 {
// because with a null value, the dataPath can't be retrieved to set it on the error report.
// With a not null value, any existence will pass and occurrences 0..0 will fail.

if (c_attr.children.size() == 1 && !c_attr.children[0].occurrences.has(0))
if (
c_attr.children.size() == 1 &&
c_attr.children[0].occurrences &&
!c_attr.children[0].occurrences.has(0)
)
{
// here we need the parent for the dataPath since the data is nul
report.addError(
Expand Down

0 comments on commit 2069dd9

Please sign in to comment.