|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (C) 2026 the Eclipse BaSyx Authors |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | + * a copy of this software and associated documentation files (the |
| 6 | + * "Software"), to deal in the Software without restriction, including |
| 7 | + * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | + * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | + * permit persons to whom the Software is furnished to do so, subject to |
| 10 | + * the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be |
| 13 | + * included in all copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 19 | + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 20 | + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 21 | + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | + * |
| 23 | + * SPDX-License-Identifier: MIT |
| 24 | + ******************************************************************************/ |
| 25 | + |
| 26 | + |
| 27 | +package org.eclipse.digitaltwin.basyx.aasrepository.client.internal; |
| 28 | + |
| 29 | +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonMapperFactory; |
| 30 | +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.SimpleAbstractTypeResolverFactory; |
| 31 | +import org.eclipse.digitaltwin.basyx.client.internal.authorization.TokenManager; |
| 32 | +import org.eclipse.digitaltwin.basyx.client.internal.ApiClient; |
| 33 | +import org.eclipse.digitaltwin.basyx.client.internal.ApiClientPool; |
| 34 | + |
| 35 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 36 | + |
| 37 | +/** |
| 38 | + * Factory class for creating instances of {@link AssetAdministrationShellRepositoryApi} using an {@link ApiClientPool}. |
| 39 | + * |
| 40 | + * @author koort |
| 41 | + */ |
| 42 | +public class AssetAdministrationShellRepositoryApiFactory { |
| 43 | + |
| 44 | + private AssetAdministrationShellRepositoryApiFactory() { |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with default configuration. |
| 49 | + * |
| 50 | + * @param repositoryBaseUri the base URI of the AAS repository |
| 51 | + * @return a new AssetAdministrationShellRepositoryApi instance |
| 52 | + */ |
| 53 | + public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri) { |
| 54 | + return create(repositoryBaseUri, null, null); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with the specified ObjectMapper. |
| 59 | + * |
| 60 | + * @param repositoryBaseUri the base URI of the AAS repository |
| 61 | + * @param objectMapper the ObjectMapper |
| 62 | + * @return a new AssetAdministrationShellRepositoryApi instance |
| 63 | + */ |
| 64 | + public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri, ObjectMapper objectMapper) { |
| 65 | + return create(repositoryBaseUri, objectMapper, null); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with the specified TokenManager. |
| 70 | + * |
| 71 | + * @param repositoryBaseUri the base URI of the AAS repository |
| 72 | + * @param tokenManager the TokenManager |
| 73 | + * @return a new AssetAdministrationShellRepositoryApi instance |
| 74 | + */ |
| 75 | + public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri, TokenManager tokenManager) { |
| 76 | + return create(repositoryBaseUri, null, tokenManager); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Creates a new instance of {@link AssetAdministrationShellRepositoryApi} with the specified ObjectMapper and TokenManager. |
| 81 | + * |
| 82 | + * @param repositoryBaseUri the base URI of the AAS repository |
| 83 | + * @param objectMapper the ObjectMapper |
| 84 | + * @param tokenManager the TokenManager |
| 85 | + * @return a new AssetAdministrationShellRepositoryApi instance |
| 86 | + */ |
| 87 | + public static AssetAdministrationShellRepositoryApi create(String repositoryBaseUri, ObjectMapper objectMapper, TokenManager tokenManager) { |
| 88 | + ObjectMapper mapper = objectMapper != null ? objectMapper : new JsonMapperFactory().create(new SimpleAbstractTypeResolverFactory().create()); |
| 89 | + |
| 90 | + ApiClient apiClient = ApiClientPool.getInstance().getOrCreateAasRepoApiClient(repositoryBaseUri, mapper); |
| 91 | + |
| 92 | + AssetAdministrationShellRepositoryApi repoApi = new AssetAdministrationShellRepositoryApi(apiClient); |
| 93 | + |
| 94 | + if (tokenManager != null) { |
| 95 | + repoApi.setTokenManager(tokenManager); |
| 96 | + } |
| 97 | + |
| 98 | + return repoApi; |
| 99 | + } |
| 100 | +} |
0 commit comments