2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
23 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
24 import org.openecomp.sdc.tosca.datatypes.ToscaArtifactType;
25 import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
26 import org.openecomp.sdc.tosca.datatypes.model.ArtifactDefinition;
27 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
28 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
29 import org.openecomp.sdc.tosca.datatypes.model.Template;
30 import org.openecomp.sdc.tosca.services.ToscaConstants;
31 import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
32 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
33 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
34 import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
43 * @since December 15, 2016.
45 public class FunctionTranslationGetFileImpl implements FunctionTranslation {
47 public Object translateFunction(ServiceTemplate serviceTemplate,
48 String resourceId, String propertyName, String functionKey,
49 Object functionValue, String heatFileName,
50 HeatOrchestrationTemplate heatOrchestrationTemplate,
51 Template toscaTemplate, TranslationContext context) {
52 String file = ((String) functionValue).replace("file:///", "");
54 final String artifactId = file.split("\\.")[0];
56 returnValue = new HashMap<>();
57 List artifactParameters = new ArrayList();
58 artifactParameters.add(0, ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
59 ((Map) returnValue).put(ToscaFunctions.GET_ARTIFACT.getDisplayName(), artifactParameters);
60 artifactParameters.add(1, artifactId);
62 ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
63 if (toscaTemplate != null) {
64 if (toscaTemplate instanceof NodeTemplate) {
65 NodeTemplate nodeTemplate = (NodeTemplate) toscaTemplate;
66 ArtifactDefinition artifactDefinition =
67 createArtifactDefinition(file, toscaFileOutputService);
68 if (nodeTemplate.getArtifacts() == null) {
69 nodeTemplate.setArtifacts(new HashMap<>());
71 nodeTemplate.getArtifacts().put(artifactId, artifactDefinition);
77 private static ArtifactDefinition createArtifactDefinition(Object function,
78 ToscaFileOutputService
79 toscaFileOutputService) {
80 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
81 artifactDefinition.setType(ToscaArtifactType.NATIVE_DEPLOYMENT);
83 .setFile("../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);
84 return artifactDefinition;