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.TableData;
40 import org.onap.aaf.auth.gui.table.TextCell;
41 import org.onap.aaf.cadi.CadiException;
42 import org.onap.aaf.cadi.client.Future;
43 import org.onap.aaf.cadi.client.Rcli;
44 import org.onap.aaf.cadi.client.Retryable;
45 import org.onap.aaf.misc.env.APIException;
46 import org.onap.aaf.misc.env.Env;
47 import org.onap.aaf.misc.env.Slot;
48 import org.onap.aaf.misc.env.TimeTaken;
50 import aaf.v2_0.Approval;
51 import aaf.v2_0.Approvals;
53 public class RequestDetail extends Page {
54 public static final String HREF = "/gui/requestdetail";
55 public static final String NAME = "RequestDetail";
56 private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
57 public static final String[] FIELDS = {"ticket"};
59 public RequestDetail(final AAF_GUI gui, Page ... breadcrumbs) throws APIException, IOException {
60 super(gui.env, NAME, HREF, FIELDS,
61 new BreadCrumbs(breadcrumbs),
62 new Table<AAF_GUI,AuthzTrans>("Request Details",gui.env.newTransNoAvg(),new Model(gui.env),"class=detail")
67 * Implement the table content for Request Detail
72 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
73 final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
75 public Model(AuthzEnv env) {
76 sTicket = env.slot(NAME+".ticket");
80 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
82 final String ticket = trans.get(sTicket, null);
85 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
87 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
88 TimeTaken tt = trans.start("AAF Approval Details",Env.REMOTE);
89 ArrayList<AbsCell[]> rv = new ArrayList<>();
91 Future<Approvals> fa = client.read(
92 "/authz/approval/ticket/"+ticket,
93 gui.getDF(Approvals.class)
96 if (fa.get(AAF_GUI.TIMEOUT)) {
97 if (!trans.user().equals(fa.value.getApprovals().get(0).getUser())) {
101 tt = trans.start("Load Data", Env.SUB);
102 boolean first = true;
103 for ( Approval approval : fa.value.getApprovals()) {
104 AbsCell[] approverLine = new AbsCell[4];
105 // only print common elements once
107 DateFormat createdDF = new SimpleDateFormat(DATE_TIME_FORMAT);
108 UUID id = UUID.fromString(approval.getId());
110 rv.add(new AbsCell[]{new TextCell("Ticket ID:"),new TextCell(approval.getTicket(),"colspan=3")});
111 rv.add(new AbsCell[]{new TextCell("Memo:"),new TextCell(approval.getMemo(),"colspan=3")});
112 rv.add(new AbsCell[]{new TextCell("Requested On:"),
113 new TextCell(createdDF.format((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000),"colspan=3")
115 rv.add(new AbsCell[]{new TextCell("Operation:"),new TextCell(decodeOp(approval.getOperation()),"colspan=3")});
116 String user = approval.getUser();
117 rv.add(new AbsCell[]{new TextCell("User:"),new TextCell(user,"colspan=3")});
119 // headers for listing each approver
120 rv.add(new AbsCell[]{new TextCell(" ","colspan=4","class=blank_line")});
121 rv.add(new AbsCell[]{AbsCell.Null,
122 new TextCell("Approver","class=bold"),
123 new TextCell("Type","class=bold"),
124 new TextCell("Status","class=bold")});
125 approverLine[0] = new TextCell("Approvals:");
129 approverLine[0] = AbsCell.Null;
132 approverLine[1] = new TextCell(approval.getApprover());
133 String type = approval.getType();
134 if ("owner".equalsIgnoreCase(type)) {
135 type = "resource owner";
138 approverLine[2] = new TextCell(type);
139 approverLine[3] = new TextCell(approval.getStatus());
140 rv.add(approverLine);
144 rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")});
149 return new Cells(rv,null);
152 } catch (Exception e) {
153 trans.error().log(e);
159 private String decodeOp(String operation) {
160 if ("C".equalsIgnoreCase(operation)) {
162 } else if ("D".equalsIgnoreCase(operation)) {
164 } else if ("U".equalsIgnoreCase(operation)) {
166 } else if ("G".equalsIgnoreCase(operation)) {
168 } else if ("UG".equalsIgnoreCase(operation)) {