2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.gui.pages;
24 import java.io.IOException;
25 import java.net.ConnectException;
26 import java.text.DateFormat;
27 import java.text.SimpleDateFormat;
28 import java.util.ArrayList;
29 import java.util.UUID;
31 import org.onap.aaf.auth.env.AuthzEnv;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.auth.gui.AAF_GUI;
34 import org.onap.aaf.auth.gui.BreadCrumbs;
35 import org.onap.aaf.auth.gui.Page;
36 import org.onap.aaf.auth.gui.Table;
37 import org.onap.aaf.auth.gui.Table.Cells;
38 import org.onap.aaf.auth.gui.table.AbsCell;
39 import org.onap.aaf.auth.gui.table.RefCell;
40 import org.onap.aaf.auth.gui.table.TableData;
41 import org.onap.aaf.auth.gui.table.TextCell;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.client.Future;
44 import org.onap.aaf.cadi.client.Rcli;
45 import org.onap.aaf.cadi.client.Retryable;
46 import org.onap.aaf.misc.env.APIException;
47 import org.onap.aaf.misc.env.Env;
48 import org.onap.aaf.misc.env.Slot;
49 import org.onap.aaf.misc.env.TimeTaken;
51 import aaf.v2_0.Approval;
52 import aaf.v2_0.Approvals;
54 public class RequestDetail extends Page {
55 public static final String HREF = "/gui/requestdetail";
56 public static final String NAME = "RequestDetail";
57 private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
58 public static final String[] FIELDS = {"ticket"};
60 public RequestDetail(final AAF_GUI gui, Page ... breadcrumbs) throws APIException, IOException {
61 super(gui.env, NAME, HREF, FIELDS,
62 new BreadCrumbs(breadcrumbs),
63 new Table<AAF_GUI,AuthzTrans>("Request Details",gui.env.newTransNoAvg(),new Model(gui.env),"class=detail")
68 * Implement the table content for Request Detail
73 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
74 static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id=";
75 private static final String CSP_ATT_COM = "@csp.att.com";
76 final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
78 public Model(AuthzEnv env) {
79 sTicket = env.slot(NAME+".ticket");
83 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
85 final String ticket = trans.get(sTicket, null);
88 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
90 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
91 TimeTaken tt = trans.start("AAF Approval Details",Env.REMOTE);
92 ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
94 Future<Approvals> fa = client.read(
95 "/authz/approval/ticket/"+ticket,
96 gui.getDF(Approvals.class)
99 if(fa.get(AAF_GUI.TIMEOUT)) {
100 if (!trans.user().equals(fa.value.getApprovals().get(0).getUser())) {
104 tt = trans.start("Load Data", Env.SUB);
105 boolean first = true;
106 for ( Approval approval : fa.value.getApprovals()) {
107 AbsCell[] approverLine = new AbsCell[4];
108 // only print common elements once
110 DateFormat createdDF = new SimpleDateFormat(DATE_TIME_FORMAT);
111 UUID id = UUID.fromString(approval.getId());
113 rv.add(new AbsCell[]{new TextCell("Ticket ID:"),new TextCell(approval.getTicket(),"colspan=3")});
114 rv.add(new AbsCell[]{new TextCell("Memo:"),new TextCell(approval.getMemo(),"colspan=3")});
115 rv.add(new AbsCell[]{new TextCell("Requested On:"),
116 new TextCell(createdDF.format((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000),"colspan=3")
118 rv.add(new AbsCell[]{new TextCell("Operation:"),new TextCell(decodeOp(approval.getOperation()),"colspan=3")});
119 String user = approval.getUser();
120 if (user.endsWith(CSP_ATT_COM)) {
121 rv.add(new AbsCell[]{new TextCell("User:"),
122 new RefCell(user,WEBPHONE + user.substring(0, user.indexOf("@")),true,"colspan=3")});
124 rv.add(new AbsCell[]{new TextCell("User:"),new TextCell(user,"colspan=3")});
127 // headers for listing each approver
128 rv.add(new AbsCell[]{new TextCell(" ","colspan=4","class=blank_line")});
129 rv.add(new AbsCell[]{AbsCell.Null,
130 new TextCell("Approver","class=bold"),
131 new TextCell("Type","class=bold"),
132 new TextCell("Status","class=bold")});
133 approverLine[0] = new TextCell("Approvals:");
137 approverLine[0] = AbsCell.Null;
140 String approver = approval.getApprover();
141 String approverShort = approver.substring(0,approver.indexOf('@'));
143 if (approver.endsWith(CSP_ATT_COM)) {
144 approverLine[1] = new RefCell(approver, WEBPHONE + approverShort,true);
146 approverLine[1] = new TextCell(approval.getApprover());
149 String type = approval.getType();
150 if ("owner".equalsIgnoreCase(type)) {
151 type = "resource owner";
154 approverLine[2] = new TextCell(type);
155 approverLine[3] = new TextCell(approval.getStatus());
156 rv.add(approverLine);
160 rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")});
165 return new Cells(rv,null);
168 } catch (Exception e) {
169 trans.error().log(e);
175 private String decodeOp(String operation) {
176 if ("C".equalsIgnoreCase(operation)) {
178 } else if ("D".equalsIgnoreCase(operation)) {
180 } else if ("U".equalsIgnoreCase(operation)) {
182 } else if ("G".equalsIgnoreCase(operation)) {
184 } else if ("UG".equalsIgnoreCase(operation)) {