7daa51fb5e96d0b49bec42aff3218b411d64b215
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / user / List.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.user;
23
24 import java.util.Collections;
25 import java.util.Comparator;
26
27 import org.onap.aaf.auth.cmd.BaseCmd;
28 import org.onap.aaf.misc.env.util.Chrono;
29
30 import aaf.v2_0.Approval;
31 import aaf.v2_0.Approvals;
32 import aaf.v2_0.Delg;
33 import aaf.v2_0.Delgs;
34 import aaf.v2_0.Users;
35
36 public class List extends BaseCmd<User> {
37
38     public List(User parent) {
39         super(parent,"list");
40         cmds.add(new ListForRoles(this));
41         cmds.add(new ListForPermission(this));
42         cmds.add(new ListForCreds(this));
43         cmds.add(new ListDelegates(this));
44         cmds.add(new ListApprovals(this));
45         cmds.add(new ListActivity(this));
46     }
47
48      
49     void report(Users users, boolean count, String ... str) {
50         reportHead(str);
51         int idx = 0;
52         java.util.List<aaf.v2_0.Users.User> sorted = users.getUser();
53         Collections.sort(sorted, (Comparator<aaf.v2_0.Users.User>) (u1, u2) -> {
54             if (u1==null || u2 == null) {
55                 return -1;
56             }
57             return u1.getId().compareTo(u2.getId());
58         });
59         String format = reportColHead("%-48s %-5s %-11s %-16s\n","User","Type","Expires","Tag");
60         String date = "XXXX-XX-XX";
61         for (aaf.v2_0.Users.User user : sorted) {
62             if (!aafcli.isTest()) {
63                 date = Chrono.dateOnlyStamp(user.getExpires());
64             }
65             String tag=user.getTag();
66             Integer type = user.getType();
67             if(tag==null) {
68                 tag="";
69             } else if(type!=null && type>=200) {
70                 tag = "\n\tfingerprint: " + tag;
71             }
72             pw().format(format, 
73                     count? (Integer.valueOf(++idx) + ") " + user.getId()): user.getId(),
74                     org.onap.aaf.auth.cmd.ns.List.getType(user),
75                     date,
76                     tag);
77         }
78         pw().println();
79     }
80
81     public void report(Approvals approvals, String title, String id) {
82         reportHead(title,id);
83         String format = reportColHead("  %-20s %-20s %-11s %-6s %12s\n","User","Approver","Type","Status","Updated");
84         java.util.List<Approval> lapp = approvals.getApprovals();
85         Collections.sort(lapp, (Comparator<Approval>) (a1, a2) -> a1.getTicket().compareTo(a2.getTicket()));
86         String ticket = null;
87         String prev = null;
88         for (Approval app : lapp ) {
89             ticket = app.getTicket();
90             if (!ticket.equals(prev)) {
91                 pw().print("Ticket: ");
92                 pw().println(ticket);
93             }
94             prev = ticket;
95
96             pw().format(format,
97                     app.getUser(),
98                     app.getApprover(),
99                     app.getType(),
100                     app.getStatus(),
101                     Chrono.niceDateStamp(app.getUpdated())
102                     );
103         }
104     }
105
106     public void report(Delgs delgs, String title, String id) {
107         reportHead(title,id);
108         String format = reportColHead(" %-25s %-25s  %-10s\n","User","Delegate","Expires");
109         String date = "XXXX-XX-XX";
110         for (Delg delg : delgs.getDelgs()) {
111             if (!this.aafcli.isTest()) 
112                 date = Chrono.dateOnlyStamp(delg.getExpires());
113             pw().printf(format, 
114                         delg.getUser(),
115                         delg.getDelegate(),
116                         date
117                         );
118         }
119     }
120
121
122 }