CSIT Fix for SDC-2585
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / CsarBuildServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.servlets;
22
23 import com.jcabi.aspects.Loggable;
24 import javax.inject.Inject;
25 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
26 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
27 import org.openecomp.sdc.be.impl.ComponentsUtils;
28 import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
29 import org.openecomp.sdc.be.resources.api.IResourceUploader;
30 import org.openecomp.sdc.be.resources.data.ESArtifactData;
31 import org.openecomp.sdc.be.user.UserBusinessLogic;
32 import org.openecomp.sdc.common.log.wrappers.Logger;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.core.Context;
39 import javax.ws.rs.core.Response;
40
41 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
42 @Path("/services")
43 public class CsarBuildServlet extends ToscaDaoServlet {
44
45     private static final Logger log = Logger.getLogger(CsarBuildServlet.class);
46
47     @Inject
48     public CsarBuildServlet(UserBusinessLogic userBusinessLogic,
49         ComponentsUtils componentsUtils,
50         IResourceUploader resourceUploader,
51         DownloadArtifactLogic logic) {
52         super(userBusinessLogic, componentsUtils, resourceUploader, logic);
53     }
54
55     @GET
56     @Path("/{serviceName}/{serviceVersion}")
57     public Response getDefaultTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
58
59         return null;// buildToscaCsar(request, serviceName, serviceVersion);
60
61     }
62
63     @GET
64     @Path("/{serviceName}/{serviceVersion}/csar")
65     public Response getToscaCsarTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
66
67         return null; // buildToscaCsar(request, serviceName, serviceVersion);
68
69     }
70
71
72     public static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
73
74     protected String[] prepareToscaMetaHeader(String serviceName) {
75         return new String[] { "TOSCA-Meta-File-Version: 1.0\n", "CSAR-Version: 1.1\n", "Created-By: INTERWISE\n", "\n", "Entry-Definitions: Definitions/" + serviceName + ".yaml\n", "\n", "Name: Definitions/" + serviceName + ".yaml\n",
76                 "Content-Type: application/vnd.oasis.tosca.definitions.yaml\n" };
77     }
78
79     protected String getAppliactionMime(String fileName) {
80         String mimeType;
81         if (fileName.contains(".sh")) {
82             mimeType = "x-sh";
83         } else if (fileName.contains(".yang")) {
84             mimeType = "yang";
85         }
86
87         else if (fileName.contains(".rar")) {
88             mimeType = "x-rar-compressed";
89         }
90
91         else if (fileName.contains(".zip")) {
92             mimeType = "zip";
93         }
94
95         else if (fileName.contains(".tar")) {
96             mimeType = "x-tar";
97         }
98
99         else if (fileName.contains(".7z")) {
100             mimeType = "x-7z-compressed";
101         }
102
103         else {
104             // Undefined
105             mimeType = "undefined";
106         }
107         return mimeType;
108     }
109
110     protected String getArtifactPath(String nodeTamplateName, ESArtifactData artifactData) {
111         return "Scripts/" + nodeTamplateName + "/" + artifactData.getId();
112     }
113
114     protected String getResourcePath(String resourceName) {
115         return "Definitions/" + resourceName + ".yaml";
116     }
117
118     @Override
119     public Logger getLogger() {
120         return log;
121     }
122
123 }