1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cmd.ns;
\r
25 import java.util.Collections;
\r
26 import java.util.Comparator;
\r
28 import org.onap.aaf.cmd.BaseCmd;
\r
30 import org.onap.aaf.cadi.client.Future;
\r
31 import org.onap.aaf.inno.env.util.Chrono;
\r
33 import aaf.v2_0.Nss;
\r
34 import aaf.v2_0.Nss.Ns;
\r
35 import aaf.v2_0.Nss.Ns.Attrib;
\r
36 import aaf.v2_0.Perms;
\r
37 import aaf.v2_0.Roles;
\r
38 import aaf.v2_0.Users;
\r
39 import aaf.v2_0.Users.User;
\r
41 public class List extends BaseCmd<NS> {
\r
43 public List(NS parent) {
\r
44 super(parent,"list");
\r
45 cmds.add(new ListByName(this));
\r
47 // TODO: uncomment when on cassandra 2.1.2 if we like cli command to get all ns's
\r
48 // a user is admin or responsible for
\r
49 cmds.add(new ListAdminResponsible(this));
\r
51 cmds.add(new ListActivity(this));
\r
52 cmds.add(new ListUsers(this));
\r
53 cmds.add(new ListChildren(this));
\r
54 cmds.add(new ListNsKeysByAttrib(this));
\r
57 private static final String sformat = " %-72s\n";
\r
58 protected static final String kformat = " %-72s\n";
\r
61 public void report(Future<Nss> fp, String ... str) {
\r
64 pw().println(" *** Namespace Not Found ***");
\r
67 if(fp!=null && fp.value!=null) {
\r
68 for(Ns ns : fp.value.getNs()) {
\r
69 pw().println(ns.getName());
\r
70 if (this.aafcli.isDetailed()) {
\r
71 pw().println(" Description");
\r
72 pw().format(sformat,ns.getDescription()==null?"":ns.getDescription());
\r
74 if(ns.getAdmin().size()>0) {
\r
75 pw().println(" Administrators");
\r
76 for(String admin : ns.getAdmin()) {
\r
77 pw().format(sformat,admin);
\r
80 if(ns.getResponsible().size()>0) {
\r
81 pw().println(" Responsible Parties");
\r
82 for(String responsible : ns.getResponsible()) {
\r
83 pw().format(sformat,responsible);
\r
86 if(ns.getAttrib().size()>0) {
\r
87 pw().println(" Namespace Attributes");
\r
88 for(Attrib attrib : ns.getAttrib()) {
\r
89 StringBuilder sb = new StringBuilder(attrib.getKey());
\r
90 if(attrib.getValue()==null || attrib.getValue().length()>0) {
\r
92 sb.append(attrib.getValue());
\r
94 pw().format(sformat,sb.toString());
\r
102 public void reportName(Future<Nss> fp, String ... str) {
\r
104 if(fp!=null && fp.value!=null) {
\r
105 java.util.List<Ns> nss = fp.value.getNs();
\r
106 Collections.sort(nss, new Comparator<Ns>() {
\r
108 public int compare(Ns ns1, Ns ns2) {
\r
109 return ns1.getName().compareTo(ns2.getName());
\r
114 pw().println(ns.getName());
\r
115 if (this.aafcli.isDetailed() && ns.getDescription() != null) {
\r
116 pw().println(" " + ns.getDescription());
\r
122 public void reportRole(Future<Roles> fr) {
\r
123 if(fr!=null && fr.value!=null && fr.value.getRole().size()>0) {
\r
124 pw().println(" Roles");
\r
125 for(aaf.v2_0.Role r : fr.value.getRole()) {
\r
126 pw().format(sformat,r.getName());
\r
131 private static final String pformat = " %-30s %-24s %-15s\n";
\r
132 public void reportPerm(Future<Perms> fp) {
\r
133 if(fp!=null && fp.value!=null && fp.value.getPerm().size()>0) {
\r
134 pw().println(" Permissions");
\r
135 for(aaf.v2_0.Perm p : fp.value.getPerm()) {
\r
136 pw().format(pformat,p.getType(),p.getInstance(),p.getAction());
\r
142 private static final String cformat = " %-30s %-6s %-24s\n";
\r
143 public void reportCred(Future<Users> fc) {
\r
144 if(fc!=null && fc.value!=null && fc.value.getUser().size()>0) {
\r
145 pw().println(" Credentials");
\r
146 java.util.List<User> users = fc.value.getUser();
\r
147 Collections.sort(users, new Comparator<User>() {
\r
149 public int compare(User u1, User u2) {
\r
150 return u1.getId().compareTo(u2.getId());
\r
153 for(aaf.v2_0.Users.User u : users) {
\r
154 if (this.aafcli.isTest()) {
\r
155 pw().format(sformat,u.getId());
\r
158 switch(u.getType()) {
\r
159 case 1: type = "U/P"; break;
\r
160 case 10: type="Cert"; break;
\r
161 case 200: type="x509"; break;
\r
162 default: type = "";
\r
164 pw().format(cformat,u.getId(),type,Chrono.niceDateStamp(u.getExpires()));
\r