blob: cf265dfafe0b2f99446af0912ecb0c5c769bd9e4 [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*******************************************************************************/
11using System.Collections.Generic;
12using Microsoft.AspNetCore.Mvc;
13using BaSyx.API.Components;
14using BaSyx.Utils.ResultHandling;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010015using System.Web;
16using BaSyx.Models.Connectivity.Descriptors;
17using BaSyx.Models.Core.Common;
18
19namespace BaSyx.API.Http.Controllers
20{
21 public class AssetAdministrationShellRegistry : Controller, IAssetAdministrationShellRegistry
22 {
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010023 private readonly IAssetAdministrationShellRegistry aasRegistryImpl;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010024 public AssetAdministrationShellRegistry(IAssetAdministrationShellRegistry aasRegistry)
25 {
26 aasRegistryImpl = aasRegistry;
27 }
28
29 #region REST-Interface
30 /// <summary>
31 /// Retrieves all registered Asset Administration Shells within a defined system (e.g. site, area, production line, station)
32 /// </summary>
33 /// <returns></returns>
Constantin Ziesche02817f12020-08-04 21:40:43 +020034 /// <response code="200">Returns a list of found Asset Administration Shell Descriptors</response>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010035 /// <response code="400">Bad Request</response>
36 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +020037 [HttpGet("api/v1/registry", Name = "GetAssetAdministrationShellDescriptors")]
38 [ProducesResponseType(typeof(List<AssetAdministrationShellDescriptor>), 200)]
39 public IActionResult GetAssetAdministrationShellDescriptors()
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010040 {
41 var result = RetrieveAssetAdministrationShells();
Constantin Zieschefa612082020-04-03 09:54:56 +020042 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010043 }
44 /// <summary>
45 /// Retrieves a specific Asset Administration Shell
46 /// </summary>
47 /// <param name="aasId">The Asset Administration Shell's unique id</param>
48 /// <returns></returns>
49 /// <response code="200">Returns the requested Asset Administration Shell</response>
50 /// <response code="400">Bad Request</response>
51 /// <response code="404">No Asset Administration Shell with passed id found</response>
52 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +020053 [HttpGet("api/v1/registry/{*aasId}", Name = "GetAssetAdministrationShellDescriptor")]
54 [ProducesResponseType(typeof(AssetAdministrationShellDescriptor), 200)]
55 public IActionResult GetAssetAdministrationShellDescriptor(string aasId)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010056 {
Constantin Ziesche02817f12020-08-04 21:40:43 +020057 if (string.IsNullOrEmpty(aasId))
58 return ResultHandling.NullResult(nameof(aasId));
59
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010060 aasId = HttpUtility.UrlDecode(aasId);
61 var result = RetrieveAssetAdministrationShell(aasId);
Constantin Zieschefa612082020-04-03 09:54:56 +020062 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010063 }
Constantin Ziesche02817f12020-08-04 21:40:43 +020064
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010065 /// <summary>
66 /// Renews a specific Asset Administration Shell's registration
67 /// </summary>
68 /// <param name="aasId">The Asset Administration Shell's unique id</param>
69 /// <returns></returns>
70 /// <response code="200">The Asset Administration Shell's registration was successfully renewed</response>
71 /// <response code="400">The syntax of the passed Asset Administration Shell is not valid or malformed request</response>
72 /// <response code="404">No Asset Administration Shell with passed id found</response>
73 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +020074 [HttpPut("api/v1/registry/{*aasId}", Name = "RenewAssetAdministrationShellRegistration")]
75 [ProducesResponseType(typeof(Result), 204)]
76 public IActionResult RenewAssetAdministrationShellRegistration(string aasId)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010077 {
Constantin Ziesche02817f12020-08-04 21:40:43 +020078 if (string.IsNullOrEmpty(aasId))
79 return ResultHandling.NullResult(nameof(aasId));
80
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010081 aasId = HttpUtility.UrlDecode(aasId);
82 Dictionary<string, string> keyValues = null;
83 if (Request.Query?.Count > 0)
84 {
85 keyValues = new Dictionary<string, string>();
86 foreach (string key in Request.Query.Keys)
87 {
88 keyValues.Add(key, Request.Query[key].ToString());
89 }
90 }
91 var result = UpdateAssetAdministrationShell(aasId, keyValues);
Constantin Zieschefa612082020-04-03 09:54:56 +020092 return result.CreateActionResult(CrudOperation.Update);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010093 }
94 /// <summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +020095 /// Registers a new Asset Administration Shell at the registry
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010096 /// </summary>
Constantin Ziesche02817f12020-08-04 21:40:43 +020097 /// <param name="aasDescriptor">The Asset Administration Shell descriptor object</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010098 /// <returns></returns>
99 /// <response code="201">The Asset Administration Shell was created successfully</response>
100 /// <response code="400">The syntax of the passed Asset Administration Shell is not valid or malformed request</response>
101 /// <response code="422">The passed Asset Administration Shell conflicts with already registered Asset Administration Shells</response>
102 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200103 [HttpPost("api/v1/registry", Name = "RegisterAssetAdministrationShell")]
104 [ProducesResponseType(typeof(AssetAdministrationShellDescriptor), 201)]
105 public IActionResult RegisterAssetAdministrationShell([FromBody] IAssetAdministrationShellDescriptor aasDescriptor)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100106 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200107 if (aasDescriptor == null)
108 return ResultHandling.NullResult(nameof(aasDescriptor));
109
110 var result = CreateAssetAdministrationShell(aasDescriptor);
111 return result.CreateActionResult(CrudOperation.Create, "api/v1/registry/"+ HttpUtility.UrlEncode(aasDescriptor.Identification.Id));
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100112 }
113 /// <summary>
114 /// Deletes a specific Asset Administration Shell
115 /// </summary>
116 /// <param name="aasId">The Asset Administration Shell's unique id</param>
117 /// <returns></returns>
118 /// <response code="200">The Asset Administration Shell was deleted successfully</response>
119 /// <response code="400">Bad Request</response>
120 /// <response code="404">No Asset Administration Shell with passed id found</response>
121 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200122 [HttpDelete("api/v1/registry/{*aasId}", Name = "DeleteAssetAdministrationShellRegistration")]
123 [ProducesResponseType(typeof(Result), 204)]
124 public IActionResult DeleteAssetAdministrationShellRegistration(string aasId)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100125 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200126 if (string.IsNullOrEmpty(aasId))
127 return ResultHandling.NullResult(nameof(aasId));
128
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100129 aasId = HttpUtility.UrlDecode(aasId);
130 var result = DeleteAssetAdministrationShell(aasId);
Constantin Zieschefa612082020-04-03 09:54:56 +0200131 return result.CreateActionResult(CrudOperation.Delete);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100132 }
133
134
135 /// <summary>
136 /// Adds a new Submodel to an existing resp. registered Asset Administration Shell
137 /// </summary>
138 /// <param name="aasId">The Asset Administration Shell's unique id</param>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200139 /// <param name="submodelDescriptor">The Submodel descriptor object</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100140 /// <returns></returns>
141 /// <response code="201">The Submodel was created successfully</response>
142 /// <response code="400">The syntax of the passed Submodel is not valid or malformed request</response>
143 /// <response code="404">No Asset Administration Shell with passed id found</response>
144 /// <response code="422">The passed Submodel conflicts with already registered Submodels</response>
145 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200146 [HttpPost("api/v1/registry/{aasId}/submodels", Name = "RegisterSubmodelAtAssetAdministrationShell")]
147 [ProducesResponseType(typeof(SubmodelDescriptor), 201)]
148 public IActionResult RegisterSubmodelAtAssetAdministrationShell(string aasId, [FromBody] ISubmodelDescriptor submodelDescriptor)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100149 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200150 if (string.IsNullOrEmpty(aasId))
151 return ResultHandling.NullResult(nameof(aasId));
152 if (submodelDescriptor == null)
153 return ResultHandling.NullResult(nameof(submodelDescriptor));
154
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100155 aasId = HttpUtility.UrlDecode(aasId);
Constantin Ziesche02817f12020-08-04 21:40:43 +0200156 var result = CreateSubmodel(aasId, submodelDescriptor);
157 return result.CreateActionResult(CrudOperation.Create, "api/v1/registry/" + aasId + "/submodels/" + submodelDescriptor.IdShort);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100158 }
159
160 /// <summary>
161 /// Retrieves a specific Submodel from a specific Asset Administration Shell
162 /// </summary>
163 /// <param name="aasId">The Asset Administration Shell's unique id</param>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200164 /// <param name="submodelIdShort">The Submodel's short id</param>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100165 /// <returns></returns>
166 /// <response code="200">Returns the requested Submodels</response>
167 /// <response code="400">Bad Request</response>
168 /// <response code="404">No Asset Administration Shell / Submodel with passed id found</response>
169 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200170 [HttpGet("api/v1/registry/{aasId}/submodels/{submodelIdShort}", Name = "GetSubmodelDescriptorFromAssetAdministrationShell")]
171 [ProducesResponseType(typeof(SubmodelDescriptor), 200)]
172 public IActionResult GetSubmodelDescriptorFromAssetAdministrationShell(string aasId, string submodelIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100173 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200174 if (string.IsNullOrEmpty(aasId))
175 return ResultHandling.NullResult(nameof(aasId));
176 if (string.IsNullOrEmpty(submodelIdShort))
177 return ResultHandling.NullResult(nameof(submodelIdShort));
178
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100179 aasId = HttpUtility.UrlDecode(aasId);
180 var result = RetrieveSubmodel(aasId, submodelIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200181 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100182 }
183 /// <summary>
184 /// Deletes a specific Submodel from a specific Asset Administration Shell
185 /// </summary>
186 /// <param name="aasId">The Asset Administration Shell's unique id</param>
187 /// <param name="submodelIdShort">The Submodel's short id (idShort)</param>
188 /// <returns></returns>
189 /// <response code="200">The Submodel was deleted successfully</response>
190 /// <response code="400">Bad Request</response>
191 /// <response code="404">No Asset Administration Shell / Submodel with passed id found</response>
192 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200193 [HttpDelete("api/v1/registry/{aasId}/submodels/{submodelIdShort}", Name = "DeleteSubmodelFromAssetAdministrationShell")]
194 [ProducesResponseType(typeof(Result), 204)]
195 public IActionResult DeleteSubmodelFromAssetAdministrationShell(string aasId, string submodelIdShort)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100196 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200197 if (string.IsNullOrEmpty(aasId))
198 return ResultHandling.NullResult(nameof(aasId));
199 if (string.IsNullOrEmpty(submodelIdShort))
200 return ResultHandling.NullResult(nameof(submodelIdShort));
201
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100202 aasId = HttpUtility.UrlDecode(aasId);
203 var result = DeleteSubmodel(aasId, submodelIdShort);
Constantin Zieschefa612082020-04-03 09:54:56 +0200204 return result.CreateActionResult(CrudOperation.Delete);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100205 }
206 /// <summary>
207 /// Retrieves all Submodels from a specific Asset Administration Shell
208 /// </summary>
209 /// <param name="aasId">The Asset Administration Shell's unique id</param>
210 /// <returns></returns>
211 /// <response code="200">Returns a list of found Submodels</response>
212 /// <response code="400">Bad Request</response>
213 /// <response code="404">No Asset Administration Shell with passed id found</response>
214 /// <response code="502">Bad Gateway</response>
Constantin Ziesche02817f12020-08-04 21:40:43 +0200215 [HttpGet("api/v1/registry/{aasId}/submodels", Name = "GetAllSubmodelDescriptorsFromAssetAdministrationShell")]
216 [ProducesResponseType(typeof(List<SubmodelDescriptor>), 200)]
217 public IActionResult GetAllSubmodelDescriptorsFromAssetAdministrationShell(string aasId)
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100218 {
Constantin Ziesche02817f12020-08-04 21:40:43 +0200219 if (string.IsNullOrEmpty(aasId))
220 return ResultHandling.NullResult(nameof(aasId));
221
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100222 aasId = HttpUtility.UrlDecode(aasId);
223 var result = RetrieveSubmodels(aasId);
Constantin Zieschefa612082020-04-03 09:54:56 +0200224 return result.CreateActionResult(CrudOperation.Retrieve);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +0100225 }
226 #endregion
227
228 #region InterfaceImplementation
229 public IResult<IAssetAdministrationShellDescriptor> CreateAssetAdministrationShell(IAssetAdministrationShellDescriptor aas)
230 {
231 return aasRegistryImpl.CreateAssetAdministrationShell(aas);
232 }
233
234 public IResult DeleteAssetAdministrationShell(string aasId)
235 {
236 return aasRegistryImpl.DeleteAssetAdministrationShell(aasId);
237 }
238
239 public IResult<IAssetAdministrationShellDescriptor> RetrieveAssetAdministrationShell(string aasId)
240 {
241 return aasRegistryImpl.RetrieveAssetAdministrationShell(aasId);
242 }
243
244 public IResult<IElementContainer<IAssetAdministrationShellDescriptor>> RetrieveAssetAdministrationShells()
245 {
246 return aasRegistryImpl.RetrieveAssetAdministrationShells();
247 }
248
249 public IResult UpdateAssetAdministrationShell(string aasId, Dictionary<string, string> metaData)
250 {
251 return aasRegistryImpl.UpdateAssetAdministrationShell(aasId, metaData);
252 }
253
254 public IResult<ISubmodelDescriptor> CreateSubmodel(string aasId, ISubmodelDescriptor submodel)
255 {
256 return aasRegistryImpl.CreateSubmodel(aasId, submodel);
257 }
258
259 public IResult<IElementContainer<ISubmodelDescriptor>> RetrieveSubmodels(string aasId)
260 {
261 return aasRegistryImpl.RetrieveSubmodels(aasId);
262 }
263
264 public IResult<ISubmodelDescriptor> RetrieveSubmodel(string aasId, string submodelIdShort)
265 {
266 return aasRegistryImpl.RetrieveSubmodel(aasId, submodelIdShort);
267 }
268
269 public IResult DeleteSubmodel(string aasId, string submodelIdShort)
270 {
271 return aasRegistryImpl.DeleteSubmodel(aasId, submodelIdShort);
272 }
273
274
275 #endregion
276
277 #region Helper Methods
278
279
280 #endregion
281 }
282}