2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * 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.
17 package org.openecomp.core.impl;
19 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
20 import org.openecomp.core.converter.datatypes.CsarFileTypes;
21 import org.openecomp.core.utilities.file.FileContentHandler;
22 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
24 import java.util.HashMap;
27 import static org.openecomp.core.converter.datatypes.Constants.globalStName;
28 import static org.openecomp.core.converter.datatypes.Constants.mainStName;
30 public class ToscaConverterImpl extends AbstractToscaConverter {
33 public ToscaServiceModel convert(FileContentHandler fileContentHandler) {
34 Map<String, byte[]> csarFiles = new HashMap<>(fileContentHandler.getFiles());
35 ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
36 Map<String, ServiceTemplate> serviceTemplates = new HashMap<>();
37 FileContentHandler artifacts = new FileContentHandler();
38 GlobalSubstitutionServiceTemplate gsst = new GlobalSubstitutionServiceTemplate();
39 csarFiles.putAll(fileContentHandler.getFiles());
40 for (Map.Entry<String, byte[]> fileEntry : csarFiles.entrySet()) {
41 CsarFileTypes fileType = getFileType(fileEntry.getKey());
43 case mainServiceTemplate:
44 handleServiceTemplate(mainStName, fileEntry.getKey(), csarFiles, serviceTemplates);
47 case globalServiceTemplate:
48 handleServiceTemplate(globalStName, fileEntry.getKey(), csarFiles, serviceTemplates);
53 getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue());
57 handleDefintionTemplate(fileEntry.getKey(), csarFiles, gsst);
64 handleMetadataFile(csarFiles);
65 updateToscaServiceModel(toscaServiceModel, serviceTemplates, artifacts, gsst, csarFiles, mainStName);
66 return toscaServiceModel;