|
8 | 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
9 | 9 | * permit persons to whom the Software is furnished to do so, subject to |
10 | 10 | * the following conditions: |
11 | | - * |
| 11 | + * |
12 | 12 | * The above copyright notice and this permission notice shall be |
13 | 13 | * included in all copies or substantial portions of the Software. |
14 | | - * |
| 14 | + * |
15 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
16 | 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17 | 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
@@ -58,7 +58,7 @@ public class DiscoveryIntegrationAasRepository implements AasRepository { |
58 | 58 | private AasRepository decorated; |
59 | 59 |
|
60 | 60 | private final AasDiscoveryService discoveryApi; |
61 | | - |
| 61 | + |
62 | 62 | public DiscoveryIntegrationAasRepository(AasRepository decorated, AasDiscoveryService discoveryApi) { |
63 | 63 | this.decorated = decorated; |
64 | 64 | this.discoveryApi = discoveryApi; |
@@ -94,6 +94,7 @@ public void deleteAas(String shellId) { |
94 | 94 | try { |
95 | 95 | discoveryApi.deleteAllAssetLinksById(shellId); |
96 | 96 | } catch (Exception e){ |
| 97 | + logger.error("Failed to unlink asset in discovery service for AAS ID {}", shellId, e); |
97 | 98 | throw new RepositoryDiscoveryUnlinkException(shellId, e); |
98 | 99 | } |
99 | 100 | } |
@@ -162,30 +163,52 @@ private void updateAssetLinks(String shellId, AssetAdministrationShell shell) { |
162 | 163 | } |
163 | 164 |
|
164 | 165 | private static DefaultSpecificAssetId getGlobalAssetIdAsSpecificAssetId(AssetAdministrationShell shell) { |
165 | | - return new DefaultSpecificAssetId.Builder().name("globalAssetId").value(shell.getAssetInformation().getGlobalAssetId()).build(); |
| 166 | + if (shell.getAssetInformation() == null || shell.getAssetInformation().getGlobalAssetId() == null) |
| 167 | + throw new IllegalArgumentException("AssetInformation or GlobalAssetId is null"); |
| 168 | + |
| 169 | + return new DefaultSpecificAssetId.Builder() |
| 170 | + .name("globalAssetId") |
| 171 | + .value(shell.getAssetInformation().getGlobalAssetId()) |
| 172 | + .build(); |
166 | 173 | } |
167 | 174 |
|
168 | 175 | private void createAssetLinksOnDiscoveryServiceIfNecessary(AssetAdministrationShell shell) { |
169 | | - List<SpecificAssetId> linksToAdd = new ArrayList<>(shell.getAssetInformation().getSpecificAssetIds()); |
170 | | - if(shell.getAssetInformation().getGlobalAssetId() != null){ |
| 176 | + if (shell.getAssetInformation() == null) return; |
| 177 | + |
| 178 | + List<SpecificAssetId> linksToAdd; |
| 179 | + if (shell.getAssetInformation().getSpecificAssetIds() != null) { |
| 180 | + linksToAdd = new ArrayList<>(shell.getAssetInformation().getSpecificAssetIds()); |
| 181 | + } else { |
| 182 | + linksToAdd = new ArrayList<>(); |
| 183 | + } |
| 184 | + |
| 185 | + if (shell.getAssetInformation().getGlobalAssetId() != null) { |
171 | 186 | linksToAdd.add(getGlobalAssetIdAsSpecificAssetId(shell)); |
172 | 187 | } |
173 | | - if(!linksToAdd.isEmpty()){ |
| 188 | + |
| 189 | + if(!linksToAdd.isEmpty()) { |
174 | 190 | try { |
175 | 191 | discoveryApi.createAllAssetLinksById(shell.getId(), linksToAdd); |
176 | 192 | } catch (Exception e) { |
177 | 193 | decorated.deleteAas(shell.getId()); |
| 194 | + logger.error("Failed to link asset in discovery service for AAS ID {}", shell.getId(), e); |
178 | 195 | throw new RepositoryDiscoveryLinkException(shell.getId(), e); |
179 | 196 | } |
180 | 197 | } |
181 | 198 | } |
182 | 199 |
|
183 | 200 | private static boolean specificAssetIdsUpdated(AssetAdministrationShell shell, AssetAdministrationShell oldShell) { |
184 | | - return !(oldShell.getAssetInformation().getSpecificAssetIds() != null && oldShell.getAssetInformation().getSpecificAssetIds().equals(shell.getAssetInformation().getSpecificAssetIds())); |
| 201 | + return !(oldShell.getAssetInformation() != null && |
| 202 | + oldShell.getAssetInformation().getSpecificAssetIds() != null && |
| 203 | + oldShell.getAssetInformation().getSpecificAssetIds().equals( |
| 204 | + shell.getAssetInformation().getSpecificAssetIds())); |
185 | 205 | } |
186 | 206 |
|
187 | 207 | private static boolean isGlobalAssetIdUpdated(AssetAdministrationShell shell, AssetAdministrationShell oldShell) { |
188 | | - return !(oldShell.getAssetInformation().getGlobalAssetId() != null && oldShell.getAssetInformation().getGlobalAssetId().equals(shell.getAssetInformation().getGlobalAssetId())); |
| 208 | + return !(oldShell.getAssetInformation() != null && |
| 209 | + oldShell.getAssetInformation().getGlobalAssetId() != null && |
| 210 | + oldShell.getAssetInformation().getGlobalAssetId().equals( |
| 211 | + shell.getAssetInformation().getGlobalAssetId())); |
189 | 212 | } |
190 | 213 |
|
191 | 214 | } |
0 commit comments