2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 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=========================================================
21 package org.openecomp.sdc.tosca.csar;
23 import org.apache.commons.lang3.StringUtils;
24 import org.openecomp.sdc.common.errors.Messages;
26 import java.util.ArrayList;
27 import java.util.List;
29 import java.util.Optional;
31 import static org.openecomp.sdc.tosca.csar.CSARConstants.ASD_MANIFEST_META_ENTRIES;
32 import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS;
35 * Processes a ASD Manifest.
37 public class AsdManifestOnboarding extends SOL004ManifestOnboarding {
40 protected boolean isMetadataEntry(final String metadataEntry) {
41 final Optional<ManifestTokenType> manifestTokenType = ManifestTokenType.parse(metadataEntry);
42 return manifestTokenType.map(ManifestTokenType::isMetadataAsdEntry).orElse(false);
46 * Processes {@link ManifestTokenType#SOURCE} entries in {@link ManifestTokenType#NON_MANO_ARTIFACT_SETS}.
48 * @return A list of sources paths
50 protected List<String> readNonManoSourceList() {
51 final List<String> nonManoSourceList = new ArrayList<>();
52 while (getCurrentLine().isPresent()) {
53 final ManifestTokenType manifestTokenType = detectLineEntry().orElse(null);
54 if (!(manifestTokenType == ManifestTokenType.SOURCE || manifestTokenType == ManifestTokenType.VENDOR_NAME || manifestTokenType == ManifestTokenType.ARTIFACT_TYPE)) {
57 if (manifestTokenType == ManifestTokenType.SOURCE) {
58 final String value = readCurrentEntryValue().orElse(null);
59 if (!StringUtils.isEmpty(value)) {
60 nonManoSourceList.add(value);
62 reportError(Messages.MANIFEST_EMPTY_NON_MANO_SOURCE);
66 readNextNonEmptyLine();
68 return nonManoSourceList;
72 * Validates the manifest metadata content, reporting errors found.
74 * @return {@code true} if the metadata content is valid, {@code false} otherwise.
76 protected boolean validateMetadata() {
77 if (metadata.isEmpty()) {
78 reportError(Messages.MANIFEST_NO_METADATA);
81 String key = metadata.keySet().stream().filter(k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k)).findFirst().orElse(null);
82 final ManifestTokenType firstManifestEntryTokenType = ManifestTokenType.parse(key).orElse(null);
83 if (firstManifestEntryTokenType == null) {
84 reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, key);
87 for (final Map.Entry<String, String> manifestEntry : metadata.entrySet()) {
88 final ManifestTokenType manifestEntryTokenType = ManifestTokenType.parse(manifestEntry.getKey()).orElse(null);
89 if (manifestEntryTokenType == null || !manifestEntryTokenType.isMetadataAsdEntry()) {
90 reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, manifestEntry.getKey());
94 if (metadata.entrySet().size() != getMaxAllowedManifestMetaEntries()) {
95 reportError(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT, getMaxAllowedManifestMetaEntries());
101 protected int getMaxAllowedManifestMetaEntries() {
102 return ASD_MANIFEST_META_ENTRIES;