[AAF-21] Updated Copyright Headers for AAF
[aaf/authz.git] / authz-certman / src / main / java / com / att / authz / cm / api / API_Artifact.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.att.authz.cm.api;\r
24 \r
25 import javax.servlet.http.HttpServletRequest;\r
26 import javax.servlet.http.HttpServletResponse;\r
27 \r
28 import com.att.aft.dme2.internal.jetty.http.HttpStatus;\r
29 import com.att.authz.cm.mapper.Mapper.API;\r
30 import com.att.authz.cm.service.CertManAPI;\r
31 import com.att.authz.cm.service.Code;\r
32 import com.att.authz.env.AuthzTrans;\r
33 import com.att.authz.layer.Result;\r
34 import com.att.cssa.rserv.HttpMethods;\r
35 \r
36 /**\r
37  * API Deployment Artifact Apis.. using Redirect for mechanism\r
38  * \r
39  *\r
40  */\r
41 public class API_Artifact {\r
42         private static final String GET_ARTIFACTS = "Get Artifacts";\r
43 \r
44         /**\r
45          * Normal Init level APIs\r
46          * \r
47          * @param cmAPI\r
48          * @param facade\r
49          * @throws Exception\r
50          */\r
51         public static void init(final CertManAPI cmAPI) throws Exception {\r
52                 cmAPI.route(HttpMethods.POST, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,"Create Artifacts") {\r
53                         @Override\r
54                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
55                                 Result<Void> r = context.createArtifacts(trans, req, resp);\r
56                                 if(r.isOK()) {\r
57                                         resp.setStatus(HttpStatus.CREATED_201);\r
58                                 } else {\r
59                                         context.error(trans,resp,r);\r
60                                 }\r
61                         }\r
62                 });\r
63                 \r
64                 cmAPI.route(HttpMethods.GET, "/cert/artifacts/:mechid/:machine", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) {\r
65                         @Override\r
66                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
67                                 \r
68                                 Result<Void> r = context.readArtifacts(trans, resp, pathParam(req,":mechid"), pathParam(req,":machine"));\r
69                                 if(r.isOK()) {\r
70                                         resp.setStatus(HttpStatus.CREATED_201);\r
71                                 } else {\r
72                                         context.error(trans,resp,r);\r
73                                 }\r
74                         }\r
75                 });\r
76 \r
77                 cmAPI.route(HttpMethods.GET, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) {\r
78                         @Override\r
79                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
80                                 Result<Void> r = context.readArtifacts(trans, req, resp);\r
81                                 if(r.isOK()) {\r
82                                         resp.setStatus(HttpStatus.CREATED_201);\r
83                                 } else {\r
84                                         context.error(trans,resp,r);\r
85                                 }\r
86                         }\r
87                 });\r
88 \r
89                 cmAPI.route(HttpMethods.PUT, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,"Update Artifacts") {\r
90                         @Override\r
91                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
92                                 Result<Void> r = context.updateArtifacts(trans, req, resp);\r
93                                 if(r.isOK()) {\r
94                                         resp.setStatus(HttpStatus.OK_200);\r
95                                 } else {\r
96                                         context.error(trans,resp,r);\r
97                                 }\r
98                         }\r
99                 });\r
100 \r
101                 cmAPI.route(HttpMethods.DELETE, "/cert/artifacts/:mechid/:machine", API.VOID, new Code(cmAPI,"Delete Artifacts") {\r
102                         @Override\r
103                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
104                                 Result<Void> r = context.deleteArtifacts(trans, resp, \r
105                                                 pathParam(req, ":mechid"), pathParam(req,":machine"));\r
106                                 if(r.isOK()) {\r
107                                         resp.setStatus(HttpStatus.OK_200);\r
108                                 } else {\r
109                                         context.error(trans,resp,r);\r
110                                 }\r
111                         }\r
112                 });\r
113                 \r
114 \r
115                 cmAPI.route(HttpMethods.DELETE, "/cert/artifacts", API.VOID, new Code(cmAPI,"Delete Artifacts") {\r
116                         @Override\r
117                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
118                                 Result<Void> r = context.deleteArtifacts(trans, req, resp);\r
119                                 if(r.isOK()) {\r
120                                         resp.setStatus(HttpStatus.OK_200);\r
121                                 } else {\r
122                                         context.error(trans,resp,r);\r
123                                 }\r
124                         }\r
125                 });\r
126                 \r
127 \r
128         }\r
129 }\r