2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils;
22 import java.util.ArrayList;
23 import java.util.List;
25 import java.util.stream.Stream;
26 import org.openecomp.sdc.be.config.NonManoArtifactType;
27 import org.openecomp.sdc.tosca.csar.Manifest;
28 import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
29 import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
31 public class FileExtractor {
33 private final InternalFilesFilter internalFilesFilter;
34 private final String etsiEntryManifestFilePath;
35 private final OnboardingPackageContentHandler contentHandler;
37 public FileExtractor(String etsiEntryManifestPath, OnboardingPackageContentHandler contentHandler) {
38 this(etsiEntryManifestPath, contentHandler, new InternalFilesFilter());
41 FileExtractor(String etsiEntryManifestPath, OnboardingPackageContentHandler contentHandler, InternalFilesFilter internalFilesFilter) {
42 this.etsiEntryManifestFilePath = etsiEntryManifestPath;
43 this.contentHandler = contentHandler;
44 this.internalFilesFilter = internalFilesFilter;
47 public Stream<byte[]> findFiles(NonManoArtifactType fileType) {
48 Map<String, List<String>> nonManoSources = extractNonManoSources();
49 List<String> pathsToSources = nonManoSources.getOrDefault(fileType.getType(), new ArrayList<>());
50 List<String> pathsToLocalFiles = internalFilesFilter.filter(pathsToSources);
51 return pathsToLocalFiles.stream().map(contentHandler::getFileContent);
54 private Map<String, List<String>> extractNonManoSources() {
55 Manifest onboardingManifest = new SOL004ManifestOnboarding();
56 onboardingManifest.parse(contentHandler.getFileContentAsStream(etsiEntryManifestFilePath));
57 return onboardingManifest.getNonManoSources();