f69e6f70dcbb03bc4cc7702d8401cd32d2ea13f0
[aaf/authz.git] / authz-service / src / main / java / org / onap / aaf / authz / service / api / API_Approval.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 org.onap.aaf.authz.service.api;\r
24 \r
25 import static org.onap.aaf.cssa.rserv.HttpMethods.GET;\r
26 import static org.onap.aaf.cssa.rserv.HttpMethods.PUT;\r
27 \r
28 import javax.servlet.http.HttpServletRequest;\r
29 import javax.servlet.http.HttpServletResponse;\r
30 \r
31 import org.onap.aaf.authz.env.AuthzTrans;\r
32 import org.onap.aaf.authz.facade.AuthzFacade;\r
33 import org.onap.aaf.authz.layer.Result;\r
34 import org.onap.aaf.authz.service.AuthAPI;\r
35 import org.onap.aaf.authz.service.Code;\r
36 import org.onap.aaf.authz.service.mapper.Mapper.API;\r
37 \r
38 import com.att.aft.dme2.internal.jetty.http.HttpStatus;\r
39 \r
40 public class API_Approval {\r
41         // Hide Public Constructor\r
42         private API_Approval() {}\r
43         \r
44         public static void init(AuthAPI authzAPI, AuthzFacade facade) throws Exception {\r
45 \r
46                 /**\r
47                  * Get Approvals by User\r
48                  */\r
49                 authzAPI.route(GET, "/authz/approval/user/:user",API.APPROVALS,\r
50                                 new Code(facade,"Get Approvals by User", true) {\r
51                         @Override\r
52                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
53                                 Result<Void> r = context.getApprovalsByUser(trans, resp, pathParam(req,"user"));\r
54                                 if(r.isOK()) {\r
55                                         resp.setStatus(HttpStatus.OK_200); \r
56                                 } else {\r
57                                         context.error(trans,resp,r);\r
58                                 }                               \r
59                         }                       \r
60                 });\r
61 \r
62                 /**\r
63                  * Get Approvals by Ticket\r
64                  */\r
65                 authzAPI.route(GET, "/authz/approval/ticket/:ticket",API.VOID,new Code(facade,"Get Approvals by Ticket ", true) {\r
66                         @Override\r
67                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
68                                 Result<Void> r = context.getApprovalsByTicket(trans, resp, pathParam(req,"ticket"));\r
69                                 if(r.isOK()) {\r
70                                         resp.setStatus(HttpStatus.OK_200);\r
71                                 } else {\r
72                                         context.error(trans,resp,r);\r
73                                 }                               \r
74                         }                       \r
75                 });\r
76 \r
77                 /**\r
78                  * Get Approvals by Approver\r
79                  */\r
80                 authzAPI.route(GET, "/authz/approval/approver/:approver",API.APPROVALS,new Code(facade,"Get Approvals by Approver", true) {\r
81                         @Override\r
82                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
83                                 Result<Void> r = context.getApprovalsByApprover(trans, resp, pathParam(req,"approver"));\r
84                                 if(r.isOK()) {\r
85                                         resp.setStatus(HttpStatus.OK_200);\r
86                                 } else {\r
87                                                 context.error(trans,resp,r);\r
88                                 }                               \r
89                         }                       \r
90                 });\r
91 \r
92 \r
93                 /**\r
94                  * Update an approval\r
95                  */\r
96                 authzAPI.route(PUT, "/authz/approval",API.APPROVALS,new Code(facade,"Update approvals", true) {\r
97                         @Override\r
98                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
99                                 Result<Void> r = context.updateApproval(trans, req, resp);\r
100                                 if(r.isOK()) {\r
101                                         resp.setStatus(HttpStatus.OK_200);\r
102                                 } else {\r
103                                         context.error(trans,resp,r);\r
104                                 }                               \r
105                         }                       \r
106                 });\r
107         }\r
108 }\r