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.util.ArrayList;
27 import java.util.Collections;
28 import java.util.Comparator;
29 import java.util.List;
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.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;
51 import aaf.v2_0.Nss.Ns;
53 public class NssShow extends Page {
54 public static final String HREF = "/gui/ns";
56 public NssShow(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
57 super(gui.env, "MyNamespaces",HREF, NO_FIELDS,
58 new BreadCrumbs(breadcrumbs),
59 new Table<AAF_GUI,AuthzTrans>("Namespaces I administer",gui.env.newTransNoAvg(),new Model(true,"Administrator",gui.env),
60 "class=std", "style=display: inline-block; width: 45%; margin: 10px;"),
61 new Table<AAF_GUI,AuthzTrans>("Namespaces I own",gui.env.newTransNoAvg(),new Model(false,"Owner",gui.env),
62 "class=std", "style=display: inline-block; width: 45%; margin: 10px;"));
65 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
66 private String[] headers;
67 private String privilege = null;
68 public final Slot sNssByUser;
69 private boolean isAdmin;
71 public Model(boolean admin, String privilege,AuthzEnv env) {
73 headers = new String[] {privilege};
74 this.privilege = privilege;
76 sNssByUser = env.slot("NSS_SHOW_MODEL_DATA");
80 public String[] headers() {
85 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
86 ArrayList<AbsCell[]> rv = new ArrayList<>();
87 List<Ns> nss = trans.get(sNssByUser, null);
89 TimeTaken tt = trans.start("AAF Nss by User for " + privilege,Env.REMOTE);
91 nss = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<List<Ns>>() {
93 public List<Ns> code(Rcli<?> client) throws CadiException, ConnectException, APIException {
95 Future<Nss> fp = client.read("/authz/nss/either/" + trans.user(),gui.getDF(Nss.class));
96 if (fp.get(AAF_GUI.TIMEOUT)) {
97 TimeTaken tt = trans.start("Load Data for " + privilege, Env.SUB);
100 nss = fp.value.getNs();
101 Collections.sort(nss, new Comparator<Ns>() {
102 public int compare(Ns ns1, Ns ns2) {
103 return ns1.getName().compareToIgnoreCase(ns2.getName());
106 trans.put(sNssByUser,nss);
112 gui.writeError(trans, fp, null,0);
117 } catch (Exception e) {
118 trans.error().log(e);
126 if ((isAdmin && !n.getAdmin().isEmpty())
127 || (!isAdmin && !n.getResponsible().isEmpty())) {
128 AbsCell[] sa = new AbsCell[] {
129 new RefCell(n.getName(),NsDetail.HREF
130 +"?ns="+n.getName(),false),
137 return new Cells(rv,null);