ListActivity,Rename.java-removing the useless assignments
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / perm / Rename.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.cmd.perm;
23
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.URLEncoder;
27
28 import org.onap.aaf.auth.cmd.AAFcli;
29 import org.onap.aaf.auth.cmd.Cmd;
30 import org.onap.aaf.auth.cmd.Param;
31 import org.onap.aaf.auth.rserv.HttpMethods;
32 import org.onap.aaf.cadi.CadiException;
33 import org.onap.aaf.cadi.LocatorException;
34 import org.onap.aaf.cadi.client.Future;
35 import org.onap.aaf.cadi.client.Rcli;
36 import org.onap.aaf.cadi.client.Retryable;
37 import org.onap.aaf.cadi.config.Config;
38 import org.onap.aaf.misc.env.APIException;
39
40 import aaf.v2_0.PermRequest;
41
42 public class Rename extends Cmd {
43     public Rename(Perm parent) {
44         super(parent,"rename",
45                 new Param("type",true),
46                 new Param("instance",true),
47                 new Param("action", true),
48                 new Param("new type",true),
49                 new Param("new instance",true),
50                 new Param("new action", true)
51                 );
52     }
53
54     @Override
55     public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
56         return same(new Retryable<Integer>() {
57             @Override
58             public Integer code(Rcli<?> client) throws CadiException, APIException {
59                 int idx = index;
60                 String origType = args[idx++];
61                 String origInstance = args[idx++];
62                 String origAction = args[idx++];
63
64                 //Create new permission
65                 PermRequest pr = new PermRequest();
66                 pr.setType(args[idx++]);
67                 pr.setInstance(args[idx++]);
68                 pr.setAction(args[idx]);
69
70                 // Set Start/End commands
71                 setStartEnd(pr);
72                 try {
73                     Future<PermRequest> fp = client.update(
74                             "/authz/perm/"+
75                             origType+ '/' +
76                             URLEncoder.encode(origInstance,Config.UTF_8) + '/' +
77                             origAction,
78                             getDF(PermRequest.class),
79                             pr
80                             );
81                     int rv;
82                     if (fp.get(AAFcli.timeout())) {
83                         rv = fp.code();
84                         pw().println("Updated Permission");
85                     } else {
86                         rv = fp.code();
87                         if (rv==202) {
88                             pw().println("Permission Update Accepted, but requires Approvals before actualizing");
89                         } else {
90                             error(fp);
91                         }
92                     }
93                     return rv;
94                 } catch (UnsupportedEncodingException e) {
95                     throw new CadiException(e);
96                 }
97             }
98         });
99
100     }
101
102     @Override
103     public void detailedHelp(int indent, StringBuilder sb) {
104         detailLine(sb,indent,"Rename a Permission from:");
105         detailLine(sb,indent+2,"<type> <instance> <action>");
106         detailLine(sb,indent,"to:");
107         detailLine(sb,indent+2,"<new type> <new instance> <new action>");
108         sb.append('\n');
109         detailLine(sb,indent,"Namespace must be the same in <type> and <new type>");
110         detailLine(sb,indent+4,"see Create for definitions of type,instance and action");
111         api(sb,indent,HttpMethods.PUT,"authz/perm/<type>/<instance>/<action>",PermRequest.class,true);
112     }
113 }