1 /*******************************************************************************
2 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 *******************************************************************************/
4 package com.att.authz.gui.pages;
6 import java.io.IOException;
7 import java.net.ConnectException;
8 import java.util.ArrayList;
10 import com.att.authz.env.AuthzEnv;
11 import com.att.authz.env.AuthzTrans;
12 import com.att.authz.gui.AuthGUI;
13 import com.att.authz.gui.BreadCrumbs;
14 import com.att.authz.gui.Page;
15 import com.att.authz.gui.Table;
16 import com.att.authz.gui.Table.Cells;
17 import com.att.authz.gui.table.AbsCell;
18 import com.att.authz.gui.table.RefCell;
19 import com.att.authz.gui.table.TextCell;
20 import com.att.cadi.CadiException;
21 import com.att.cadi.client.Future;
22 import com.att.cadi.client.Rcli;
23 import com.att.cadi.client.Retryable;
24 import com.att.inno.env.APIException;
25 import com.att.inno.env.Env;
26 import com.att.inno.env.Slot;
27 import com.att.inno.env.TimeTaken;
31 import aaf.v2_0.Roles;
34 * Detail Page for Permissions
38 public class RoleDetail extends Page {
39 public static final String HREF = "/gui/roledetail";
40 public static final String NAME = "RoleDetail";
41 private static final String BLANK = "";
43 public RoleDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException {
44 super(gui.env, NAME, HREF, new String[] {"role"},
45 new BreadCrumbs(breadcrumbs),
46 new Table<AuthGUI,AuthzTrans>("Role Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail")
51 * Implement the table content for Permissions Detail
55 private static class Model implements Table.Data<AuthGUI,AuthzTrans> {
56 private static final String[] headers = new String[0];
58 public Model(AuthzEnv env) {
59 role = env.slot(NAME+".role");
63 public String[] headers() {
68 public Cells get(final AuthGUI gui, final AuthzTrans trans) {
69 final String pRole = trans.get(role, null);
70 Cells rv = Cells.EMPTY;
73 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
75 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
76 ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
77 rv.add(new AbsCell[]{new TextCell("Role:"),new TextCell(pRole)});
79 TimeTaken tt = trans.start("AAF Role Details",Env.REMOTE);
82 Future<Roles> fr = client.read("/authz/roles/"+pRole,gui.rolesDF);
83 if(fr.get(AuthGUI.TIMEOUT)) {
85 tt = trans.start("Load Data", Env.SUB);
86 Role role = fr.value.getRole().get(0);
87 String desc = (role.getDescription()!=null?role.getDescription():BLANK);
88 rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)});
90 for(Pkey r : role.getPerms()) {
93 rv.add(new AbsCell[] {
94 new TextCell("Associated Permissions:"),
95 new TextCell(r.getType() +
96 " | " + r.getInstance() +
101 rv.add(new AbsCell[] {
103 new TextCell(r.getType() +
104 " | " + r.getInstance() +
105 " | " + r.getAction()
110 String historyLink = RoleHistory.HREF
112 rv.add(new AbsCell[] {new RefCell("See History",historyLink)});
114 rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")});
119 return new Cells(rv,null);
122 } catch (Exception e) {
123 trans.error().log(e);