2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.cmd.perm;
24 import java.util.Collections;
25 import java.util.Comparator;
27 import org.onap.aaf.auth.cmd.AAFcli;
28 import org.onap.aaf.auth.cmd.BaseCmd;
29 import org.onap.aaf.cadi.CadiException;
30 import org.onap.aaf.cadi.client.Future;
31 import org.onap.aaf.cadi.client.Retryable;
32 import org.onap.aaf.misc.env.APIException;
34 import aaf.v2_0.Perms;
36 public class List extends BaseCmd<Perm> {
37 // private static final String LIST_PERM_DETAILS = "list permission details";
39 public List(Perm parent) {
42 cmds.add(new ListByUser(this));
43 cmds.add(new ListByName(this));
44 cmds.add(new ListByNS(this));
45 cmds.add(new ListByRole(this));
46 cmds.add(new ListActivity(this));
48 // Package Level on purpose
49 abstract class ListPerms extends Retryable<Integer> {
50 protected int list(Future<Perms> fp,String header, String parentPerm) throws CadiException, APIException {
51 if(fp.get(AAFcli.timeout())) {
52 report(fp,header, parentPerm);
60 private static final Comparator<aaf.v2_0.Perm> permCompare = new Comparator<aaf.v2_0.Perm>() {
62 public int compare(aaf.v2_0.Perm a, aaf.v2_0.Perm b) {
64 if((rc=a.getType().compareTo(b.getType()))!=0) {
67 if((rc=a.getInstance().compareTo(b.getInstance()))!=0) {
70 return a.getAction().compareTo(b.getAction());
74 private static final String permFormat = "%-30s %-30s %-10s\n";
76 void report(Future<Perms> fp, String ... str) {
78 if (this.aafcli.isDetailed()) {
79 String format = "%-36s %-30s %-15s\n";
80 String descFmt = " %-75s\n";
81 reportColHead(format + descFmt,"[PERM NS].Type","Instance","Action", "Description");
82 Collections.sort(fp.value.getPerm(),permCompare);
83 for(aaf.v2_0.Perm p : fp.value.getPerm()) {
84 String pns = p.getNs();
92 '['+pns + "]." + p.getType().substring(pns.length()+1),
96 String desc = p.getDescription();
97 if(desc!=null && desc.length()>0) {
98 pw().format(descFmt,p.getDescription());
103 String format = reportColHead(permFormat,"PERM Type","Instance","Action");
105 Collections.sort(fp.value.getPerm(),permCompare);
106 for(aaf.v2_0.Perm p : fp.value.getPerm()) {