Skip to content

Commit f6e7900

Browse files
Merge pull request PHOENIXCONTACT#190 from PHOENIXCONTACT/feature/add-exception-from-extension
Add exception from Moryx.Asp.Extensions to Products and Resources endpoints
2 parents 0c28487 + 4e89c24 commit f6e7900

12 files changed

+64
-24
lines changed

AbstractionLayer.sln

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StartProject.Asp", "src\Sta
5353
EndProject
5454
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moryx.AbstractionLayer.Resources.Endpoints", "src\Moryx.AbstractionLayer.Resources.Endpoints\Moryx.AbstractionLayer.Resources.Endpoints.csproj", "{F5141A5C-D29F-4870-85D5-277C04A944EC}"
5555
EndProject
56+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C65808F9-A467-455B-8732-01214C1ECA69}"
57+
ProjectSection(SolutionItems) = preProject
58+
.gitignore = .gitignore
59+
Build.ps1 = Build.ps1
60+
Directory.build.props = Directory.build.props
61+
Directory.Build.targets = Directory.Build.targets
62+
NuGet.Config = NuGet.Config
63+
README.md = README.md
64+
VERSION = VERSION
65+
EndProjectSection
66+
EndProject
5667
Global
5768
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5869
Debug|Any CPU = Debug|Any CPU

Directory.Build.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33

44
<PropertyGroup>
5-
<MoryxCoreVersion>3.4.0</MoryxCoreVersion>
5+
<MoryxCoreVersion>3.7.1-dev.576</MoryxCoreVersion>
66
<MoryxClientFrameworkVersion>3.2.0</MoryxClientFrameworkVersion>
77
<MoryxMaintenanceWebVersion>3.1.1</MoryxMaintenanceWebVersion>
88
</PropertyGroup>

NuGet.Config

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageRestore>
44
<!-- Allow NuGet to download missing packages -->
@@ -12,5 +12,5 @@
1212
<clear />
1313
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
1414
<add key="MORYX" value="https://www.myget.org/F/moryx/api/v3/index.json" />
15-
</packageSources>
15+
</packageSources>
1616
</configuration>

src/Moryx.AbstractionLayer.Products.Endpoints/Moryx.AbstractionLayer.Products.Endpoints.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="5.0.0" />
2828
</ItemGroup>
2929

30+
<ItemGroup>
31+
<PackageReference Include="Moryx.Asp.Extensions" />
32+
</ItemGroup>
33+
3034
<ItemGroup>
3135
<ProjectReference Include="..\Moryx.AbstractionLayer\Moryx.AbstractionLayer.csproj" />
3236
</ItemGroup>

src/Moryx.AbstractionLayer.Products.Endpoints/ProductManagementController.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
using Moryx.Serialization;
1414
using System.Net;
1515
using Moryx.AbstractionLayer.Properties;
16+
using Moryx.Asp.Extensions.Exception;
1617
using Moryx.Configuration;
17-
1818
namespace Moryx.AbstractionLayer.Products.Endpoints
1919
{
2020
/// <summary>
@@ -110,7 +110,7 @@ public ActionResult<long> SaveType(ProductModel newTypeModel)
110110
var type = ReflectionTool.GetPublicClasses<ProductType>(t => t.Name == newTypeModel.Type)
111111
.FirstOrDefault();
112112
if (type == null)
113-
return NotFound(Strings.TYPE_NOT_FOUND);
113+
return NotFound(new MoryxExceptionResponse { Title = Strings.TYPE_NOT_FOUND });
114114
var productType = (ProductType)Activator.CreateInstance(type);
115115
var newType = _productConverter.ConvertProductBack(newTypeModel, productType);
116116
return _productManagement.SaveType(newType);
@@ -139,7 +139,7 @@ public ActionResult<ProductModel[]> GetTypeByIdentity(string identity = null)
139139
var productIdentity = new ProductIdentity(identityArray[0],Convert.ToInt16(identityArray[1]));
140140
var productType = _productManagement.LoadType(productIdentity);
141141
if (productType == null)
142-
return NotFound(Strings.TYPE_NOT_FOUND);
142+
return NotFound(new MoryxExceptionResponse { Title = Strings.TYPE_NOT_FOUND });
143143
return new ProductModel[] { _productConverter.ConvertProduct(productType, false) };
144144
}
145145

@@ -170,11 +170,11 @@ public ActionResult<ProductModel> GetTypeById(long id)
170170
{
171171
productType = _productManagement.LoadType(id);
172172
}
173-
catch (ProductNotFoundException)
173+
catch (ProductNotFoundException e)
174174
{
175175
}
176176
if (productType == null)
177-
return NotFound(Strings.TYPE_NOT_FOUND);
177+
return NotFound(new MoryxExceptionResponse { Title = Strings.TYPE_NOT_FOUND } );
178178
return _productConverter.ConvertProduct(productType, false);
179179
}
180180

@@ -186,7 +186,7 @@ public ActionResult<bool> DeleteType(long id)
186186
{
187187
var result = _productManagement.DeleteProduct(id);
188188
if (!result)
189-
return NotFound(Strings.TYPE_NOT_FOUND);
189+
return NotFound(new MoryxExceptionResponse { Title = Strings.TYPE_NOT_FOUND });
190190
return result;
191191
}
192192

@@ -254,7 +254,7 @@ public ActionResult<ProductInstanceModel> GetInstance(long id)
254254
return BadRequest($"Id was 0");
255255
var productInstance = _productManagement.GetInstance(id);
256256
if (productInstance == null)
257-
return NotFound(string.Format(Strings.ProductNotFoundException_Message,id));
257+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ProductNotFoundException_Message, id) });
258258
return _productConverter.ConvertProductInstance(productInstance);
259259
}
260260

@@ -294,7 +294,7 @@ public ActionResult SaveInstance(ProductInstanceModel instanceModel)
294294
var type = ReflectionTool.GetPublicClasses<IProductType>(t => t.Name == instanceModel.Type)
295295
.FirstOrDefault();
296296
if (type == null)
297-
return NotFound(string.Format(Strings.ProductNotFoundException_Message,"null"));
297+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ProductNotFoundException_Message, "null") });
298298
var productType = (IProductType)Activator.CreateInstance(type);
299299
var productInstance = _productConverter.ConvertProductInstanceBack(instanceModel, productType);
300300
_productManagement.SaveInstance(productInstance);
@@ -314,7 +314,7 @@ public ActionResult<RecipeModel> GetRecipe(long id)
314314
return BadRequest($"Id was 0");
315315
var recipe = _productManagement.LoadRecipe(id);
316316
if (recipe == null)
317-
return NotFound(string.Format(Strings.RecipeNotFoundException_Message,id));
317+
return NotFound(new MoryxExceptionResponse {Title= string.Format(Strings.RecipeNotFoundException_Message, id) });
318318
return ProductConverter.ConvertRecipe(recipe);
319319
}
320320

@@ -330,7 +330,7 @@ public ActionResult<long> SaveRecipe(RecipeModel recipe)
330330
var type = ReflectionTool.GetPublicClasses<IProductRecipe>(t => t.Name == recipe.Type)
331331
.FirstOrDefault();
332332
if (type == null)
333-
return NotFound(string.Format(Strings.RecipeNotFoundException_Message, "null"));
333+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.RecipeNotFoundException_Message, "null") });
334334
var productRecipe = (IProductRecipe)Activator.CreateInstance(type);
335335
return _productManagement.SaveRecipe(_productConverter.ConvertRecipeBack(recipe, productRecipe, null));
336336
}
@@ -362,7 +362,7 @@ public ActionResult<RecipeModel> CreateRecipe(string recipeType)
362362
// TODO: Use type wrapper
363363
var type = ReflectionTool.GetPublicClasses<IProductRecipe>(t => t.Name == recipeType).FirstOrDefault();
364364
if (type == null)
365-
return NotFound(string.Format(Strings.RECIPE_TYPE_NOT_FOUND, recipeType));
365+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.RECIPE_TYPE_NOT_FOUND, recipeType) });
366366
var recipe = (IProductRecipe)Activator.CreateInstance(type);
367367
return ProductConverter.ConvertRecipe(recipe);
368368

src/Moryx.AbstractionLayer.Products.Endpoints/WorkplanController.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using Microsoft.AspNetCore.Http;
55
using Microsoft.AspNetCore.Mvc;
6+
using Moryx.AbstractionLayer.Properties;
7+
using Moryx.Asp.Extensions.Exception;
68
using Moryx.Products.Management.Modification;
79
using Moryx.Workflows;
810
using System.Collections.Generic;
@@ -51,7 +53,7 @@ public ActionResult<WorkplanModel[]> GetVersions(long id)
5153
return BadRequest($"Workplan id was 0");
5254
var versions = _workplansVersions.LoadVersions(id);
5355
if (versions == null)
54-
return NotFound();
56+
return NotFound(new MoryxExceptionResponse { Title =string.Format(Strings.WORKPLAN_NOT_FOUND,id) });
5557
var model = new List<WorkplanModel>();
5658
foreach (var v in versions)
5759
{
@@ -71,7 +73,7 @@ public ActionResult<WorkplanModel> GetWorkplan(long id)
7173
return BadRequest($"Workplan id was 0");
7274
var workplan = _workplansVersions.LoadWorkplan(id);
7375
if (workplan == null)
74-
return NotFound();
76+
return NotFound(new MoryxExceptionResponse { Title =string.Format(Strings.WORKPLAN_NOT_FOUND,id)});
7577
return ProductConverter.ConvertWorkplan(workplan);
7678
}
7779

@@ -82,7 +84,7 @@ public ActionResult<WorkplanModel> GetWorkplan(long id)
8284
public ActionResult DeleteWorkplan(long id)
8385
{
8486
if (_workplansVersions.LoadWorkplan(id) == null)
85-
return NotFound();
87+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.WORKPLAN_NOT_FOUND, id) });
8688
_workplansVersions.DeleteWorkplan(id);
8789
return Ok();
8890
}

src/Moryx.AbstractionLayer.Resources.Endpoints/Moryx.AbstractionLayer.Resources.Endpoints.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="5.0.0" />
2424
</ItemGroup>
2525

26+
<ItemGroup>
27+
<PackageReference Include="Moryx.Asp.Extensions"/>
28+
</ItemGroup>
29+
2630
<ItemGroup>
2731
<ProjectReference Include="..\Moryx.AbstractionLayer\Moryx.AbstractionLayer.csproj" />
2832
</ItemGroup>

src/Moryx.AbstractionLayer.Resources.Endpoints/ResourceManagementController.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.AspNetCore.Mvc;
1111
using Microsoft.AspNetCore.Mvc.ModelBinding;
1212
using Moryx.AbstractionLayer.Properties;
13+
using Moryx.Asp.Extensions.Exception;
1314
using Moryx.Resources.Interaction;
1415
using Moryx.Resources.Interaction.Converter;
1516
using Moryx.Serialization;
@@ -82,12 +83,12 @@ public ActionResult<ResourceModel[]> GetResources(ResourceQuery query)
8283
public ActionResult<ResourceModel> GetDetails(long id)
8384
{
8485
if (_resourceModification.GetAllResources<IResource>(r => r.Id == id) is null)
85-
return NotFound(string.Format(Strings.ResourceNotFoundException_ById_Message, id));
86+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ResourceNotFoundException_ById_Message, id) });
8687

8788
var converter = new ResourceToModelConverter(_resourceTypeTree, _serialization);
8889
var resourceModel = _resourceModification.Read(id, r => converter.GetDetails(r));
8990
if (resourceModel is null)
90-
return NotFound(string.Format(Strings.ResourceNotFoundException_ById_Message, id));
91+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ResourceNotFoundException_ById_Message, id) });
9192

9293
return resourceModel;
9394
}
@@ -101,7 +102,7 @@ public ActionResult<ResourceModel> GetDetails(long id)
101102
public ActionResult<Entry> InvokeMethod(long id, string method, Entry parameters)
102103
{
103104
if (_resourceModification.GetAllResources<IResource>(r => r.Id == id) is null)
104-
return NotFound(string.Format(Strings.ResourceNotFoundException_ById_Message, id));
105+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ResourceNotFoundException_ById_Message, id) });
105106

106107
Entry entry = null;
107108
_resourceModification.Modify(id, r =>
@@ -130,7 +131,7 @@ private ActionResult<ResourceModel> Construct(string type, MethodEntry method)
130131
{
131132
var resource = (Resource)Activator.CreateInstance(_resourceTypeTree[type].ResourceType);
132133
if (resource is null)
133-
return NotFound(Strings.RESOURCE_NOT_FOUND);
134+
return NotFound(new MoryxExceptionResponse { Title = Strings.RESOURCE_NOT_FOUND });
134135

135136
if (method != null)
136137
EntryConvert.InvokeMethod(resource, method, _serialization);
@@ -288,7 +289,7 @@ private void UpdateReferences(Resource instance, HashSet<long> resourcesToSave,
288289
public ActionResult<ResourceModel> Update(long id, ResourceModel model)
289290
{
290291
if (_resourceModification.GetAllResources<IResource>(r=>r.Id == id) is null)
291-
return NotFound(string.Format(Strings.ResourceNotFoundException_ById_Message, id));
292+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ResourceNotFoundException_ById_Message, id) });
292293

293294
_resourceModification.Modify(id, r => {
294295
var resourcesToSave = new HashSet<long>();
@@ -310,7 +311,7 @@ public ActionResult<ResourceModel> Update(long id, ResourceModel model)
310311
public ActionResult Remove(long id)
311312
{
312313
if (_resourceModification.GetAllResources<IResource>(r => r.Id == id) is null)
313-
return NotFound(string.Format(Strings.ResourceNotFoundException_ById_Message, id));
314+
return NotFound(new MoryxExceptionResponse { Title = string.Format(Strings.ResourceNotFoundException_ById_Message, id) });
314315

315316
var deleted = _resourceModification.Delete(id);
316317
if (!deleted)

src/Moryx.AbstractionLayer/Properties/Strings.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Moryx.AbstractionLayer/Properties/Strings.de.resx

+4-1
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,7 @@
150150
<data name="RESOURCE_NOT_FOUND" xml:space="preserve">
151151
<value>Die Ressource konnte nicht gefunden werden.</value>
152152
</data>
153-
</root>
153+
<data name="WORKPLAN_NOT_FOUND" xml:space="preserve">
154+
<value>Arbeitsplan nicht gefunden für id: {0}</value>
155+
</data>
156+
</root>

src/Moryx.AbstractionLayer/Properties/Strings.it.resx

+3
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@
129129
<data name="TYPE_NOT_FOUND" xml:space="preserve">
130130
<value>Il tipo indicato non è stato trovato.</value>
131131
</data>
132+
<data name="WORKPLAN_NOT_FOUND" xml:space="preserve">
133+
<value>Piano di lavoro non trovato per l'id: {0}</value>
134+
</data>
132135
</root>

src/Moryx.AbstractionLayer/Properties/Strings.resx

+3
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,7 @@
150150
<data name="RESOURCE_NOT_FOUND" xml:space="preserve">
151151
<value>Resource not found!</value>
152152
</data>
153+
<data name="WORKPLAN_NOT_FOUND" xml:space="preserve">
154+
<value>Workplan not found for id: {0}</value>
155+
</data>
153156
</root>

0 commit comments

Comments
 (0)