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