Skip to content

Commit

Permalink
Fix for GitHub Issue 158
Browse files Browse the repository at this point in the history
  • Loading branch information
juileetikekar committed Mar 6, 2024
1 parent 551486c commit 31cbd43
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/AasxCsharpLibrary/AdminShellPackageEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,8 @@ public void TemporarilySaveCloseAndReOpenPackage(
{
_openPackage = Package.Open(Filename, FileMode.OpenOrCreate);

} }
}
}
}

private int BackupIndex = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/AasxCsharpLibrary/Extensions/ExtendBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public static Blob ConvertFromV10(this Blob blob, AasxCompatibilityModels.AdminS
public static Blob ConvertFromV20(this Blob blob, AasxCompatibilityModels.AdminShellV20.Blob sourceBlob)
{
blob.ContentType = sourceBlob.mimeType;
blob.Value = Encoding.ASCII.GetBytes(sourceBlob.value);
if (!string.IsNullOrEmpty(sourceBlob.value))
{
blob.Value = Encoding.ASCII.GetBytes(sourceBlob.value);
}
return blob;
}

Expand Down
16 changes: 11 additions & 5 deletions src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,19 @@ public static ConceptDescription ConvertFromV20(

if (srcCD.IsCaseOf != null && srcCD.IsCaseOf.Count != 0)
{
if (cd.IsCaseOf == null)
{
cd.IsCaseOf = new List<IReference>();
}
foreach (var caseOf in srcCD.IsCaseOf)
{
cd.IsCaseOf.Add(ExtensionsUtil.ConvertReferenceFromV20(caseOf, ReferenceTypes.ModelReference));
IReference newCaseOf = null;
if(caseOf != null && !caseOf.IsEmpty)
{
newCaseOf = ExtensionsUtil.ConvertReferenceFromV20(caseOf, ReferenceTypes.ModelReference);
}

if(newCaseOf != null)
{
cd.IsCaseOf ??= new List<IReference>();
cd.IsCaseOf.Add(newCaseOf);
}
}
}

Expand Down
43 changes: 25 additions & 18 deletions src/AasxCsharpLibrary/Extensions/ExtendEmbeddedDataSpecification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,38 @@ public static EmbeddedDataSpecification ConvertFromV20(this EmbeddedDataSpecific
{
if (sourceEmbeddedSpec != null)
{
embeddedDataSpecification.DataSpecification = ExtensionsUtil.ConvertReferenceFromV20(sourceEmbeddedSpec.dataSpecification, ReferenceTypes.ExternalReference);
if (sourceEmbeddedSpec.dataSpecification != null)
{
embeddedDataSpecification.DataSpecification = ExtensionsUtil.ConvertReferenceFromV20(sourceEmbeddedSpec.dataSpecification, ReferenceTypes.ExternalReference);

// TODO (MIHO, 2022-19-12): check again, see questions
var oldid = new[] {
// TODO (MIHO, 2022-19-12): check again, see questions
var oldid = new[] {
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/2/0",
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360",
"www.admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360"
};
var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0";
};
var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0";

// map all "usable" old ids to new one ..
foreach (var oi in oldid)
if (sourceEmbeddedSpec.dataSpecification?.Matches("", false, "IRI", oi,
AasxCompatibilityModels.AdminShellV20.Key.MatchMode.Identification) == true)
{
embeddedDataSpecification.DataSpecification.Keys[0].Value = newid;
}
}
// map all "usable" old ids to new one ..
foreach (var oi in oldid)
if (sourceEmbeddedSpec.dataSpecification?.Matches("", false, "IRI", oi,
AasxCompatibilityModels.AdminShellV20.Key.MatchMode.Identification) == true)
{
embeddedDataSpecification.DataSpecification.Keys[0].Value = newid;
}
}

if (sourceEmbeddedSpec.dataSpecificationContent?.dataSpecificationIEC61360 != null)
{
embeddedDataSpecification.DataSpecificationContent =
new DataSpecificationIec61360(null).ConvertFromV20(
sourceEmbeddedSpec.dataSpecificationContent.dataSpecificationIEC61360);
if (sourceEmbeddedSpec.dataSpecificationContent != null)
{
if (sourceEmbeddedSpec.dataSpecificationContent?.dataSpecificationIEC61360 != null)
{
embeddedDataSpecification.DataSpecificationContent =
new DataSpecificationIec61360(null).ConvertFromV20(
sourceEmbeddedSpec.dataSpecificationContent.dataSpecificationIEC61360);
}
}
}

return embeddedDataSpecification;
}

Expand Down
17 changes: 8 additions & 9 deletions src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,15 @@ private static void BasicConversionFromV20(this ISubmodelElement submodelElement

if (sourceSubmodelElement.hasDataSpecification != null && sourceSubmodelElement.hasDataSpecification.Count > 0)
{
//TODO (jtikekar, 0000-00-00): EmbeddedDataSpecification?? (as per old implementation)
submodelElement.EmbeddedDataSpecifications ??= new List<IEmbeddedDataSpecification>();

//TODO (jtikekar, 0000-00-00): DataSpecificationContent?? (as per old implementation)
foreach (var sourceDataSpec in sourceSubmodelElement.hasDataSpecification)
foreach (var sourceEmbeddedDataSpec in sourceSubmodelElement.hasDataSpecification)
{
submodelElement.EmbeddedDataSpecifications.Add(
new EmbeddedDataSpecification(
ExtensionsUtil.ConvertReferenceFromV20(sourceDataSpec.dataSpecification, ReferenceTypes.ExternalReference),
null));
var newEmbeddedDataSpec = new EmbeddedDataSpecification (null, null);
newEmbeddedDataSpec.ConvertFromV20(sourceEmbeddedDataSpec);
if(newEmbeddedDataSpec.DataSpecification != null || newEmbeddedDataSpec.DataSpecificationContent != null)
{
submodelElement.EmbeddedDataSpecifications ??= new List<IEmbeddedDataSpecification>();
submodelElement.EmbeddedDataSpecifications.Add(newEmbeddedDataSpec);
}
}
}

Expand Down

0 comments on commit 31cbd43

Please sign in to comment.