AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-certman / src / main / java / org / onap / aaf / auth / cm / api / API_Artifact.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.cm.api;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.eclipse.jetty.http.HttpStatus;
28 import org.onap.aaf.auth.cm.AAF_CM;
29 import org.onap.aaf.auth.cm.mapper.Mapper.API;
30 import org.onap.aaf.auth.cm.service.Code;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.layer.Result;
33 import org.onap.aaf.auth.rserv.HttpMethods;
34
35 /**
36  * API Deployment Artifact Apis.. using Redirect for mechanism
37  * 
38  * @author Jonathan
39  *
40  */
41 public class API_Artifact {
42         private static final String GET_ARTIFACTS = "Get Artifacts";
43
44         /**
45          * Normal Init level APIs
46          * 
47          * @param cmAPI
48          * @param facade
49          * @throws Exception
50          */
51         public static void init(final AAF_CM cmAPI) throws Exception {
52                 cmAPI.route(HttpMethods.POST, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,"Create Artifacts") {
53                         @Override
54                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
55                                 Result<Void> r = context.createArtifacts(trans, req, resp);
56                                 if(r.isOK()) {
57                                         resp.setStatus(HttpStatus.CREATED_201);
58                                 } else {
59                                         context.error(trans,resp,r);
60                                 }
61                         }
62                 });
63
64                 /**
65                  * Use Query Params to get Artifacts by Machine or MechID
66                  */
67                 cmAPI.route(HttpMethods.GET, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) {
68                         @Override
69                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
70                                 Result<Void> r = context.readArtifacts(trans, req, resp);
71                                 if(r.isOK()) {
72                                         resp.setStatus(HttpStatus.OK_200);
73                                 } else {
74                                         context.error(trans,resp,r);
75                                 }
76                         }
77                 });
78
79
80                 cmAPI.route(HttpMethods.GET, "/cert/artifacts/:mechid/:machine", API.ARTIFACTS, new Code(cmAPI,GET_ARTIFACTS) {
81                         @Override
82                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
83                                 
84                                 Result<Void> r = context.readArtifacts(trans, resp, pathParam(req,":mechid"), pathParam(req,":machine"));
85                                 if(r.isOK()) {
86                                         resp.setStatus(HttpStatus.OK_200);
87                                 } else {
88                                         context.error(trans,resp,r);
89                                 }
90                         }
91                 });
92                 
93                 
94                 cmAPI.route(HttpMethods.PUT, "/cert/artifacts", API.ARTIFACTS, new Code(cmAPI,"Update Artifacts") {
95                         @Override
96                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
97                                 Result<Void> r = context.updateArtifacts(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                 cmAPI.route(HttpMethods.DELETE, "/cert/artifacts/:mechid/:machine", API.VOID, new Code(cmAPI,"Delete Artifacts") {
107                         @Override
108                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
109                                 Result<Void> r = context.deleteArtifacts(trans, resp, 
110                                                 pathParam(req, ":mechid"), pathParam(req,":machine"));
111                                 if(r.isOK()) {
112                                         resp.setStatus(HttpStatus.OK_200);
113                                 } else {
114                                         context.error(trans,resp,r);
115                                 }
116                         }
117                 });
118                 
119
120                 cmAPI.route(HttpMethods.DELETE, "/cert/artifacts", API.VOID, new Code(cmAPI,"Delete Artifacts") {
121                         @Override
122                         public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
123                                 Result<Void> r = context.deleteArtifacts(trans, req, resp);
124                                 if(r.isOK()) {
125                                         resp.setStatus(HttpStatus.OK_200);
126                                 } else {
127                                         context.error(trans,resp,r);
128                                 }
129                         }
130                 });
131                 
132
133         }
134 }