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