3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2021 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdc.be.tosca;
24 import java.nio.file.Path;
25 import lombok.AccessLevel;
26 import lombok.NoArgsConstructor;
27 import org.apache.commons.lang.StringUtils;
30 * Helper class for TOSCA default imports.
32 @NoArgsConstructor(access = AccessLevel.PRIVATE)
33 public class ToscaDefaultImportHelper {
36 * Add the model as a file prefix in the given path, e.g.: "path/to/entry.yaml -> path/to/modelId-entry.yaml".
38 * @param originalPath the entry original path
39 * @param modelId the model id to add as prefix
40 * @return the modified file path with a model prefix.
42 public static Path addModelAsFilePrefix(final Path originalPath, final String modelId) {
43 if (StringUtils.isEmpty(modelId)) {
46 final var fileName = originalPath.getFileName().toString();
47 final var newFileName = String.format("%s-%s", modelId, fileName);
48 if (originalPath.getParent() == null) {
49 return Path.of(newFileName);
51 return originalPath.getParent().resolve(newFileName);