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.text.DateFormat;
9 import java.text.SimpleDateFormat;
10 import java.util.ArrayList;
11 import java.util.UUID;
13 import com.att.authz.env.AuthzEnv;
14 import com.att.authz.env.AuthzTrans;
15 import com.att.authz.gui.AuthGUI;
16 import com.att.authz.gui.BreadCrumbs;
17 import com.att.authz.gui.Page;
18 import com.att.authz.gui.Table;
19 import com.att.authz.gui.Table.Cells;
20 import com.att.authz.gui.table.AbsCell;
21 import com.att.authz.gui.table.RefCell;
22 import com.att.authz.gui.table.TextCell;
23 import org.onap.aaf.cadi.CadiException;
24 import org.onap.aaf.cadi.client.Future;
25 import org.onap.aaf.cadi.client.Rcli;
26 import org.onap.aaf.cadi.client.Retryable;
27 import org.onap.aaf.inno.env.APIException;
28 import org.onap.aaf.inno.env.Env;
29 import org.onap.aaf.inno.env.Slot;
30 import org.onap.aaf.inno.env.TimeTaken;
32 import aaf.v2_0.Approval;
33 import aaf.v2_0.Approvals;
35 public class RequestDetail extends Page {
36 public static final String HREF = "/gui/requestdetail";
37 public static final String NAME = "RequestDetail";
38 private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
39 public static final String[] FIELDS = {"ticket"};
41 public RequestDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException {
42 super(gui.env, NAME, HREF, FIELDS,
43 new BreadCrumbs(breadcrumbs),
44 new Table<AuthGUI,AuthzTrans>("Request Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail")
49 * Implement the table content for Request Detail
53 private static class Model implements Table.Data<AuthGUI,AuthzTrans> {
54 static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id=";
55 private static final String CSP_ATT_COM = "@csp.att.com";
56 final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
57 private static final String[] headers = new String[0];
59 public Model(AuthzEnv env) {
60 sTicket = env.slot(NAME+".ticket");
64 public String[] headers() {
69 public Cells get(final AuthGUI gui, final AuthzTrans trans) {
71 final String ticket = trans.get(sTicket, null);
74 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
76 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
77 TimeTaken tt = trans.start("AAF Approval Details",Env.REMOTE);
78 ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
80 Future<Approvals> fa = client.read(
81 "/authz/approval/ticket/"+ticket,
85 if(fa.get(AuthGUI.TIMEOUT)) {
86 if (!trans.user().equals(fa.value.getApprovals().get(0).getUser())) {
90 tt = trans.start("Load Data", Env.SUB);
92 for ( Approval approval : fa.value.getApprovals()) {
93 AbsCell[] approverLine = new AbsCell[4];
94 // only print common elements once
96 DateFormat createdDF = new SimpleDateFormat(DATE_TIME_FORMAT);
97 UUID id = UUID.fromString(approval.getId());
99 rv.add(new AbsCell[]{new TextCell("Ticket ID:"),new TextCell(approval.getTicket(),"colspan=3")});
100 rv.add(new AbsCell[]{new TextCell("Memo:"),new TextCell(approval.getMemo(),"colspan=3")});
101 rv.add(new AbsCell[]{new TextCell("Requested On:"),
102 new TextCell(createdDF.format((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000),"colspan=3")
104 rv.add(new AbsCell[]{new TextCell("Operation:"),new TextCell(decodeOp(approval.getOperation()),"colspan=3")});
105 String user = approval.getUser();
106 if (user.endsWith(CSP_ATT_COM)) {
107 rv.add(new AbsCell[]{new TextCell("User:"),
108 new RefCell(user,WEBPHONE + user.substring(0, user.indexOf("@")),"colspan=3")});
110 rv.add(new AbsCell[]{new TextCell("User:"),new TextCell(user,"colspan=3")});
113 // headers for listing each approver
114 rv.add(new AbsCell[]{new TextCell(" ","colspan=4","class=blank_line")});
115 rv.add(new AbsCell[]{AbsCell.Null,
116 new TextCell("Approver","class=bold"),
117 new TextCell("Type","class=bold"),
118 new TextCell("Status","class=bold")});
119 approverLine[0] = new TextCell("Approvals:");
123 approverLine[0] = AbsCell.Null;
126 String approver = approval.getApprover();
127 String approverShort = approver.substring(0,approver.indexOf('@'));
129 if (approver.endsWith(CSP_ATT_COM)) {
130 approverLine[1] = new RefCell(approver, WEBPHONE + approverShort);
132 approverLine[1] = new TextCell(approval.getApprover());
135 String type = approval.getType();
136 if ("owner".equalsIgnoreCase(type)) {
137 type = "resource owner";
140 approverLine[2] = new TextCell(type);
141 approverLine[3] = new TextCell(approval.getStatus());
142 rv.add(approverLine);
146 rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")});
151 return new Cells(rv,null);
154 } catch (Exception e) {
155 trans.error().log(e);
161 private String decodeOp(String operation) {
162 if ("C".equalsIgnoreCase(operation)) {
164 } else if ("D".equalsIgnoreCase(operation)) {
166 } else if ("U".equalsIgnoreCase(operation)) {
168 } else if ("G".equalsIgnoreCase(operation)) {
170 } else if ("UG".equalsIgnoreCase(operation)) {