2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nokia
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=========================================================
20 package org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.validation;
22 import static org.openecomp.sdc.common.errors.Messages.MANIFEST_VALIDATION_HELM_IS_BASE_MISSING;
23 import static org.openecomp.sdc.common.errors.Messages.MANIFEST_VALIDATION_HELM_IS_BASE_NOT_SET;
24 import static org.openecomp.sdc.common.errors.Messages.MANIFEST_VALIDATION_HELM_IS_BASE_NOT_UNIQUE;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
31 public class CnfPackageValidator {
33 public List<String> validateHelmPackage(List<FileData> modules) {
34 List<String> messages = Collections.emptyList();
36 if (modules != null && !modules.isEmpty()) {
37 Stats stats = calculateStats(modules);
38 messages = createErrorMessages(stats);
44 private Stats calculateStats(List<FileData> modules) {
45 Stats stats = new Stats();
46 for (FileData mod : modules) {
47 if (mod.getBase() == null) {
49 } else if (mod.getBase()) {
56 private List<String> createErrorMessages(Stats stats) {
57 List<String> messages = new ArrayList<>();
59 if (stats.without > 0) {
60 messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_MISSING.formatMessage(stats.without));
63 if (stats.base == 0) {
64 messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_NOT_SET.getErrorMessage());
65 } else if (stats.base > 1) {
66 messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_NOT_UNIQUE.getErrorMessage());
72 private static class Stats {
75 private int without = 0;