2 * Copyright © 2016-2018 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.sdc.translator.services.heattotosca.impl.functiontranslation;
19 import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition;
20 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
21 import org.openecomp.sdc.tosca.datatypes.ToscaArtifactType;
22 import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
23 import org.openecomp.sdc.tosca.services.ToscaConstants;
24 import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
25 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
26 import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
33 public class FunctionTranslationGetFileImpl implements FunctionTranslation {
34 private static ArtifactDefinition createArtifactDefinition(Object function,
35 ToscaFileOutputService toscaFileOutputService) {
36 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
37 artifactDefinition.setType(ToscaArtifactType.NATIVE_DEPLOYMENT);
38 artifactDefinition.setFile("../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);
39 return artifactDefinition;
43 public Object translateFunction(FunctionTranslator functionTranslator) {
45 String file = ((String) functionTranslator.getFunctionValue()).replace("file:///", "");
46 final String artifactId = file.split("\\.")[0];
47 Map<String, Object> returnValue = new HashMap<>();
48 List<String> artifactParameters = new ArrayList<>();
49 artifactParameters.add(ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
50 returnValue.put(ToscaFunctions.GET_ARTIFACT.getDisplayName(), artifactParameters);
51 artifactParameters.add(artifactId);
53 ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
54 if (functionTranslator.getToscaTemplate() instanceof NodeTemplate) {
55 NodeTemplate nodeTemplate = (NodeTemplate) functionTranslator.getToscaTemplate();
56 ArtifactDefinition artifactDefinition = createArtifactDefinition(file, toscaFileOutputService);
57 if (nodeTemplate.getArtifacts() == null) {
58 nodeTemplate.setArtifacts(new HashMap<>());
60 nodeTemplate.getArtifacts().put(artifactId, artifactDefinition);