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 permFormat = "%-30s %-30s %-10s\n";
38 private static final Comparator<aaf.v2_0.Perm> permCompare = new Comparator<aaf.v2_0.Perm>() {
40 public int compare(aaf.v2_0.Perm a, aaf.v2_0.Perm b) {
42 if ((rc=a.getType().compareTo(b.getType()))!=0) {
45 if ((rc=a.getInstance().compareTo(b.getInstance()))!=0) {
48 return a.getAction().compareTo(b.getAction());
51 public List(Perm parent) {
54 cmds.add(new ListByUser(this));
55 cmds.add(new ListByName(this));
56 cmds.add(new ListByNS(this));
57 cmds.add(new ListByRole(this));
58 cmds.add(new ListActivity(this));
60 // Package Level on purpose
61 abstract class ListPerms extends Retryable<Integer> {
62 protected int list(Future<Perms> fp,String header, String parentPerm) throws CadiException {
63 if (fp.get(AAFcli.timeout())) {
64 report(fp,header, parentPerm);
72 void report(Future<Perms> fp, String ... str) {
74 if (this.aafcli.isDetailed()) {
75 String format = "%-36s %-30s %-15s\n";
76 String descFmt = " %-75s\n";
77 reportColHead(format + descFmt,"[PERM NS].Type","Instance","Action", "Description");
78 Collections.sort(fp.value.getPerm(),permCompare);
79 for (aaf.v2_0.Perm p : fp.value.getPerm()) {
80 String pns = p.getNs();
88 '['+pns + "]." + p.getType().substring(pns.length()+1),
92 String desc = p.getDescription();
93 if (desc!=null && desc.length()>0) {
94 pw().format(descFmt,p.getDescription());
99 String format = reportColHead(permFormat,"PERM Type","Instance","Action");
101 Collections.sort(fp.value.getPerm(),permCompare);
102 for (aaf.v2_0.Perm p : fp.value.getPerm()) {