Skip to content

Commit

Permalink
Fix bugs w.r.t., Path and submodel service
Browse files Browse the repository at this point in the history
  • Loading branch information
juileetikekar committed Oct 31, 2024
1 parent 0e3bacc commit a5bc270
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 166 deletions.
2 changes: 1 addition & 1 deletion src/AasxServerStandardBib/Interfaces/ISubmodelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ISubmodelService
void DeleteSubmodelById(string submodelIdentifier);
void DeleteSubmodelElementByPath(string submodelIdentifier, string idShortPath);
List<ISubmodelElement> GetAllSubmodelElements(string submodelIdentifier);
List<ISubmodel> GetAllSubmodels();
List<ISubmodel> GetAllSubmodels(IReference reqSemanticId = null, string idShort = null);
string GetFileByPath(string submodelIdentifier, string idShortPath, out byte[] byteArray, out long fileSize);
ISubmodel GetSubmodelById(string submodelIdentifier);
ISubmodelElement GetSubmodelElementByPath(string submodelIdentifier, string idShortPath);
Expand Down
32 changes: 31 additions & 1 deletion src/AasxServerStandardBib/Services/SubmodelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
using AasxServerStandardBib.Interfaces;
using AasxServerStandardBib.Logging;
using AasxServerStandardBib.Transformers;
using AdminShellNS.Extensions;
using Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

Expand Down Expand Up @@ -488,7 +490,35 @@ public void ReplaceSubmodelElementByPath(string submodelIdentifier, string idSho
}
}

public List<ISubmodel> GetAllSubmodels() => _packageEnvService.GetAllSubmodels();
public List<ISubmodel> GetAllSubmodels(IReference reqSemanticId = null, string idShort = null)
{
var output = _packageEnvService.GetAllSubmodels();

if(!output.IsNullOrEmpty())
{
if (!string.IsNullOrEmpty(idShort))
{
_logger.LogDebug($"Filtering Submodels with idShort {idShort}.");
output = output.Where(s => s.IdShort.Equals(idShort)).ToList();
if (output.IsNullOrEmpty())
{
_logger.LogInformation($"No Submodels with idShort {idShort} found.");
}
}

if(reqSemanticId != null)
{
_logger.LogDebug($"Filtering Submodels with requested Semnatic Id.");
output = output.Where(s => s.SemanticId != null && s.SemanticId.Matches(reqSemanticId)).ToList();
if (output.IsNullOrEmpty())
{
_logger.LogInformation($"No Submodels with requested semanticId found.");
}
}
}

return output;
}

public ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void GetDescription_ShouldReturn200WithServiceDescription()
var mockServiceDescription = new Mock<IServiceDescription>();
var expectedServiceDescription = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.AasxFileServerServiceSpecificationSSP001,
ServiceDescription.ServiceProfiles.SubmodelRepositoryServiceSpecificationSSP001,
Expand Down
24 changes: 12 additions & 12 deletions src/IO.Swagger.Lib.V3.Tests/Models/ServiceDescriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void ToString_ShouldReturnFormattedString()
// Arrange
var serviceDescription = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
}
Expand All @@ -45,7 +45,7 @@ public void ToJson_ShouldReturnIndentedJsonString()
// Arrange
var serviceDescription = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
}
Expand All @@ -66,7 +66,7 @@ public void Equals_WithSameObject_ShouldReturnTrue()
// Arrange
var serviceDescription = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
}
Expand All @@ -88,8 +88,8 @@ public void Equals_WithEqualObject_ShouldReturnTrue()
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
};

var serviceDescription1 = new ServiceDescription { Profiles = profiles };
var serviceDescription2 = new ServiceDescription { Profiles = profiles };
var serviceDescription1 = new ServiceDescription { profiles = profiles };
var serviceDescription2 = new ServiceDescription { profiles = profiles };

// Act
var result = serviceDescription1.Equals(serviceDescription2);
Expand All @@ -104,15 +104,15 @@ public void Equals_WithDifferentObject_ShouldReturnFalse()
// Arrange
var serviceDescription1 = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
}
};

var serviceDescription2 = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.AssetAdministrationShellRepositoryServiceSpecificationSSP001
}
Expand All @@ -134,7 +134,7 @@ public void GetHashCode_ShouldReturnCorrectHashCode()
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
};

var serviceDescription = new ServiceDescription { Profiles = profiles };
var serviceDescription = new ServiceDescription { profiles = profiles };
var expectedHashCode = 41;
expectedHashCode = (expectedHashCode * 59) + profiles.GetHashCode();

Expand All @@ -154,8 +154,8 @@ public void OperatorEquals_WithEqualObjects_ShouldReturnTrue()
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
};

var serviceDescription1 = new ServiceDescription { Profiles = profiles };
var serviceDescription2 = new ServiceDescription { Profiles = profiles };
var serviceDescription1 = new ServiceDescription { profiles = profiles };
var serviceDescription2 = new ServiceDescription { profiles = profiles };

// Act
var result = serviceDescription1 == serviceDescription2;
Expand All @@ -170,15 +170,15 @@ public void OperatorNotEquals_WithDifferentObjects_ShouldReturnTrue()
// Arrange
var serviceDescription1 = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.DiscoveryServiceSpecificationSSP001
}
};

var serviceDescription2 = new ServiceDescription
{
Profiles = new List<ServiceDescription.ServiceProfiles>
profiles = new List<ServiceDescription.ServiceProfiles>
{
ServiceDescription.ServiceProfiles.SubmodelServiceSpecificationSSP002
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void GenerateSerializationByIds_ShouldReturnEmptyEnvironment_WhenNoIdsPro
{
// Arrange
_mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny<List<ISpecificAssetId>?>(), It.IsAny<string?>())).Returns([]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny<IReference?>(), It.IsAny<string?>())).Returns([]);

// Act
var result = _service.GenerateSerializationByIds();
Expand All @@ -80,7 +80,7 @@ public void GenerateSerializationByIds_ShouldFetchAASs_WhenAasIdsProvided()
mockAas.SetupGet(x => x.Id).Returns(aasId);

_mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny<List<ISpecificAssetId>?>(), It.IsAny<string?>())).Returns([mockAas.Object]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny<IReference?>(), It.IsAny<string?>())).Returns([]);

// Act
var result = _service.GenerateSerializationByIds(new List<string> {aasId});
Expand All @@ -99,7 +99,7 @@ public void GenerateSerializationByIds_ShouldFetchSubmodels_WhenSubmodelIdsProvi
mockSubmodel.SetupGet(x => x.Id).Returns(submodelId);

_mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny<List<ISpecificAssetId>?>(), It.IsAny<string?>())).Returns([]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([mockSubmodel.Object]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny<IReference?>(), It.IsAny<string?>())).Returns([mockSubmodel.Object]);

// Act
var result = _service.GenerateSerializationByIds(null, new List<string> {submodelId});
Expand All @@ -123,7 +123,7 @@ public void GenerateSerializationByIds_ShouldFetchAASsAndSubmodels_WhenBothIdsPr
mockSubmodel.SetupGet(x => x.Id).Returns(submodelId);

_mockAasService.Setup(x => x.GetAllAssetAdministrationShells(It.IsAny<List<ISpecificAssetId>?>(), It.IsAny<string?>())).Returns([mockAas.Object]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels()).Returns([mockSubmodel.Object]);
_mockSubmodelService.Setup(x => x.GetAllSubmodels(It.IsAny<IReference?>(), It.IsAny<string?>())).Returns([mockSubmodel.Object]);

// Act
var result = _service.GenerateSerializationByIds(new List<string> {aasId}, new List<string> {submodelId});
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Swagger.Lib.V3/Controllers/DescriptionAPIApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class DescriptionAPIApiController : ControllerBase
public virtual IActionResult GetDescription()
{
var output = new ServiceDescription();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
output
is useless, since its value is never read.
_serviceDescription.Profiles = new List<ServiceProfiles>
_serviceDescription.profiles = new List<ServiceProfiles>
{
ServiceProfiles.AasxFileServerServiceSpecificationSSP001,
ServiceProfiles.SubmodelRepositoryServiceSpecificationSSP001,
Expand Down
10 changes: 1 addition & 9 deletions src/IO.Swagger.Lib.V3/Controllers/SerializationAPIApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,7 @@ public SerializationAPIApiController(IAppLogger<SerializationAPIApiController> l
public virtual IActionResult GenerateSerializationByIds([FromQuery] List<string>? aasIds, [FromQuery] List<string>? submodelIds,
[FromQuery] bool? includeConceptDescriptions)
{
if (aasIds == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(aasIds)} is null");
}

if (submodelIds == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(submodelIds)} is null");
}
_logger.LogDebug($"Received a request an appropriate serialization");

var decodedAasIds = aasIds.Select(aasId => _decoderService.Decode("aasIdentifier", aasId)).ToList();

Expand Down
Loading

0 comments on commit a5bc270

Please sign in to comment.