Skip to content

Commit

Permalink
Fix for positional identifier strings
Browse files Browse the repository at this point in the history
This fix solves #14

The commit also improves documentation and includes name
refactoring of internal methods.
  • Loading branch information
CBenghi committed Oct 7, 2023
1 parent 49ea244 commit ce816ee
Show file tree
Hide file tree
Showing 43 changed files with 348 additions and 72 deletions.
11 changes: 11 additions & 0 deletions comp.WinMerge
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<paths>
<left>..\\IDS\Documentation\testcases\</left>
<right>..\\IfcOpenShell\src\ifctester\test\build\testcases\</right>
<filter>.ids;.ifc</filter>
<subfolders>1</subfolders>
<left-readonly>0</left-readonly>
<right-readonly>0</right-readonly>
</paths>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NodeIdentification class

Provides a way to identify the element of the xml with line/poistion or relative index inside the IDS
Provides a way to identify the element of the xml with line/poistion or relative index inside the IDS Instances of this class are passed as a parameter in the ILogger calls, and by default it presents the location by line and number. A custom implementation of ILogger allows you to cast the received state parameter to IReadOnlyList&lt;KeyValuePair&lt;string, object&gt;&gt; and receive instances of NodeIdentification as parameters, to access the precise identifier.

```csharp
public class NodeIdentification : IFormattable
Expand Down
2 changes: 1 addition & 1 deletion ids-lib-documentation/IdsLib.IfcSchema/ClassInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ClassInfo
| [DirectAttributes](ClassInfo/DirectAttributes.md) { get; } | List of attribute names for the type |
| [FunctionalType](ClassInfo/FunctionalType.md) { get; } | Is the class |
| [MatchingConcreteClasses](ClassInfo/MatchingConcreteClasses.md) { get; } | All matching concrete classes, including self and entire subclass tree |
| [Name](ClassInfo/Name.md) { get; } | relationXmlAttributeName string |
| [Name](ClassInfo/Name.md) { get; } | Class Name as string (stored as camelcase, convert to upper for valid IDS class names) |
| [NameSpace](ClassInfo/NameSpace.md) { get; } | The namespace of the class |
| [Parent](ClassInfo/Parent.md) { get; } | Resolved parent Classinfo |
| [ParentName](ClassInfo/ParentName.md) { get; } | Parent name as string |
Expand Down
2 changes: 1 addition & 1 deletion ids-lib-documentation/IdsLib.IfcSchema/ClassInfo/Name.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ClassInfo.Name property

relationXmlAttributeName string
Class Name as string (stored as camelcase, convert to upper for valid IDS class names)

```csharp
public string Name { get; }
Expand Down
24 changes: 24 additions & 0 deletions ids-lib-documentation/IdsLib/LibraryInformation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# LibraryInformation class

General information on the assembly without reflection. This is useful for environments that do not allow to load information from the DLL dynamically (e.g. Blazor).

```csharp
public static class LibraryInformation
```

## Public Members

| name | description |
| --- | --- |
| static [AssemblyVersion](LibraryInformation/AssemblyVersion.md) { get; } | Static field with hardcoded DLL version number. |
| static [Commit](LibraryInformation/Commit.md) { get; } | Static field with the short commit hash at compilation time |
| static [CommitDate](LibraryInformation/CommitDate.md) { get; } | Static field with the full datetime string of the commit. |
| static [Isdirty](LibraryInformation/Isdirty.md) { get; } | Static field with informing of possible dirty repository on compilation. When compiled remotely it does not necessarily mean that the code differs from the commit. |
| static [Sha](LibraryInformation/Sha.md) { get; } | Static field with the full SHA hash at compilation time |

## See Also

* namespace [IdsLib](../ids-lib.md)
* [LibraryInformation.cs](https://github.com/buildingSMART/IDS-Audit-tool/tree/main/ids-lib/LibraryInformation.cs)
<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
14 changes: 14 additions & 0 deletions ids-lib-documentation/IdsLib/LibraryInformation/AssemblyVersion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LibraryInformation.AssemblyVersion property

Static field with hardcoded DLL version number.

```csharp
public static string AssemblyVersion { get; }
```

## See Also

* class [LibraryInformation](../LibraryInformation.md)
* namespace [IdsLib](../../ids-lib.md)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
14 changes: 14 additions & 0 deletions ids-lib-documentation/IdsLib/LibraryInformation/Commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LibraryInformation.Commit property

Static field with the short commit hash at compilation time

```csharp
public static string Commit { get; }
```

## See Also

* class [LibraryInformation](../LibraryInformation.md)
* namespace [IdsLib](../../ids-lib.md)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
14 changes: 14 additions & 0 deletions ids-lib-documentation/IdsLib/LibraryInformation/CommitDate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LibraryInformation.CommitDate property

Static field with the full datetime string of the commit.

```csharp
public static string CommitDate { get; }
```

## See Also

* class [LibraryInformation](../LibraryInformation.md)
* namespace [IdsLib](../../ids-lib.md)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
14 changes: 14 additions & 0 deletions ids-lib-documentation/IdsLib/LibraryInformation/Isdirty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LibraryInformation.Isdirty property

Static field with informing of possible dirty repository on compilation. When compiled remotely it does not necessarily mean that the code differs from the commit.

```csharp
public static bool Isdirty { get; }
```

## See Also

* class [LibraryInformation](../LibraryInformation.md)
* namespace [IdsLib](../../ids-lib.md)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LibraryInformation constructor

The default constructor.

```csharp
public LibraryInformation()
```

## See Also

* class [LibraryInformation](../LibraryInformation.md)
* namespace [IdsLib](../../ids-lib.md)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
14 changes: 14 additions & 0 deletions ids-lib-documentation/IdsLib/LibraryInformation/Sha.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LibraryInformation.Sha property

Static field with the full SHA hash at compilation time

```csharp
public static string Sha { get; }
```

## See Also

* class [LibraryInformation](../LibraryInformation.md)
* namespace [IdsLib](../../ids-lib.md)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
3 changes: 2 additions & 1 deletion ids-lib-documentation/ids-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| static class [Audit](./IdsLib/Audit.md) | Main static class for invoking the audit functions. If you wish to audit a single file, the best entry point is [`Run`](./IdsLib/Audit/Run.md). This method allows you to run audits on the provided stream. For more complex auditing scenarios (e.g. those used by the tool), some automation can be achieved with [`Run`](./IdsLib/Audit/Run.md). Both APIs provide a return value that can be interpreted to determine if errors have been found. For more detailed feedback on the specific location of issues encountered, you must pass an ILogger interface, and collect events. |
| class [AuditProcessOptions](./IdsLib/AuditProcessOptions.md) | Configuration parameters required within the inner loop of the audit. |
| interface [IBatchAuditOptions](./IdsLib/IBatchAuditOptions.md) | This interface contains the parameters to configure a complex execution of the audit in a batch scenario. |
| static class [LibraryInformation](./IdsLib/LibraryInformation.md) | General information on the assembly without reflection. This is useful for environments that do not allow to load information from the DLL dynamically (e.g. Blazor). |
| class [SingleAuditOptions](./IdsLib/SingleAuditOptions.md) | Configuration parameters needed to setup the audit of a single IDS. The [`IdsVersion`](./IdsLib/SingleAuditOptions/IdsVersion.md) property is currently required to avoid the need to seek the stream, then resume the audit once the version is detected from the content. Future versions will attempt to relax this requirement. Ensure that the properties of the base class [`AuditProcessOptions`](./IdsLib/AuditProcessOptions.md) are also populated. |

## IdsLib.IdsSchema.IdsNodes namespace
Expand All @@ -17,7 +18,7 @@
| --- | --- |
| class [IdsInformation](./IdsLib.IdsSchema.IdsNodes/IdsInformation.md) | Status information of an IDS source |
| enum [IdsVersion](./IdsLib.IdsSchema.IdsNodes/IdsVersion.md) | Enumeration to identify a single IDS version. |
| class [NodeIdentification](./IdsLib.IdsSchema.IdsNodes/NodeIdentification.md) | Provides a way to identify the element of the xml with line/poistion or relative index inside the IDS |
| class [NodeIdentification](./IdsLib.IdsSchema.IdsNodes/NodeIdentification.md) | Provides a way to identify the element of the xml with line/poistion or relative index inside the IDS Instances of this class are passed as a parameter in the ILogger calls, and by default it presents the location by line and number. A custom implementation of ILogger allows you to cast the received state parameter to IReadOnlyList&lt;KeyValuePair&lt;string, object&gt;&gt; and receive instances of NodeIdentification as parameters, to access the precise identifier. |

## IdsLib.IfcSchema namespace

Expand Down
4 changes: 2 additions & 2 deletions ids-lib/AuditHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ internal void Notify(ILogger? logger, IdsSchema.IdsXmlNode newContext)
loc.StartLinePosition = Position;
loc.NodeType = newContext.type;
if (Schema == Original.SchemaError)
IdsMessages.ReportSchema306ComplianceError(logger, loc, Message);
IdsErrorMessages.ReportSchema306ComplianceError(logger, loc, Message);
else
IdsMessages.ReportSchema307ComplianceWarning(logger, Level, loc, Message);
IdsErrorMessages.ReportSchema307ComplianceWarning(logger, Level, loc, Message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ids-lib/IdsSchema/IdsNodes/Facets/IdsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
var sm = name?.GetListMatcher();
// the first child must be a valid string matcher
if (sm is null)
return IdsMessages.Report102NoStringMatcher(logger, this, "name");
return IdsErrorMessages.Report102NoStringMatcher(logger, this, "name");

Audit.Status ret = Audit.Status.Ok;
requiredSchemaVersions.TryGetSchemaInformation(out var schemas);
Expand Down
8 changes: 4 additions & 4 deletions ids-lib/IdsSchema/IdsNodes/Facets/IdsEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
// one child must be a valid string matcher
var sm = name?.GetListMatcher();
if (sm is null)
return IdsMessages.Report102NoStringMatcher(logger, this, "name");
return IdsErrorMessages.Report102NoStringMatcher(logger, this, "name");

// we introduce a schema-by-schema evaluation of the valid classes
//
Expand All @@ -65,7 +65,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)

var predefinedTypeMatcher = predefinedType.GetListMatcher();
if (predefinedTypeMatcher is null)
return IdsMessages.Report102NoStringMatcher(logger, this, "predefinedType");
return IdsErrorMessages.Report102NoStringMatcher(logger, this, "predefinedType");


List<string>? possiblePredefined = null;
Expand All @@ -74,7 +74,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
var c = schema[ifcClass];
if (c is null)
{
ret |= IdsMessages.Report501UnexpectedScenario(logger, $"class metadata for {ifcClass} not found in schema {schema.Version}.", this);
ret |= IdsErrorMessages.Report501UnexpectedScenario(logger, $"class metadata for {ifcClass} not found in schema {schema.Version}.", this);
continue;
}
if (possiblePredefined == null)
Expand All @@ -84,7 +84,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
}

if (possiblePredefined == null)
ret |= IdsMessages.Report105InvalidDataConfiguration(logger, this, "predefinedType");
ret |= IdsErrorMessages.Report105InvalidDataConfiguration(logger, this, "predefinedType");
else if (possiblePredefined.Contains("USERDEFINED")) // if a user defined option is available then any value is acceptable
return ret;
else
Expand Down
2 changes: 1 addition & 1 deletion ids-lib/IdsSchema/IdsNodes/Facets/IdsFacet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Audit.Status PerformCardinalityAudit(ILogger? logger)
var ret = Audit.Status.Ok;
if (minMaxOccurr.Audit(out var _) != Audit.Status.Ok)
{
IdsMessages.Report301InvalidCardinality(logger, this, minMaxOccurr);
IdsErrorMessages.Report301InvalidCardinality(logger, this, minMaxOccurr);
ret |= MinMaxCardinality.ErrorStatus;
IsValid = false;
}
Expand Down
12 changes: 6 additions & 6 deletions ids-lib/IdsSchema/IdsNodes/Facets/IdsPartOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
var requiredSchemaVersions = spec.SchemaVersions;
if (string.IsNullOrEmpty(relationValue))
{
ret |= IdsMessages.Report106InvalidEmtpyValue(logger, this, relationXmlAttributeName);
ret |= IdsErrorMessages.Report106InvalidEmtpyValue(logger, this, relationXmlAttributeName);
return ret;
}

Expand Down Expand Up @@ -74,7 +74,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
var relationInfo = SchemaInfo.AllPartOfRelations.FirstOrDefault(x => x.IfcName == matchedRelationName);
if (relationInfo is null)
{
ret |= IdsMessages.Report501UnexpectedScenario(logger, $"no valid relation found for {matchedRelationName}", this);
ret |= IdsErrorMessages.Report501UnexpectedScenario(logger, $"no valid relation found for {matchedRelationName}", this);
return SetInvalid(ret);
}

Expand All @@ -87,7 +87,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
var filter = new IfcInheritanceTypeConstraint(relationInfo.ManySideIfcType, schema.Version);
if (IfcTypeConstraint.IsNotNullAndEmpty(filter))
{
ret |= IdsMessages.Report501UnexpectedScenario(logger, $"no valid types found for {relationInfo.ManySideIfcType}", this);
ret |= IdsErrorMessages.Report501UnexpectedScenario(logger, $"no valid types found for {relationInfo.ManySideIfcType}", this);
return SetInvalid(ret);
}
typeFilters.Add(schema, filter);
Expand All @@ -96,15 +96,15 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
//
if (GetChildNodes("entity").FirstOrDefault() is not IIfcTypeConstraintProvider childEntity)
{
ret |= IdsMessages.Report106InvalidEmtpyValue(logger, this, "entity");
ret |= IdsErrorMessages.Report106InvalidEmtpyValue(logger, this, "entity");
return SetInvalid(ret);
}

var validChildEntityType = new IfcInheritanceTypeConstraint(relationInfo.OneSideIfcType, schema.Version);
var possible = validChildEntityType.Intersect(childEntity.GetTypesFilter(schema));
if (possible.IsEmpty)
{
ret |= IdsMessages.Report201IncompatibleClauses(logger, this, schema, "relation not compatible with provided child entity");
ret |= IdsErrorMessages.Report201IncompatibleClauses(logger, this, schema, "relation not compatible with provided child entity");
return SetInvalid(ret);
}

Expand All @@ -118,7 +118,7 @@ public Audit.Status PerformCardinalityAudit(ILogger? logger)
var ret = Audit.Status.Ok;
if (minMaxOccurr.Audit(out var _) != Audit.Status.Ok)
{
IdsMessages.Report301InvalidCardinality(logger, this, minMaxOccurr);
IdsErrorMessages.Report301InvalidCardinality(logger, this, minMaxOccurr);
ret |= MinMaxCardinality.ErrorStatus;
}
return ret;
Expand Down
18 changes: 9 additions & 9 deletions ids-lib/IdsSchema/IdsNodes/Facets/IdsProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace IdsLib.IdsSchema.IdsNodes;
internal class IdsProperty : IdsXmlNode, IIdsCardinalityFacet, IIfcTypeConstraintProvider
{
private readonly MinMaxCardinality minMaxOccurr;
private readonly IStringListMatcher? measureMatcher;
private readonly IStringListMatcher? datatypeMatcher;
public IdsProperty(System.Xml.XmlReader reader, IdsXmlNode? parent) : base(reader, parent)
{
minMaxOccurr = new MinMaxCardinality(reader);
var measure = reader.GetAttribute("datatype") ?? string.Empty;
if (!string.IsNullOrEmpty(measure))
measureMatcher = new StringListMatcher(measure, this);
datatypeMatcher = new StringListMatcher(measure, this);
else
measureMatcher = null;
datatypeMatcher = null;
}

public bool IsValid { get; private set; } = false;
Expand Down Expand Up @@ -50,12 +50,12 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
var pset = GetChildNodes("propertySet").FirstOrDefault();
var psetMatcher = pset?.GetListMatcher();
if (psetMatcher is null)
return IdsMessages.Report102NoStringMatcher(logger, this, "propertySet");
return IdsErrorMessages.Report102NoStringMatcher(logger, this, "propertySet");

var name = GetChildNodes("name").FirstOrDefault();
var nameMatcher = name?.GetListMatcher();
if (nameMatcher is null)
return IdsMessages.Report102NoStringMatcher(logger, this, "name");
return IdsErrorMessages.Report102NoStringMatcher(logger, this, "name");

// we are keeping the stricter type to ensure that it is valid across multiple schemas
// depending on the schema version of IfcRelDefinesByProperties the filter needs to be
Expand Down Expand Up @@ -111,7 +111,7 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
else if (psetMatcher is IStringPrefixMatcher ssm && ssm.MatchesPrefix("Pset_"))
{
IsValid = false;
return IdsMessages.Report401ReservedStringMatched(logger, this, "prefix 'Pset_'", "property set name");
return IdsErrorMessages.Report401ReservedStringMatched(logger, this, "prefix 'Pset_'", "property set name");
}
else
{
Expand All @@ -125,9 +125,9 @@ internal protected override Audit.Status PerformAudit(ILogger? logger)
typeFilters.Add(schema, filter);
IsValid = true;
}
if (measureMatcher is not null)
if (datatypeMatcher is not null)
{
ret |= measureMatcher.DoesMatch(validMeasureNames, false, logger, out var matches, "measure names", schema.Version);
ret |= datatypeMatcher.DoesMatch(validMeasureNames, false, logger, out var matches, "datatype", schema.Version);
}
if (ret != Audit.Status.Ok)
IsValid = false;
Expand All @@ -146,7 +146,7 @@ private Audit.Status SetInvalid()
public Audit.Status PerformCardinalityAudit(ILogger? logger)
{
if (minMaxOccurr.Audit(out var _) != Audit.Status.Ok)
return IdsMessages.Report301InvalidCardinality(logger, this, minMaxOccurr);
return IdsErrorMessages.Report301InvalidCardinality(logger, this, minMaxOccurr);
return Audit.Status.Ok;
}
}
2 changes: 1 addition & 1 deletion ids-lib/IdsSchema/IdsNodes/IdsFacetCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected internal override Audit.Status PerformAudit(ILogger? logger)
foreach (var schemaInfo in schemaInfos)
{
if (!ChildFacets.Any(x => !x.IsValid) && IfcTypeConstraint.IsNotNullAndEmpty(GetTypesFilter(schemaInfo)))
ret |= IdsMessages.Report201IncompatibleClauses(logger, this, schemaInfo, "impossible match of constraints in set");
ret |= IdsErrorMessages.Report201IncompatibleClauses(logger, this, schemaInfo, "impossible match of constraints in set");
}
}
return ret;
Expand Down
2 changes: 1 addition & 1 deletion ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected internal override void SetContent(string contentString)
public Audit.Status DoesMatch(IEnumerable<string> candidateStrings, bool ignoreCase, ILogger? logger, out IEnumerable<string> matches, string listToMatchName, IfcSchema.IfcSchemaVersions schemaContext)
{
if (!TryMatch(candidateStrings, ignoreCase, out matches))
return IdsMessages.Report103InvalidListMatcher(this, Content, logger, listToMatchName, schemaContext, candidateStrings);
return IdsErrorMessages.Report103InvalidListMatcher(this, Content, logger, listToMatchName, schemaContext, candidateStrings);
return Audit.Status.Ok;
}

Expand Down
Loading

0 comments on commit ce816ee

Please sign in to comment.