AT&T 2.0.19 Code drop, stage 4
[aaf/authz.git] / authz-gui / src / main / java / com / att / authz / gui / pages / PermsShow.java
1 /*******************************************************************************
2  * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3  *******************************************************************************/
4 package com.att.authz.gui.pages;
5
6 import java.io.IOException;
7 import java.net.ConnectException;
8 import java.util.ArrayList;
9
10 import com.att.authz.env.AuthzTrans;
11 import com.att.authz.gui.AuthGUI;
12 import com.att.authz.gui.BreadCrumbs;
13 import com.att.authz.gui.Page;
14 import com.att.authz.gui.Table;
15 import com.att.authz.gui.Table.Cells;
16 import com.att.authz.gui.table.AbsCell;
17 import com.att.authz.gui.table.RefCell;
18 import com.att.authz.gui.table.TextCell;
19 import org.onap.aaf.cadi.CadiException;
20 import org.onap.aaf.cadi.client.Future;
21 import org.onap.aaf.cadi.client.Rcli;
22 import org.onap.aaf.cadi.client.Retryable;
23 import org.onap.aaf.inno.env.APIException;
24 import org.onap.aaf.inno.env.Env;
25 import org.onap.aaf.inno.env.TimeTaken;
26
27 import aaf.v2_0.Perm;
28 import aaf.v2_0.Perms;
29
30 /**
31  * Page content for My Permissions
32  * 
33  *
34  */
35 public class PermsShow extends Page {
36         public static final String HREF = "/gui/myperms";
37         
38         public PermsShow(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
39                 super(gui.env, "MyPerms",HREF, NO_FIELDS,
40                         new BreadCrumbs(breadcrumbs), 
41                         new Table<AuthGUI,AuthzTrans>("Permissions",gui.env.newTransNoAvg(),new Model(), "class=std"));
42         }
43
44         /**
45          * Implement the Table Content for Permissions by User
46          * 
47          *
48          */
49         private static class Model implements Table.Data<AuthGUI,AuthzTrans> {
50                 private static final String[] headers = new String[] {"Type","Instance","Action"};
51
52                 @Override
53                 public String[] headers() {
54                         return headers;
55                 }
56                 
57                 @Override
58                 public Cells get(final AuthGUI gui, final AuthzTrans trans) {
59                         ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
60                         TimeTaken tt = trans.start("AAF Perms by User",Env.REMOTE);
61                         try {
62                                 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
63                                         @Override
64                                         public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
65                                                 Future<Perms> fp = client.read("/authz/perms/user/"+trans.user(), gui.permsDF);
66                                                 if(fp.get(5000)) {
67                                                         TimeTaken ttld = trans.start("Load Data", Env.SUB);
68                                                         try {
69                                                                 if(fp.value!=null) {    
70                                                                         for(Perm p : fp.value.getPerm()) {
71                                                                                 AbsCell[] sa = new AbsCell[] {
72                                                                                         new RefCell(p.getType(),PermDetail.HREF
73                                                                                                         +"?type="+p.getType()
74                                                                                                         +"&amp;instance="+p.getInstance()
75                                                                                                         +"&amp;action="+p.getAction()),
76                                                                                         new TextCell(p.getInstance()),
77                                                                                         new TextCell(p.getAction())
78                                                                                 };
79                                                                                 rv.add(sa);
80                                                                         }
81                                                                 } else {
82                                                                         gui.writeError(trans, fp, null);
83                                                                 }
84                                                         } finally {
85                                                                 ttld.done();
86                                                         }
87                                                 }
88                                                 return null;
89                                         }
90                                 });
91                         } catch (Exception e) {
92                                 trans.error().log(e);
93                         } finally {
94                                 tt.done();
95                         }
96                         return new Cells(rv,null);
97                 }
98         }
99 }