6f06289d969897884389501a41e238b0968b77b3
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar;
22
23 import org.openecomp.sdc.logging.api.Logger;
24 import org.openecomp.sdc.logging.api.LoggerFactory;
25 import java.io.InputStream;
26 import java.io.IOException;
27 import org.apache.commons.io.IOUtils;
28 import java.util.List;
29
30 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
31 import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE;
32
33 public class OnboardingToscaMetadata {
34
35   private static final Logger LOGGER = LoggerFactory.getLogger(OnboardingToscaMetadata.class);
36   private String entryDefinitionsPath;
37
38   public OnboardingToscaMetadata(InputStream is) throws IOException {
39       parseToscaMetadataFile(is);
40   }
41
42   private void parseToscaMetadataFile(InputStream st) throws IOException {
43
44     try {
45       List<String> metadataLines = IOUtils.readLines(st,"utf-8");
46
47       for (String line : metadataLines) {
48         line = line.trim();
49         if (line.startsWith(TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE)) {
50
51           entryDefinitionsPath = line.replaceAll(TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE, "")
52               .trim();
53           break;
54
55         }
56       }
57
58     } catch (IOException e) {
59       LOGGER.error(e.getMessage(), e);
60       throw new IOException("Invalid TOSCA Metadata file", e);
61
62     }
63
64   }
65
66   public String getEntryDefinitionsPath() {
67     return entryDefinitionsPath;
68   }
69 }
70