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=========================================================
19 package org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.validation;
21 import static org.openecomp.sdc.common.errors.Messages.MANIFEST_VALIDATION_HELM_IS_BASE_MISSING;
22 import static org.openecomp.sdc.common.errors.Messages.MANIFEST_VALIDATION_HELM_IS_BASE_NOT_SET;
23 import static org.openecomp.sdc.common.errors.Messages.MANIFEST_VALIDATION_HELM_IS_BASE_NOT_UNIQUE;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
30 public class CnfPackageValidator {
32 public List<String> validateHelmPackage(List<FileData> modules) {
33 List<String> messages = Collections.emptyList();
34 if (modules != null && !modules.isEmpty()) {
35 Stats stats = calculateStats(modules);
36 messages = createErrorMessages(stats);
41 private Stats calculateStats(List<FileData> modules) {
42 Stats stats = new Stats();
43 for (FileData mod : modules) {
44 if (mod.getBase() == null) {
46 } else if (mod.getBase()) {
53 private List<String> createErrorMessages(Stats stats) {
54 List<String> messages = new ArrayList<>();
55 if (stats.without > 0) {
56 messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_MISSING.formatMessage(stats.without));
58 if (stats.base == 0) {
59 messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_NOT_SET.getErrorMessage());
60 } else if (stats.base > 1) {
61 messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_NOT_UNIQUE.getErrorMessage());
66 private static class Stats {
69 private int without = 0;