blob: b61d25ce62e143ee44524b076e26f5f43fb6f99f [file] [log] [blame]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +01001/*******************************************************************************
2* Copyright (c) 2020 Robert Bosch GmbH
3* Author: Constantin Ziesche (constantin.ziesche@bosch.com)
4*
5* This program and the accompanying materials are made available under the
6* terms of the Eclipse Public License 2.0 which is available at
7* http://www.eclipse.org/legal/epl-2.0
8*
9* SPDX-License-Identifier: EPL-2.0
10*******************************************************************************/
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010011using Microsoft.AspNetCore.Mvc;
12using BaSyx.Models.Core.AssetAdministrationShell.Generics;
13using BaSyx.Utils.ResultHandling;
14using BaSyx.API.Components;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010015using BaSyx.Utils.Client;
16using System;
17using BaSyx.API.AssetAdministrationShell;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010018using Newtonsoft.Json.Linq;
19using BaSyx.Models.Extensions;
Constantin Ziesche02817f12020-08-04 21:40:43 +020020using BaSyx.Models.Core.AssetAdministrationShell.Implementations;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010021using BaSyx.Models.Core.AssetAdministrationShell.Generics.SubmodelElementTypes;
22using BaSyx.Models.Core.AssetAdministrationShell.Implementations.SubmodelElementTypes;
23using BaSyx.Models.Connectivity.Descriptors;
24using BaSyx.Models.Core.Common;
Constantin Zieschefa612082020-04-03 09:54:56 +020025using BaSyx.Models.Communication;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010026
27namespace BaSyx.API.Http.Controllers
28{
29 /// <summary>
30 /// All Asset Administration Shell Services provided by the component
31 /// </summary>
32 public class SubmodelServices : Controller, ISubmodelServiceProvider
33 {
34 private readonly ISubmodelServiceProvider submodelServiceProvider;
35
36 public ISubmodel Submodel => submodelServiceProvider?.GetBinding();
37 public ISubmodelDescriptor ServiceDescriptor { get; }
38
39 public SubmodelServices(ISubmodelServiceProvider submodelServiceProvider)
40 {
41 this.submodelServiceProvider = submodelServiceProvider;
42 ServiceDescriptor = submodelServiceProvider?.ServiceDescriptor;
43 }
44
45 public void BindTo(ISubmodel element)
46 {
47 submodelServiceProvider.BindTo(element);
48 }
49 public ISubmodel GetBinding()
50 {
51 return submodelServiceProvider.GetBinding();
52 }
53
54
55 #region REST-Interface Submodel
56
Constantin Ziesche02817f12020-08-04 21:40:43 +020057
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010058 /// <summary>
59 /// Retrieves a customizable table version of a Submodel
60 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +020061 /// <param name="columns">A comma-separated list of field names to structure the payload beeing returned</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010062 /// <returns></returns>
63 /// <response code="200">Success</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +020064 /// <response code="404">Submodel not found</response>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010065 [HttpGet("submodel/table", Name = "GetSubmodelAsTable")]
66 [ProducesResponseType(typeof(Result), 404)]
67 public IActionResult GetSubmodelAsTable([FromQuery] string columns)
68 {
Constantin Ziesche02817f12020-08-04 21:40:43 +020069 if (string.IsNullOrEmpty(columns))
70 return ResultHandling.NullResult(nameof(columns));
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010071
Constantin Ziesche02817f12020-08-04 21:40:43 +020072 var result = RetrieveSubmodel();
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010073 if (result != null && result.Entity != null)
74 {
Constantin Ziesche02817f12020-08-04 21:40:43 +020075 string[] columnNames = columns.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010076 JToken customizedSubmodel = result.Entity.CustomizeSubmodel(columnNames);
77 return new JsonResult(customizedSubmodel);
78 }
79
Constantin Zieschefa612082020-04-03 09:54:56 +020080 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010081 }
82
83
84 /// <summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +020085 /// Retrieves the minimized version of a Submodel, i.e. only the values of SubmodelElements are serialized and returned
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010086 /// </summary>
87 /// <returns></returns>
88 /// <response code="200">Success</response>
89 /// <response code="404">Submodel not found</response>
90 [HttpGet("submodel/values", Name = "GetSubmodelValues")]
91 [ProducesResponseType(typeof(Result), 404)]
92 public IActionResult GetMinimizedSubmodel()
93 {
94 var result = RetrieveSubmodel();
95
96 if (result != null && result.Entity != null)
97 {
98 JObject minimizedSubmodel = result.Entity.MinimizeSubmodel();
99 return new JsonResult(minimizedSubmodel);
100 }
101
Constantin Zieschefa612082020-04-03 09:54:56 +0200102 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100103 }
104
105 /// <summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200106 /// Retrieves the entire Submodel
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100107 /// </summary>
108 /// <returns></returns>
109 /// <response code="200">Success</response>
110 /// <response code="404">Submodel not found</response>
111 [HttpGet("submodel", Name = "GetSubmodel")]
112 [ProducesResponseType(typeof(BaSyx.Models.Core.AssetAdministrationShell.Implementations.Submodel), 200)]
113 [ProducesResponseType(typeof(Result), 404)]
114 public IActionResult GetSubmodel()
115 {
116 var result = RetrieveSubmodel();
Constantin Zieschefa612082020-04-03 09:54:56 +0200117 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100118 }
119
120 /// <summary>
121 /// Retrieves all SubmodelElements from the current Submodel
122 /// </summary>
123 /// <returns></returns>
124 /// <response code="200">Returns a list of found SubmodelElements</response>
125 /// <response code="404">Submodel not found / No SubmodelElements found</response>
126 [HttpGet("submodel/submodelElements", Name = "GetSubmodelElements")]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200127 [ProducesResponseType(typeof(SubmodelElement[]), 200)]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100128 [ProducesResponseType(typeof(Result), 404)]
129 public IActionResult GetSubmodelElements()
130 {
131 var result = RetrieveSubmodelElements();
Constantin Zieschefa612082020-04-03 09:54:56 +0200132 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100133 }
134
135 /// <summary>
136 /// Retrieves all Properties from the current Submodel
137 /// </summary>
138 /// <returns></returns>
139 /// <response code="200">Returns a list of found Properties</response>
140 /// <response code="404">Submodel not found / No Properties found</response>
141 [HttpGet("submodel/properties", Name = "GetProperties")]
142 [ProducesResponseType(typeof(Property[]), 200)]
143 [ProducesResponseType(typeof(Result), 404)]
144 public IActionResult GetProperties()
145 {
146 var result = RetrieveProperties();
Constantin Zieschefa612082020-04-03 09:54:56 +0200147 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100148 }
149
150 /// <summary>
151 /// Retrieves all Operations from the current Submodel
152 /// </summary>
153 /// <returns></returns>
154 /// <response code="200">Success</response>
155 /// <response code="404">Submodel not found / No Operations found</response>
156 [HttpGet("submodel/operations", Name = "GetOperations")]
157 [ProducesResponseType(typeof(Operation[]), 200)]
158 [ProducesResponseType(typeof(Result), 404)]
159 public IActionResult GetOperations()
160 {
161 var result = RetrieveOperations();
Constantin Zieschefa612082020-04-03 09:54:56 +0200162 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100163 }
164
165 /// <summary>
166 /// Retrieves all Events from the current Submodel
167 /// </summary>
168 /// <returns></returns>
169 /// <response code="200">Success</response>
170 /// <response code="404">Submodel not found / No Events found</response>
171 [HttpGet("submodel/events", Name = "GetEvents")]
172 [ProducesResponseType(typeof(Event[]), 200)]
173 [ProducesResponseType(typeof(Result), 404)]
174 public IActionResult GetEvents()
175 {
176 var result = RetrieveEvents();
Constantin Zieschefa612082020-04-03 09:54:56 +0200177 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100178 }
179
180
Constantin Ziesche95d51092020-03-04 17:58:10 +0100181 #region SubmodelElement - REST-Calls
182 /// <summary>
183 /// Adds a new Submodel Element to the Submodel
184 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200185 /// <param name="submodelElement">The serialized Submodel Element object</param>
Constantin Ziesche95d51092020-03-04 17:58:10 +0100186 /// <returns></returns>
187 /// <response code="201">Submodel Element created successfully</response>
188 /// <response code="400">Bad Request</response>
189 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200190 [HttpPut("submodel/submodelElements", Name = "PutSubmodelElement")]
191 [ProducesResponseType(typeof(SubmodelElement), 201)]
Constantin Ziesche95d51092020-03-04 17:58:10 +0100192 [ProducesResponseType(typeof(Result), 400)]
193 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200194 public IActionResult PutSubmodelElement([FromBody] ISubmodelElement submodelElement)
Constantin Ziesche95d51092020-03-04 17:58:10 +0100195 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200196 if(submodelElement == null)
197 return ResultHandling.NullResult(nameof(submodelElement));
198
Constantin Ziesche95d51092020-03-04 17:58:10 +0100199 var result = CreateSubmodelElement(submodelElement);
Constantin Zieschefa612082020-04-03 09:54:56 +0200200 return result.CreateActionResult(CrudOperation.Create, "submodel/submodelElements/" + submodelElement.IdShort);
Constantin Ziesche95d51092020-03-04 17:58:10 +0100201 }
Constantin Ziesche02817f12020-08-04 21:40:43 +0200202
203
Constantin Ziesche95d51092020-03-04 17:58:10 +0100204 /// <summary>
205 /// Retrieves a specific Submodel Element from the Submodel
206 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200207 /// <param name="submodelElementIdShort">The Submodel Element's short id</param>
Constantin Ziesche95d51092020-03-04 17:58:10 +0100208 /// <returns></returns>
209 /// <response code="200">Returns the requested Submodel Element</response>
210 /// <response code="404">Submodel/Submodel Element not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200211 [HttpGet("submodel/submodelElements/{*submodelElementIdShort}", Name = "GetSubmodelElementByIdShort")]
Constantin Ziesche95d51092020-03-04 17:58:10 +0100212 [ProducesResponseType(typeof(Property), 200)]
213 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200214 public IActionResult GetSubmodelElementByIdShort(string submodelElementIdShort)
Constantin Ziesche95d51092020-03-04 17:58:10 +0100215 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200216 if (string.IsNullOrEmpty(submodelElementIdShort))
217 return ResultHandling.NullResult(nameof(submodelElementIdShort));
218
219 var result = RetrieveSubmodelElement(submodelElementIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200220 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche95d51092020-03-04 17:58:10 +0100221 }
222
223 /// <summary>
224 /// Deletes a specific Submodel Element from the Submodel
225 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200226 /// <param name="submodelElementIdShort">The Submodel Element's short id</param>
Constantin Ziesche95d51092020-03-04 17:58:10 +0100227 /// <returns></returns>
228 /// <response code="204">Submodel Element deleted successfully</response>
229 /// <response code="404">Submodel/Submodel Element not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200230 [HttpDelete("submodel/submodelElements/{*submodelElementIdShort}", Name = "DeleteSubmodelElementByIdShort")]
231 [ProducesResponseType(typeof(Result), 200)]
232 public IActionResult DeleteSubmodelElementByIdShort(string submodelElementIdShort)
Constantin Ziesche95d51092020-03-04 17:58:10 +0100233 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200234 if (string.IsNullOrEmpty(submodelElementIdShort))
235 return ResultHandling.NullResult(nameof(submodelElementIdShort));
236
237 var result = DeleteSubmodelElement(submodelElementIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200238 return result.CreateActionResult(CrudOperation.Delete);
Constantin Ziesche95d51092020-03-04 17:58:10 +0100239 }
240 #endregion
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100241 #region Property - REST-Calls
242 /// <summary>
243 /// Adds a new Property to the Asset Administration Shell's Submodel
244 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200245 /// <param name="property">The serialized Property object</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100246 /// <returns></returns>
247 /// <response code="201">Property created successfully</response>
248 /// <response code="400">Bad Request</response>
249 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200250 [HttpPut("submodel/properties", Name = "PutProperty")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100251 [ProducesResponseType(typeof(Property), 201)]
252 [ProducesResponseType(typeof(Result), 400)]
253 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200254 public IActionResult PutProperty([FromBody] IProperty property)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100255 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200256 if (property == null)
257 return ResultHandling.NullResult(nameof(property));
258
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100259 var result = CreateProperty(property);
Constantin Zieschefa612082020-04-03 09:54:56 +0200260 return result.CreateActionResult(CrudOperation.Create, "submodel/properties/" + property.IdShort);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100261 }
262 /// <summary>
263 /// Retrieves a specific Property from the Asset Administrations's Submodel
264 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200265 /// <param name="propertyIdShort">The Property's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100266 /// <returns></returns>
267 /// <response code="200">Returns the requested Property</response>
268 /// <response code="404">Submodel/Property not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200269 [HttpGet("submodel/properties/{propertyIdShort}", Name = "GetPropertyByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100270 [ProducesResponseType(typeof(Property), 200)]
271 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200272 public IActionResult GetPropertyByIdShort(string propertyIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100273 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200274 if (string.IsNullOrEmpty(propertyIdShort))
275 return ResultHandling.NullResult(nameof(propertyIdShort));
276
277 var result = RetrieveProperty(propertyIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200278 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100279 }
280
281 /// <summary>
282 /// Retrieves the value of a specific Property from the Asset Administrations Shell's Submodel
283 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200284 /// <param name="propertyIdShort">The Property's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100285 /// <returns></returns>
286 /// <response code="200">Returns the requested Property's value</response>
287 /// <response code="404">Submodel/Property not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200288 [HttpGet("submodel/properties/{propertyIdShort}/value", Name = "GetPropertyValueByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100289 [ProducesResponseType(typeof(ElementValue), 200)]
290 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200291 public IActionResult GetPropertyValueByIdShort(string propertyIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100292 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200293 if (string.IsNullOrEmpty(propertyIdShort))
294 return ResultHandling.NullResult(nameof(propertyIdShort));
295
296 var result = RetrievePropertyValue(propertyIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200297 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100298 }
299
300 /// <summary>
301 /// Updates the Asset Administration Shell's Submodel's Property
302 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200303 /// <param name="propertyIdShort">The Property's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100304 /// <param name="value">The new value</param>
305 /// <returns></returns>
306 /// <response code="200">Property's value changed successfully</response>
307 /// <response code="404">Submodel/Property not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200308 [HttpPut("submodel/properties/{propertyIdShort}/value", Name = "PutPropertyValueByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100309 [ProducesResponseType(typeof(ElementValue), 200)]
310 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200311 public IActionResult PutPropertyValueByIdShort(string propertyIdShort, [FromBody] IValue value)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100312 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200313 if (string.IsNullOrEmpty(propertyIdShort))
314 return ResultHandling.NullResult(nameof(propertyIdShort));
315
316 var result = UpdatePropertyValue(propertyIdShort, value);
Constantin Zieschefa612082020-04-03 09:54:56 +0200317 return result.CreateActionResult(CrudOperation.Update);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100318 }
319 /// <summary>
320 /// Deletes a specific Property from the Asset Administration Shell's Submodel
321 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200322 /// <param name="propertyIdShort">The Property's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100323 /// <returns></returns>
324 /// <response code="204">Property deleted successfully</response>
325 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200326 [HttpDelete("submodel/properties/{propertyIdShort}", Name = "DeletePropertyByIdShort")]
327 [ProducesResponseType(typeof(Result), 200)]
328 public IActionResult DeletePropertyByIdShort(string propertyIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100329 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200330 if (string.IsNullOrEmpty(propertyIdShort))
331 return ResultHandling.NullResult(nameof(propertyIdShort));
332
333 var result = DeleteProperty(propertyIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200334 return result.CreateActionResult(CrudOperation.Delete);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100335 }
336 #endregion
337 #region Operation - REST-Calls
338 /// <summary>
339 /// Adds a new operation to the Asset Administraiton Shell's Submodel
340 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200341 /// <param name="operation">The serialized Operation object</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100342 /// <returns></returns>
343 /// <response code="201">Operation created successfully</response>
344 /// <response code="400">Bad Request</response>
345 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200346 [HttpPut("submodel/operations", Name = "PutOperation")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100347 [ProducesResponseType(typeof(Operation), 201)]
348 [ProducesResponseType(typeof(Result), 400)]
349 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200350 public IActionResult PutOperation([FromBody] IOperation operation)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100351 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200352 if (operation == null)
353 return ResultHandling.NullResult(nameof(operation));
354
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100355 var result = CreateOperation(operation);
Constantin Zieschefa612082020-04-03 09:54:56 +0200356 return result.CreateActionResult(CrudOperation.Create, "submodel/operations/" + operation.IdShort);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100357 }
358 /// <summary>
359 /// Retrieves a specific Operation from the Asset Administration Shell's Submodel
360 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200361 /// <param name="operationIdShort">The Operation's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100362 /// <returns></returns>
363 /// <response code="200">Success</response>
364 /// <response code="404">Submodel/Operation not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200365 [HttpGet("submodel/operations/{operationIdShort}", Name = "GetOperationByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100366 [ProducesResponseType(typeof(Operation), 200)]
367 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200368 public IActionResult GetOperationByIdShort(string operationIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100369 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200370 if (string.IsNullOrEmpty(operationIdShort))
371 return ResultHandling.NullResult(nameof(operationIdShort));
372
373 var result = RetrieveOperation(operationIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200374 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100375 }
376 /// <summary>
377 /// Deletes a specific Operation from the Asset Administration Shell's Submodel
378 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200379 /// <param name="operationIdShort">The Operation's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100380 /// <returns></returns>
381 /// <response code="204">Operation deleted successfully</response>
382 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200383 [HttpDelete("submodel/operations/{operationIdShort}", Name = "DeleteOperationByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100384 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200385 public IActionResult DeleteOperationByIdShort(string operationIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100386 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200387 if (string.IsNullOrEmpty(operationIdShort))
388 return ResultHandling.NullResult(nameof(operationIdShort));
389
390 var result = DeleteOperation(operationIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200391 return result.CreateActionResult(CrudOperation.Delete);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100392 }
393 /// <summary>
Constantin Zieschefa612082020-04-03 09:54:56 +0200394 /// Synchronously invokes a specific operation from the Submodel
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100395 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200396 /// <param name="operationIdShort">The Operation's short id</param>
Constantin Zieschefa612082020-04-03 09:54:56 +0200397 /// <param name="invocationRequest">The parameterized request object for the invocation</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100398 /// <returns></returns>
399 /// <response code="200">Operation invoked successfully</response>
400 /// <response code="400">Bad Request</response>
Constantin Zieschefa612082020-04-03 09:54:56 +0200401 /// <response code="404">Submodel / Method handler not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200402 [HttpPost("submodel/operations/{operationIdShort}", Name = "InvokeOperationByIdShort")]
Constantin Zieschefa612082020-04-03 09:54:56 +0200403 [ProducesResponseType(typeof(InvocationResponse), 200)]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100404 [ProducesResponseType(typeof(Result), 400)]
405 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200406 public IActionResult InvokeOperationByIdShort(string operationIdShort, [FromBody] InvocationRequest invocationRequest)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100407 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200408 if (string.IsNullOrEmpty(operationIdShort))
409 return ResultHandling.NullResult(nameof(operationIdShort));
410 if (invocationRequest == null)
411 return ResultHandling.NullResult(nameof(invocationRequest));
412
413 IResult<InvocationResponse> result = InvokeOperation(operationIdShort, invocationRequest);
Constantin Zieschefa612082020-04-03 09:54:56 +0200414 return result.CreateActionResult(CrudOperation.Invoke);
415 }
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100416
Constantin Zieschefa612082020-04-03 09:54:56 +0200417 /// <summary>
418 /// Asynchronously invokes a specific operation from the Submodel
419 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200420 /// <param name="operationIdShort">The Operation's short id</param>
Constantin Zieschefa612082020-04-03 09:54:56 +0200421 /// <param name="invocationRequest">The parameterized request object for the invocation</param>
422 /// <returns></returns>
423 /// <response code="200">Operation invoked successfully</response>
424 /// <response code="400">Bad Request</response>
425 /// <response code="404">Submodel / Method handler not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200426 [HttpPost("submodel/operations/{operationIdShort}/async", Name = "InvokeOperationByIdShortAsync")]
Constantin Zieschefa612082020-04-03 09:54:56 +0200427 [ProducesResponseType(typeof(CallbackResponse), 200)]
428 [ProducesResponseType(typeof(Result), 400)]
429 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200430 public IActionResult InvokeOperationByIdShortAsync(string operationIdShort, [FromBody] InvocationRequest invocationRequest)
Constantin Zieschefa612082020-04-03 09:54:56 +0200431 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200432 if (string.IsNullOrEmpty(operationIdShort))
433 return ResultHandling.NullResult(nameof(operationIdShort));
434 if (invocationRequest == null)
435 return ResultHandling.NullResult(nameof(invocationRequest));
436
437 IResult<CallbackResponse> result = InvokeOperationAsync(operationIdShort, invocationRequest);
Constantin Zieschefa612082020-04-03 09:54:56 +0200438 return result.CreateActionResult(CrudOperation.Invoke);
439 }
440
441 /// <summary>
442 /// Retrieves the result of an asynchronously started operation
443 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200444 /// <param name="operationIdShort">The Operation's short id</param>
Constantin Zieschefa612082020-04-03 09:54:56 +0200445 /// <param name="requestId">The request id</param>
446 /// <returns></returns>
447 /// <response code="200">Result found</response>
448 /// <response code="400">Bad Request</response>
449 /// <response code="404">Submodel / Operation / Request not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200450 [HttpGet("submodel/operations/{operationIdShort}/invocationList/{requestId}", Name = "GetInvocationResultByIdShort")]
Constantin Zieschefa612082020-04-03 09:54:56 +0200451 [ProducesResponseType(typeof(InvocationResponse), 200)]
452 [ProducesResponseType(typeof(Result), 400)]
453 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200454 public IActionResult GetInvocationResultByIdShort(string operationIdShort, string requestId)
Constantin Zieschefa612082020-04-03 09:54:56 +0200455 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200456 if (string.IsNullOrEmpty(operationIdShort))
457 return ResultHandling.NullResult(nameof(operationIdShort));
458 if (string.IsNullOrEmpty(requestId))
459 return ResultHandling.NullResult(nameof(requestId));
460
461 IResult<InvocationResponse> result = GetInvocationResult(operationIdShort, requestId);
Constantin Zieschefa612082020-04-03 09:54:56 +0200462 return result.CreateActionResult(CrudOperation.Invoke);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100463 }
464
465 #endregion
466 #region Event - REST-Calls
467 /// <summary>
468 /// Adds a new event to the Asset Administration Shell's Submodel
469 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200470 /// <param name="eventable">The serialized Event object</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100471 /// <returns></returns>
472 /// <response code="201">Event created successfully</response>
473 /// <response code="400">Bad Request</response>
474 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200475 [HttpPut("submodel/events", Name = "PutEvent")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100476 [ProducesResponseType(typeof(Event), 201)]
477 [ProducesResponseType(typeof(Result), 400)]
478 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200479 public IActionResult PutEvent([FromBody] IEvent eventable)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100480 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200481 if (eventable == null)
482 return ResultHandling.NullResult(nameof(eventable));
483
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100484 var result = CreateEvent(eventable);
Constantin Zieschefa612082020-04-03 09:54:56 +0200485 return result.CreateActionResult(CrudOperation.Create, "submodel/events/" + eventable.IdShort);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100486 }
487 /// <summary>
488 /// Retrieves a specific event from the Asset Administration Shell's Submodel
489 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200490 /// <param name="eventIdShort">The Event's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100491 /// <returns></returns>
492 /// <response code="200">Success</response>
493 /// <response code="404">Submodel/Event not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200494 [HttpGet("submodel/events/{eventIdShort}", Name = "GetEventByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100495 [ProducesResponseType(typeof(Event), 200)]
496 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200497 public IActionResult GetEventByIdShort(string eventIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100498 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200499 if (string.IsNullOrEmpty(eventIdShort))
500 return ResultHandling.NullResult(nameof(eventIdShort));
501
502 var result = RetrieveEvent(eventIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200503 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100504 }
505 /// <summary>
506 /// Deletes a specific event from the Asset Administration Shell's Submodel
507 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200508 /// <param name="eventIdShort">The Event's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100509 /// <returns></returns>
510 /// <response code="204">Event deleted successfully</response>
511 /// <response code="404">Submodel not found</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200512 [HttpDelete("submodel/events/{eventIdShort}", Name = "DeleteEventByIdShort")]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100513 [ProducesResponseType(typeof(Result), 404)]
Constantin Ziesche02817f12020-08-04 21:40:43 +0200514 public IActionResult DeleteEventByIdShort(string eventIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100515 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200516 if (string.IsNullOrEmpty(eventIdShort))
517 return ResultHandling.NullResult(nameof(eventIdShort));
518
519 var result = DeleteEvent(eventIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200520 return result.CreateActionResult(CrudOperation.Delete);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100521 }
522
523
524 #endregion
525
526 #endregion
527
528 #region Interface Implementation SubmodelServiceProvider
529
530 public IResult<IOperation> CreateOperation(IOperation operation)
531 {
532 return submodelServiceProvider.CreateOperation(operation);
533 }
534
535 public IResult<IElementContainer<IOperation>> RetrieveOperations()
536 {
537 return submodelServiceProvider.RetrieveOperations();
538 }
539
540 public IResult<IOperation> RetrieveOperation(string operationId)
541 {
542 return submodelServiceProvider.RetrieveOperation(operationId);
543 }
544
545 public IResult DeleteOperation(string operationId)
546 {
547 return submodelServiceProvider.DeleteOperation(operationId);
548 }
549
Constantin Zieschefa612082020-04-03 09:54:56 +0200550 public IResult<InvocationResponse> InvokeOperation(string operationId, InvocationRequest invocationRequest)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100551 {
Constantin Zieschefa612082020-04-03 09:54:56 +0200552 return submodelServiceProvider.InvokeOperation(operationId, invocationRequest);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100553 }
554
Constantin Ziesche02817f12020-08-04 21:40:43 +0200555 public IResult<IProperty> CreateProperty(IProperty property)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100556 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200557 return submodelServiceProvider.CreateProperty(property);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100558 }
559
560 public IResult<IElementContainer<IProperty>> RetrieveProperties()
561 {
562 return submodelServiceProvider.RetrieveProperties();
563 }
564
565 public IResult<IProperty> RetrieveProperty(string propertyId)
566 {
567 return submodelServiceProvider.RetrieveProperty(propertyId);
568 }
569
570 public IResult UpdatePropertyValue(string propertyId, IValue propertyValue)
571 {
572 return submodelServiceProvider.UpdatePropertyValue(propertyId, propertyValue);
573 }
574
575 public IResult DeleteProperty(string propertyId)
576 {
577 return submodelServiceProvider.DeleteProperty(propertyId);
578 }
579
580 public IResult<IEvent> CreateEvent(IEvent eventable)
581 {
582 return submodelServiceProvider.CreateEvent(eventable);
583 }
584
585 public IResult<IElementContainer<IEvent>> RetrieveEvents()
586 {
587 return submodelServiceProvider.RetrieveEvents();
588 }
589
590 public IResult<IEvent> RetrieveEvent(string eventId)
591 {
592 return submodelServiceProvider.RetrieveEvent(eventId);
593 }
594
595 public IResult ThrowEvent(IPublishableEvent publishableEvent, string topic, Action<IMessagePublishedEventArgs> MessagePublished, byte qosLevel, bool retain)
596 {
597 return submodelServiceProvider.ThrowEvent(publishableEvent, topic, MessagePublished, qosLevel, retain);
598 }
599
600 public IResult DeleteEvent(string eventId)
601 {
602 return submodelServiceProvider.DeleteEvent(eventId);
603 }
604
605 public Delegate RetrieveMethodDelegate(string operationId)
606 {
607 return submodelServiceProvider.RetrieveMethodDelegate(operationId);
608 }
609
610 public void RegisterMethodCalledHandler(string operationId, Delegate handler)
611 {
612 submodelServiceProvider.RegisterMethodCalledHandler(operationId, handler);
613 }
614
615 public void ConfigureEventHandler(IMessageClient messageClient)
616 {
617 submodelServiceProvider.ConfigureEventHandler(messageClient);
618 }
619
620 public IResult<IValue> RetrievePropertyValue(string propertyId)
621 {
622 return submodelServiceProvider.RetrievePropertyValue(propertyId);
623 }
624
625 public PropertyHandler RetrievePropertyHandler(string propertyId)
626 {
627 return submodelServiceProvider.RetrievePropertyHandler(propertyId);
628 }
629
630 public void RegisterPropertyHandler(string propertyId, PropertyHandler handler)
631 {
632 submodelServiceProvider.RegisterPropertyHandler(propertyId, handler);
633 }
634
635 public void SubscribeUpdates(string propertyId, Action<IValue> updateFunction)
636 {
637 submodelServiceProvider.SubscribeUpdates(propertyId, updateFunction);
638 }
639
640 public void PublishUpdate(string propertyId, IValue propertyValue)
641 {
642 submodelServiceProvider.PublishUpdate(propertyId, propertyValue);
643 }
644
645 public IResult<ISubmodel> RetrieveSubmodel()
646 {
647 return submodelServiceProvider.RetrieveSubmodel();
648 }
649
650 public void RegisterEventDelegate(string eventId, EventDelegate eventDelegate)
651 {
652 submodelServiceProvider.RegisterEventDelegate(eventId, eventDelegate);
653 }
654
655 public IResult<ISubmodelElement> CreateSubmodelElement(ISubmodelElement submodelElement)
656 {
657 return submodelServiceProvider.CreateSubmodelElement(submodelElement);
658 }
659
660 public IResult<IElementContainer<ISubmodelElement>> RetrieveSubmodelElements()
661 {
662 return submodelServiceProvider.RetrieveSubmodelElements();
663 }
664
665 public IResult<ISubmodelElement> RetrieveSubmodelElement(string submodelElementId)
666 {
667 return submodelServiceProvider.RetrieveSubmodelElement(submodelElementId);
668 }
669
670 public IResult<IValue> RetrieveSubmodelElementValue(string submodelElementId)
671 {
672 return submodelServiceProvider.RetrieveSubmodelElementValue(submodelElementId);
673 }
674
675 public IResult UpdateSubmodelElement(string submodelElementId, ISubmodelElement submodelElement)
676 {
677 return submodelServiceProvider.UpdateSubmodelElement(submodelElementId, submodelElement);
678 }
679
680 public IResult DeleteSubmodelElement(string submodelElementId)
681 {
682 return submodelServiceProvider.DeleteSubmodelElement(submodelElementId);
683 }
684
Constantin Zieschefa612082020-04-03 09:54:56 +0200685 public IResult<CallbackResponse> InvokeOperationAsync(string operationId, InvocationRequest invocationRequest)
686 {
687 return submodelServiceProvider.InvokeOperationAsync(operationId, invocationRequest);
688 }
689
690 public IResult<InvocationResponse> GetInvocationResult(string operationId, string requestId)
691 {
692 return submodelServiceProvider.GetInvocationResult(operationId, requestId);
693 }
694
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100695 #endregion
696
697 #region Helper Methods
698
699
700 #endregion
701 }
702}