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 javax.servlet.http.HttpServletRequest;
33 import org.onap.aaf.auth.common.Define;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.gui.AAF_GUI;
37 import org.onap.aaf.auth.gui.BreadCrumbs;
38 import org.onap.aaf.auth.gui.Page;
39 import org.onap.aaf.auth.gui.Table;
40 import org.onap.aaf.auth.gui.Table.Cells;
41 import org.onap.aaf.auth.gui.table.AbsCell;
42 import org.onap.aaf.auth.gui.table.TableData;
43 import org.onap.aaf.auth.gui.table.TextCell;
44 import org.onap.aaf.cadi.CadiException;
45 import org.onap.aaf.cadi.client.Future;
46 import org.onap.aaf.cadi.client.Rcli;
47 import org.onap.aaf.cadi.client.Retryable;
48 import org.onap.aaf.misc.env.APIException;
49 import org.onap.aaf.misc.env.Env;
50 import org.onap.aaf.misc.env.Slot;
51 import org.onap.aaf.misc.env.TimeTaken;
53 import aaf.v2_0.Approval;
54 import aaf.v2_0.Approvals;
56 public class RequestDetail extends Page {
57 public static final String HREF = "/gui/requestdetail";
58 public static final String NAME = "RequestDetail";
59 private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
60 public static final String[] FIELDS = {"ticket"};
62 public RequestDetail(final AAF_GUI gui, Page ... breadcrumbs) throws APIException, IOException {
63 super(gui.env, NAME, HREF, FIELDS,
64 new BreadCrumbs(breadcrumbs),
65 new Table<AAF_GUI,AuthzTrans>("Request Details",gui.env.newTransNoAvg(),new Model(gui.env),"class=detail")
70 * Implement the table content for Request Detail
75 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
76 static 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<>();
94 Future<Approvals> fa = client.read(
95 "/authz/approval/ticket/"+ticket,
96 gui.getDF(Approvals.class)
99 if (fa.get(AAF_GUI.TIMEOUT)) {
100 Approval app = fa.value.getApprovals().get(0);
104 if (!(trans.user().equals(app.getUser()) ||
105 trans.user().equals(app.getApprover()))) {
106 HttpServletRequest req = trans.get(gui.slot_httpServletRequest,null);
107 if(req==null || !req.isUserInRole(Define.ROOT_NS()+"|access|*|*")) {
113 tt = trans.start("Load Data", Env.SUB);
114 boolean first = true;
115 for ( Approval approval : fa.value.getApprovals()) {
116 AbsCell[] approverLine = new AbsCell[4];
117 // only print common elements once
119 DateFormat createdDF = new SimpleDateFormat(DATE_TIME_FORMAT);
120 UUID id = UUID.fromString(approval.getId());
122 rv.add(new AbsCell[]{new TextCell("Ticket ID:"),new TextCell(approval.getTicket(),"colspan=3")});
123 rv.add(new AbsCell[]{new TextCell("Memo:"),new TextCell(approval.getMemo(),"colspan=3")});
124 rv.add(new AbsCell[]{new TextCell("Requested On:"),
125 new TextCell(createdDF.format((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000),"colspan=3")
127 rv.add(new AbsCell[]{new TextCell("Operation:"),new TextCell(decodeOp(approval.getOperation()),"colspan=3")});
128 String user = approval.getUser();
129 rv.add(new AbsCell[]{new TextCell("User:"),new TextCell(user,"colspan=3")});
131 // headers for listing each approver
132 rv.add(new AbsCell[]{new TextCell(" ","colspan=4","class=blank_line")});
133 rv.add(new AbsCell[]{AbsCell.Null,
134 new TextCell("Approver","class=bold"),
135 new TextCell("Type","class=bold"),
136 new TextCell("Status","class=bold")});
137 approverLine[0] = new TextCell("Approvals:");
141 approverLine[0] = AbsCell.Null;
144 approverLine[1] = new TextCell(approval.getApprover());
145 String type = approval.getType();
146 if ("owner".equalsIgnoreCase(type)) {
147 type = "resource owner";
150 approverLine[2] = new TextCell(type);
151 approverLine[3] = new TextCell(approval.getStatus());
152 rv.add(approverLine);
156 rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")});
161 return new Cells(rv,null);
164 } catch (Exception e) {
165 trans.error().log(e);
171 private String decodeOp(String operation) {
172 if ("C".equalsIgnoreCase(operation)) {
174 } else if ("D".equalsIgnoreCase(operation)) {
176 } else if ("U".equalsIgnoreCase(operation)) {
178 } else if ("G".equalsIgnoreCase(operation)) {
180 } else if ("UG".equalsIgnoreCase(operation)) {