99c539357e531ca10aa0ad04f91f5c35251cc42c
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / ServiceUploadServlet.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 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import io.swagger.v3.oas.annotations.tags.Tag;
24 import io.swagger.v3.oas.annotations.tags.Tags;
25 import javax.inject.Singleton;
26 import javax.ws.rs.Path;
27 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
28 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
29 import org.openecomp.sdc.be.impl.ComponentsUtils;
30 import org.openecomp.sdc.be.impl.ServletUtils;
31 import org.openecomp.sdc.common.log.wrappers.Logger;
32
33 /**
34  * Root service (exposed at "/" path)
35  */
36
37 //upload Service model by Shiyong1989@hotmail.com
38 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
39 @Path("/v1/catalog/uploadservice")
40 @Tags({@Tag(name = "SDCE-2 APIs")})
41 @Singleton
42 public class ServiceUploadServlet extends AbstractValidationsServlet {
43
44     public static final String NORMATIVE_TYPE_SERVICE = "multipart";
45     public static final String CSAR_TYPE_SERVICE = "csar";
46     public static final String USER_TYPE_SERVICE = "user-service";
47     public static final String USER_TYPE_SERVICE_UI_IMPORT = "user-servcie-ui-import";
48     private static final Logger log = Logger.getLogger(ServiceUploadServlet.class);
49
50     public ServiceUploadServlet(ComponentInstanceBusinessLogic componentInstanceBL,
51                                 ComponentsUtils componentsUtils, ServletUtils servletUtils, ResourceImportManager resourceImportManager) {
52         super(componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
53     }
54
55     public enum ServiceAuthorityTypeEnum {
56         NORMATIVE_TYPE_BE(NORMATIVE_TYPE_SERVICE, true, false), USER_TYPE_BE(USER_TYPE_SERVICE, true, true), USER_TYPE_UI(USER_TYPE_SERVICE_UI_IMPORT,
57             false, true), CSAR_TYPE_BE(CSAR_TYPE_SERVICE, true, true);
58         private String urlPath;
59         private boolean isBackEndImport, isUserTypeService;
60
61         private ServiceAuthorityTypeEnum(String urlPath, boolean isBackEndImport, boolean isUserTypeService) {
62             this.urlPath = urlPath;
63             this.isBackEndImport = isBackEndImport;
64             this.isUserTypeService = isUserTypeService;
65         }
66
67         public static ServiceAuthorityTypeEnum findByUrlPath(String urlPath) {
68             ServiceAuthorityTypeEnum found = null;
69             for (ServiceAuthorityTypeEnum curr : ServiceAuthorityTypeEnum.values()) {
70                 if (curr.getUrlPath().equals(urlPath)) {
71                     found = curr;
72                     break;
73                 }
74             }
75             return found;
76         }
77
78         public String getUrlPath() {
79             return urlPath;
80         }
81
82         public boolean isBackEndImport() {
83             return isBackEndImport;
84         }
85
86         public boolean isUserTypeService() {
87             return isUserTypeService;
88         }
89     }
90 }