2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2018 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.cmd.perm;
26 import java.util.Collections;
27 import java.util.Comparator;
29 import org.onap.aaf.auth.cmd.AAFcli;
30 import org.onap.aaf.auth.cmd.BaseCmd;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.client.Future;
33 import org.onap.aaf.cadi.client.Retryable;
35 import aaf.v2_0.Perms;
37 public class List extends BaseCmd<Perm> {
38 private static final String permFormat = "%-30s %-30s %-10s\n";
39 private static final Comparator<aaf.v2_0.Perm> permCompare = new Comparator<aaf.v2_0.Perm>() {
41 public int compare(aaf.v2_0.Perm a, aaf.v2_0.Perm b) {
43 if ((rc=a.getType().compareTo(b.getType()))!=0) {
46 if ((rc=a.getInstance().compareTo(b.getInstance()))!=0) {
49 return a.getAction().compareTo(b.getAction());
52 public List(Perm parent) {
55 cmds.add(new ListByUser(this));
56 cmds.add(new ListByName(this));
57 cmds.add(new ListByNS(this));
58 cmds.add(new ListByRole(this));
59 cmds.add(new ListActivity(this));
61 // Package Level on purpose
62 abstract class ListPerms extends Retryable<Integer> {
63 protected int list(Future<Perms> fp,String header, String parentPerm) throws CadiException {
64 if (fp.get(AAFcli.timeout())) {
65 report(fp,header, parentPerm);
73 void report(Future<Perms> fp, String ... str) {
75 if (this.aafcli.isDetailed()) {
76 String format = "%-36s %-30s %-15s\n";
77 String descFmt = " %-75s\n";
78 reportColHead(format + descFmt,"[PERM NS].Type","Instance","Action", "Description");
79 Collections.sort(fp.value.getPerm(),permCompare);
80 for (aaf.v2_0.Perm p : fp.value.getPerm()) {
81 String pns = p.getNs();
89 '['+pns + "]." + p.getType().substring(pns.length()+1),
93 String desc = p.getDescription();
94 if (desc!=null && desc.length()>0) {
95 pw().format(descFmt,p.getDescription());
100 String format = reportColHead(permFormat,"PERM Type","Instance","Action");
102 Collections.sort(fp.value.getPerm(),permCompare);
103 for (aaf.v2_0.Perm p : fp.value.getPerm()) {