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.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;
28 import aaf.v2_0.Perms;
31 * Page content for My Permissions
35 public class PermsShow extends Page {
36 public static final String HREF = "/gui/myperms";
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"));
45 * Implement the Table Content for Permissions by User
49 private static class Model implements Table.Data<AuthGUI,AuthzTrans> {
50 private static final String[] headers = new String[] {"Type","Instance","Action"};
53 public String[] headers() {
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);
62 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
64 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
65 Future<Perms> fp = client.read("/authz/perms/user/"+trans.user(), gui.permsDF);
67 TimeTaken ttld = trans.start("Load Data", Env.SUB);
70 for(Perm p : fp.value.getPerm()) {
71 AbsCell[] sa = new AbsCell[] {
72 new RefCell(p.getType(),PermDetail.HREF
74 +"&instance="+p.getInstance()
75 +"&action="+p.getAction()),
76 new TextCell(p.getInstance()),
77 new TextCell(p.getAction())
82 gui.writeError(trans, fp, null);
91 } catch (Exception e) {
96 return new Cells(rv,null);