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