8e56669c62d7ab27169d32b617a90239675e4c41
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.tosca.csar;
22
23 import com.google.common.collect.ImmutableList;
24 import org.openecomp.sdc.common.errors.Messages;
25 import java.util.Iterator;
26
27 import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE;
28 import static org.openecomp.sdc.tosca.csar.CSARConstants.SOURCE_MF_ATTRIBUTE;
29
30 public class ONAPManifestOnboarding extends AbstractOnboardingManifest implements Manifest {
31
32     @Override
33     protected void processManifest(ImmutableList<String> lines) {
34         super.processManifest(lines);
35         if (errors.isEmpty() && sources.isEmpty()) {
36                 errors.add(Messages.MANIFEST_NO_SOURCES.getErrorMessage());
37         }
38     }
39
40     @Override
41     protected void processMetadata(Iterator<String> iterator) {
42         if(!iterator.hasNext()){
43             return;
44         }
45         String line = iterator.next();
46         if(isEmptyLine(iterator, line)) {
47             return;
48         }
49         String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE);
50         if (isInvalidLine(line, metaSplit)) {
51             return;
52         }
53         if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE)){
54             String value = line.substring((metaSplit[0] + SEPERATOR_MF_ATTRIBUTE).length()).trim();
55             metadata.put(metaSplit[0].trim(),value.trim());
56             processMetadata(iterator);
57         }else if(metaSplit[0].startsWith(SOURCE_MF_ATTRIBUTE)){
58             String value = line.substring((metaSplit[0] + SEPERATOR_MF_ATTRIBUTE).length()).trim();
59             sources.add(value);
60             processMetadata(iterator);
61         }
62     }
63
64 }