2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
19 package org.openecomp.sdc.be.config;
21 import java.util.List;
22 import java.util.Optional;
23 import java.util.stream.Collectors;
24 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
27 * Singleton that manages the artifact type configuration
29 public class ArtifactConfigManager {
31 public static final ArtifactConfigManager INSTANCE = new ArtifactConfigManager();
33 private ArtifactConfigManager() {
36 public static ArtifactConfigManager getInstance() {
41 * Find an artifact configuration by artifact type.
43 * @param type the artifact type
44 * @return the artifact configuration if the type exists
46 public Optional<ArtifactConfiguration> find(final String type) {
47 final List<ArtifactConfiguration> artifactConfigurationList = getConfiguration();
48 return artifactConfigurationList.stream().filter(artifactConfiguration -> artifactConfiguration.getType().equals(type)).findFirst();
52 * Find an artifact configuration by artifact type, that supports the artifact category/group and component type.
54 * @param type the artifact type
55 * @param artifactGroup the artifact category/group
56 * @param componentType the component type
57 * @return the artifact configuration if it matches the provided filter
59 public Optional<ArtifactConfiguration> find(final String type, final ArtifactGroupTypeEnum artifactGroup, final ComponentType componentType) {
60 final ArtifactConfiguration artifactConfiguration = find(type).orElse(null);
61 if (artifactConfiguration == null) {
62 return Optional.empty();
64 final boolean hasCategory = artifactConfiguration.hasSupport(artifactGroup);
66 return Optional.empty();
68 final boolean hasComponentType = artifactConfiguration.hasSupport(componentType);
69 if (!hasComponentType) {
70 return Optional.empty();
72 return Optional.of(artifactConfiguration);
76 * Find all artifact configuration that supports an artifact category/group and a component type.
78 * @param artifactGroup the artifact group/category
79 * @param componentType the component type
80 * @return the artifact configurations that matches the filter
82 public List<ArtifactConfiguration> findAll(final ArtifactGroupTypeEnum artifactGroup, final ComponentType componentType) {
83 final List<ArtifactConfiguration> artifactConfigurationList = ConfigurationManager.getConfigurationManager().getConfiguration()
85 return artifactConfigurationList.stream()
86 .filter(artifactConfiguration1 -> artifactConfiguration1.hasSupport(artifactGroup) && artifactConfiguration1.hasSupport(componentType))
87 .collect(Collectors.toList());
91 * Find all artifact configuration that supports an artifact category/group.
93 * @param artifactGroup the artifact category/group
94 * @return the artifact configurations that matches the filter
96 public List<ArtifactConfiguration> findAll(final ArtifactGroupTypeEnum artifactGroup) {
97 final List<ArtifactConfiguration> artifactConfigurationList = ConfigurationManager.getConfigurationManager().getConfiguration()
99 return artifactConfigurationList.stream().filter(artifactConfiguration1 -> artifactConfiguration1.hasSupport(artifactGroup))
100 .collect(Collectors.toList());
104 * Find all artifact configuration that supports a component type.
106 * @param componentType the component type
107 * @return the artifact configurations that matches the filter
109 public List<ArtifactConfiguration> findAll(final ComponentType componentType) {
110 final List<ArtifactConfiguration> artifactConfigurationList = ConfigurationManager.getConfigurationManager().getConfiguration()
112 return artifactConfigurationList.stream().filter(artifactConfiguration1 -> artifactConfiguration1.hasSupport(componentType))
113 .collect(Collectors.toList());
117 * Gets the artifact configuration list.
119 * @return the artifact configuration list.
121 public List<ArtifactConfiguration> getConfiguration() {
122 return ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();