3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2020 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
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder;
23 * Builder for the TOSCA.meta file in a NSD CSAR
25 public class NsdToscaMetadataBuilder {
27 public static final String CSAR_VERSION = "CSAR-Version";
28 public static final String CREATED_BY = "Created-By";
29 public static final String TOSCA_META_FILE_VERSION = "TOSCA-Meta-File-Version";
30 public static final String ENTRY_DEFINITIONS = "Entry-Definitions";
31 public static final String ETSI_ENTRY_CHANGE_LOG = "ETSI-Entry-Change-Log";
32 public static final String ETSI_ENTRY_MANIFEST = "ETSI-Entry-Manifest";
33 private static final String ATTRIBUTE_SEPARATOR = ": ";
34 private static final String NEW_LINE = "\n";
35 private final StringBuilder builder = new StringBuilder();
36 private String csarVersion;
37 private String createdBy;
38 private String entryDefinitionsPath;
39 private String toscaMetaVersion;
40 private String entryManifest;
41 private String changeLogPath;
44 * Sets a value for the {@link #CSAR_VERSION} metadata entry.
46 * @param csarVersion the value
47 * @return the builder instance
49 public NsdToscaMetadataBuilder withCsarVersion(final String csarVersion) {
50 this.csarVersion = csarVersion;
55 * Sets a value for the {@link #CREATED_BY} metadata entry.
57 * @param createdBy the value
58 * @return the builder instance
60 public NsdToscaMetadataBuilder withCreatedBy(final String createdBy) {
61 this.createdBy = createdBy;
66 * Sets a value for the {@link #TOSCA_META_FILE_VERSION} metadata entry.
68 * @param toscaMetaVersion the value
69 * @return the builder instance
71 public NsdToscaMetadataBuilder withToscaMetaVersion(final String toscaMetaVersion) {
72 this.toscaMetaVersion = toscaMetaVersion;
77 * Sets a value for the {@link #ENTRY_DEFINITIONS} metadata entry.
79 * @param entryDefinitionsPath the value
80 * @return the builder instance
82 public NsdToscaMetadataBuilder withEntryDefinitions(final String entryDefinitionsPath) {
83 this.entryDefinitionsPath = entryDefinitionsPath;
88 * Sets a value for the {@link #ETSI_ENTRY_MANIFEST} metadata entry.
90 * @param entryManifest the value
91 * @return the builder instance
93 public NsdToscaMetadataBuilder withEntryManifest(final String entryManifest) {
94 this.entryManifest = entryManifest;
99 * Sets a value for the {@link #ETSI_ENTRY_CHANGE_LOG} metadata entry.
101 * @param changeLogPath the value
102 * @return the builder instance
104 public NsdToscaMetadataBuilder withEntryChangeLog(final String changeLogPath) {
105 this.changeLogPath = changeLogPath;
110 * Builds a string representing the TOSCA metadata content based on provided values.
112 * @return a string representing the TOSCA metadata content
114 public String build() {
115 appendEntry(CSAR_VERSION, csarVersion);
116 appendEntry(CREATED_BY, createdBy);
117 appendEntry(TOSCA_META_FILE_VERSION, toscaMetaVersion);
118 appendEntry(ENTRY_DEFINITIONS, entryDefinitionsPath);
119 appendEntry(ETSI_ENTRY_MANIFEST, entryManifest);
120 appendEntry(ETSI_ENTRY_CHANGE_LOG, changeLogPath);
121 return builder.toString();
124 private void appendEntry(final String entry, final String value) {
126 builder.append(entry).append(ATTRIBUTE_SEPARATOR).append(value).append(NEW_LINE);