Skip to content

Commit

Permalink
Fix missing usage of externalRepository and "AASREPOSITORY" environme…
Browse files Browse the repository at this point in the history
…nt property (eclipse-aaspe#286)

* Fix missing usage of externalRepository and "AASREPOSITORY" environment parameter

* add missing check
  • Loading branch information
Freezor authored Jun 18, 2024
1 parent e9ddf84 commit 8584df8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 49 deletions.
15 changes: 13 additions & 2 deletions src/AasxServerStandardBib/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public static bool loadPackageForSubmodel(string submodelIdentifier, out ISubmod
public static bool edit = false;
public static string externalRest = "";
public static string externalBlazor = "";
public static string externalRepository = "";
public static bool readTemp = false;
public static int saveTemp = 0;
public static DateTime saveTempDt = new DateTime();
Expand Down Expand Up @@ -396,7 +397,7 @@ private static async Task<int> Run(CommandLineArguments a)
}

// Read environment variables
string[] evlist = {"PLCNEXTTARGET", "WITHPOLICY", "SHOWWEIGHT"};
string[] evlist = {"PLCNEXTTARGET", "WITHPOLICY", "SHOWWEIGHT", "AASREPOSITORY"};
foreach (var ev in evlist)
{
string v = System.Environment.GetEnvironmentVariable(ev);
Expand Down Expand Up @@ -440,6 +441,8 @@ private static async Task<int> Run(CommandLineArguments a)
Console.WriteLine("showWeight: " + showWeight);
}

envVariables.TryGetValue("AASREPOSITORY", out externalRepository);

if (a.Connect != null)
{
if (a.Connect.Length == 0)
Expand Down Expand Up @@ -611,7 +614,15 @@ private static async Task<int> Run(CommandLineArguments a)
{
externalBlazor = "http://" + blazorHostPort;
}


externalBlazor = externalBlazor.Replace("\r", "");
externalBlazor = externalBlazor.Replace("\n", "");

if (string.IsNullOrEmpty(externalRepository))
{
externalRepository = externalBlazor;
}

Query.ExternalBlazor = externalBlazor;

/*
Expand Down
92 changes: 47 additions & 45 deletions src/IO.Swagger.Registry.Lib.V3/Services/AasRegistryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,55 @@ public AssetAdministrationShellDescriptor CreateAasDescriptorFromDB(AASSet aasDB
//string asset = aas.assetRef?[0].Value;
var globalAssetId = aasDB.GlobalAssetId;

using AasContext db = new AasContext();
// ad.Administration.Version = aas.administration.version;
// ad.Administration.Revision = aas.administration.revision;
ad.IdShort = aasDB.IdShort;
ad.Id = aasDB.Identifier;
var e = new Models.Endpoint();
e.ProtocolInformation = new ProtocolInformation();
e.ProtocolInformation.Href =
AasxServer.Program.externalBlazor + "/shells/" +
Base64UrlEncoder.Encode(ad.Id);
_logger.LogDebug("AAS " + ad.IdShort + " " + e.ProtocolInformation.Href);
e.Interface = "AAS-1.0";
ad.Endpoints = new List<Endpoint>
{
e
};
ad.GlobalAssetId = globalAssetId;
//
ad.SpecificAssetIds = new List<SpecificAssetId>();
var specificAssetId = new SpecificAssetId("AssetKind", aasDB.AssetKind, externalSubjectId: new Reference(ReferenceTypes.ExternalReference, new List<IKey>() { new Key(KeyTypes.GlobalReference, "assetKind") }));
ad.SpecificAssetIds.Add(specificAssetId);

// Submodels
var submodelDBList = db.SMSets.Where(s => s.AASId == aasDB.Id);
if (submodelDBList.Any())
using (AasContext db = new AasContext())
{
ad.SubmodelDescriptors = new List<SubmodelDescriptor>();
foreach (var submodelDB in submodelDBList)
// ad.Administration.Version = aas.administration.version;
// ad.Administration.Revision = aas.administration.revision;
ad.IdShort = aasDB.IdShort;
ad.Id = aasDB.Identifier;
var e = new Models.Endpoint();
e.ProtocolInformation = new ProtocolInformation();
e.ProtocolInformation.Href =
AasxServer.Program.externalRepository + "/shells/" +
Base64UrlEncoder.Encode(ad.Id);
_logger.LogDebug("AAS " + ad.IdShort + " " + e.ProtocolInformation.Href);
e.Interface = "AAS-1.0";
ad.Endpoints = new List<Models.Endpoint>
{
e
};
ad.GlobalAssetId = globalAssetId;
//
ad.SpecificAssetIds = new List<SpecificAssetId>();
var specificAssetId = new SpecificAssetId("AssetKind", aasDB.AssetKind, externalSubjectId: new Reference(ReferenceTypes.ExternalReference, new List<IKey>() { new Key(KeyTypes.GlobalReference, "assetKind") }));
ad.SpecificAssetIds.Add(specificAssetId);

// Submodels
var submodelDBList = db.SMSets.Where(s => s.AASId == aasDB.Id);
if (submodelDBList.Any())
{
SubmodelDescriptor sd = new SubmodelDescriptor();
sd.IdShort = submodelDB.IdShort;
sd.Id = submodelDB.Identifier;
var esm = new Models.Endpoint();
esm.ProtocolInformation = new ProtocolInformation();
esm.ProtocolInformation.Href =
AasxServer.Program.externalBlazor + "/shells/" +
Base64UrlEncoder.Encode(ad.Id) + "/submodels/" +
Base64UrlEncoder.Encode(sd.Id);
// Base64UrlEncoder.Encode(sd.Identification) + "/submodel/";
// Console.WriteLine("SM " + sd.IdShort + " " + esm.ProtocolInformation.EndpointAddress);
esm.Interface = "SUBMODEL-1.0";
sd.Endpoints = new List<Models.Endpoint>
{
esm
};
sd.SemanticId = new Reference(ReferenceTypes.ExternalReference, new List<IKey>() { new Key(KeyTypes.GlobalReference, submodelDB.SemanticId) });
ad.SubmodelDescriptors.Add(sd);
ad.SubmodelDescriptors = new List<SubmodelDescriptor>();
foreach (var submodelDB in submodelDBList)
{
SubmodelDescriptor sd = new SubmodelDescriptor();
sd.IdShort = submodelDB.IdShort;
sd.Id = submodelDB.Identifier;
var esm = new Models.Endpoint();
esm.ProtocolInformation = new ProtocolInformation();
esm.ProtocolInformation.Href =
AasxServer.Program.externalRepository + "/shells/" +
Base64UrlEncoder.Encode(ad.Id) + "/submodels/" +
Base64UrlEncoder.Encode(sd.Id);
// Base64UrlEncoder.Encode(sd.Identification) + "/submodel/";
// Console.WriteLine("SM " + sd.IdShort + " " + esm.ProtocolInformation.EndpointAddress);
esm.Interface = "SUBMODEL-1.0";
sd.Endpoints = new List<Models.Endpoint>
{
esm
};
sd.SemanticId = new Reference(ReferenceTypes.ExternalReference, new List<IKey>() { new Key(KeyTypes.GlobalReference, submodelDB.SemanticId) });
ad.SubmodelDescriptors.Add(sd);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ static void AddAasToRegistry(AdminShellNS.AdminShellPackageEnv env, DateTime tim
var e = new Endpoint();
e.ProtocolInformation = new ProtocolInformation();
e.ProtocolInformation.Href =
Program.externalRest + "/shells/" +
Program.externalRepository + "/shells/" +
Base64UrlEncoder.Encode(ad.Id);
Console.WriteLine("AAS " + ad.IdShort + " " + e.ProtocolInformation.Href);
e.Interface = "AAS-1.0";
Expand All @@ -714,7 +714,7 @@ static void AddAasToRegistry(AdminShellNS.AdminShellPackageEnv env, DateTime tim
var esm = new Models.Endpoint();
esm.ProtocolInformation = new ProtocolInformation();
esm.ProtocolInformation.Href =
AasxServer.Program.externalRest + "/shells/" +
AasxServer.Program.externalRepository + "/shells/" +
Base64UrlEncoder.Encode(ad.Id) + "/submodels/" +
Base64UrlEncoder.Encode(sd.Id);
// Console.WriteLine("SM " + sd.IdShort + " " + esm.ProtocolInformation.EndpointAddress);
Expand Down

0 comments on commit 8584df8

Please sign in to comment.