640f54e67d5ef91dae8bb5c375a925c3e6a79d98
[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 org.openecomp.sdc.be.resources.data.ESArtifactData;
25 import org.openecomp.sdc.common.log.wrappers.Logger;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.Response;
33
34 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
35 @Path("/services")
36 public class CsarBuildServlet extends ToscaDaoServlet {
37
38     private static final Logger log = Logger.getLogger(CsarBuildServlet.class);
39
40     @GET
41     @Path("/{serviceName}/{serviceVersion}")
42     public Response getDefaultTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
43
44         return null;// buildToscaCsar(request, serviceName, serviceVersion);
45
46     }
47
48     @GET
49     @Path("/{serviceName}/{serviceVersion}/csar")
50     public Response getToscaCsarTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
51
52         return null; // buildToscaCsar(request, serviceName, serviceVersion);
53
54     }
55
56
57     public static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
58
59     protected String[] prepareToscaMetaHeader(String serviceName) {
60         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",
61                 "Content-Type: application/vnd.oasis.tosca.definitions.yaml\n" };
62     }
63
64     protected String getAppliactionMime(String fileName) {
65         String mimeType;
66         if (fileName.contains(".sh")) {
67             mimeType = "x-sh";
68         } else if (fileName.contains(".yang")) {
69             mimeType = "yang";
70         }
71
72         else if (fileName.contains(".rar")) {
73             mimeType = "x-rar-compressed";
74         }
75
76         else if (fileName.contains(".zip")) {
77             mimeType = "zip";
78         }
79
80         else if (fileName.contains(".tar")) {
81             mimeType = "x-tar";
82         }
83
84         else if (fileName.contains(".7z")) {
85             mimeType = "x-7z-compressed";
86         }
87
88         else {
89             // Undefined
90             mimeType = "undefined";
91         }
92         return mimeType;
93     }
94
95     protected String getArtifactPath(String nodeTamplateName, ESArtifactData artifactData) {
96         return "Scripts/" + nodeTamplateName + "/" + artifactData.getId();
97     }
98
99     protected String getResourcePath(String resourceName) {
100         return "Definitions/" + resourceName + ".yaml";
101     }
102
103     @Override
104     public Logger getLogger() {
105         return log;
106     }
107
108 }