2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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=========================================================
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";
34 private static final String ATTRIBUTE_SEPARATOR = ": ";
35 private static final String NEW_LINE = "\n";
37 private final StringBuilder builder = new StringBuilder();
38 private String csarVersion;
39 private String createdBy;
40 private String entryDefinitionsPath;
41 private String toscaMetaVersion;
42 private String entryManifest;
43 private String changeLogPath;
46 * Sets a value for the {@link #CSAR_VERSION} metadata entry.
48 * @param csarVersion the value
49 * @return the builder instance
51 public NsdToscaMetadataBuilder withCsarVersion(final String csarVersion) {
52 this.csarVersion = csarVersion;
57 * Sets a value for the {@link #CREATED_BY} metadata entry.
59 * @param createdBy the value
60 * @return the builder instance
62 public NsdToscaMetadataBuilder withCreatedBy(final String createdBy) {
63 this.createdBy = createdBy;
68 * Sets a value for the {@link #TOSCA_META_FILE_VERSION} metadata entry.
70 * @param toscaMetaVersion the value
71 * @return the builder instance
73 public NsdToscaMetadataBuilder withToscaMetaVersion(final String toscaMetaVersion) {
74 this.toscaMetaVersion = toscaMetaVersion;
79 * Sets a value for the {@link #ENTRY_DEFINITIONS} metadata entry.
81 * @param entryDefinitionsPath the value
82 * @return the builder instance
84 public NsdToscaMetadataBuilder withEntryDefinitions(final String entryDefinitionsPath) {
85 this.entryDefinitionsPath = entryDefinitionsPath;
90 * Sets a value for the {@link #ETSI_ENTRY_MANIFEST} metadata entry.
92 * @param entryManifest the value
93 * @return the builder instance
95 public NsdToscaMetadataBuilder withEntryManifest(final String entryManifest) {
96 this.entryManifest = entryManifest;
101 * Sets a value for the {@link #ETSI_ENTRY_CHANGE_LOG} metadata entry.
103 * @param changeLogPath the value
104 * @return the builder instance
106 public NsdToscaMetadataBuilder withEntryChangeLog(final String changeLogPath) {
107 this.changeLogPath = changeLogPath;
112 * Builds a string representing the TOSCA metadata content based on provided values.
114 * @return a string representing the TOSCA metadata content
116 public String build() {
117 appendEntry(CSAR_VERSION, csarVersion);
118 appendEntry(CREATED_BY, createdBy);
119 appendEntry(TOSCA_META_FILE_VERSION, toscaMetaVersion);
120 appendEntry(ENTRY_DEFINITIONS, entryDefinitionsPath);
121 appendEntry(ETSI_ENTRY_MANIFEST, entryManifest);
122 appendEntry(ETSI_ENTRY_CHANGE_LOG, changeLogPath);
123 return builder.toString();
126 private void appendEntry(final String entry, final String value) {
128 builder.append(entry).append(ATTRIBUTE_SEPARATOR).append(value)