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 static org.onap.aaf.misc.xgen.html.HTMLGen.A;
25 import static org.onap.aaf.misc.xgen.html.HTMLGen.TABLE;
27 import java.io.IOException;
28 import java.net.ConnectException;
29 import java.util.List;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.gui.AAF_GUI;
33 import org.onap.aaf.auth.gui.BreadCrumbs;
34 import org.onap.aaf.auth.gui.NamedCode;
35 import org.onap.aaf.auth.gui.Page;
36 import org.onap.aaf.cadi.CadiException;
37 import org.onap.aaf.cadi.client.Future;
38 import org.onap.aaf.cadi.client.Rcli;
39 import org.onap.aaf.cadi.client.Retryable;
40 import org.onap.aaf.misc.env.APIException;
41 import org.onap.aaf.misc.env.Env;
42 import org.onap.aaf.misc.env.Slot;
43 import org.onap.aaf.misc.env.TimeTaken;
44 import org.onap.aaf.misc.xgen.Cache;
45 import org.onap.aaf.misc.xgen.DynamicCode;
46 import org.onap.aaf.misc.xgen.Mark;
47 import org.onap.aaf.misc.xgen.html.HTMLGen;
50 import aaf.v2_0.Nss.Ns;
52 public class NsInfoForm extends Page {
55 static final String HREF = "/gui/onboard";
56 static final String NAME = "Onboarding";
57 static final String fields[] = {"ns","description","mots","owners","admins"};
59 public NsInfoForm(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
60 super(gui.env,NAME,HREF, fields,
61 new BreadCrumbs(breadcrumbs),
62 new NamedCode(true,"content") {
64 private final Slot sID = gui.env.slot(NsInfoForm.NAME+'.'+NsInfoForm.fields[0]);
66 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
67 // p tags not closing right using .p() - causes issues in IE8 password form - so using leaf for the moment
68 hgen.leaf(HTMLGen.H2).text("Namespace Info").end()
69 .leaf("p").text("Hover over Fields for Tool Tips, or click ")
70 .leaf(A,"href="+gui.env.getProperty(AAF_URL_GUI_ONBOARD,"")).text("Here").end()
71 .text(" for more information")
73 .incr("form","method=post");
74 Mark table = new Mark(TABLE);
76 cache.dynamic(hgen, new DynamicCode<HTMLGen, AAF_GUI, AuthzTrans>() {
77 @SuppressWarnings("unchecked")
79 public void code(final AAF_GUI gui, final AuthzTrans trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
80 final String incomingID= trans.get(sID, "");
81 final String[] info = new String[fields.length];
82 final Object own_adm[] = new Object[2];
83 for (int i=0;i<info.length;++i) {
86 if (incomingID.length()>0) {
87 TimeTaken tt = trans.start("AAF Namespace Info",Env.REMOTE);
89 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
91 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
92 Future<Nss> fn = client.read("/authz/nss/"+incomingID,gui.getDF(Nss.class));
93 if (fn.get(AAF_GUI.TIMEOUT)) {
94 for (Ns ns : fn.value.getNs()) {
96 info[1]=ns.getDescription();
97 for (Ns.Attrib attr: ns.getAttrib()) {
98 switch(attr.getKey()) {
100 info[2]=attr.getValue();
104 own_adm[0]=ns.getResponsible();
105 own_adm[1]=ns.getAdmin();
108 trans.error().log(fn.body());
113 } catch (Exception e) {
114 trans.error().log("Unable to access AAF for NS Info",incomingID);
120 hgen.input(fields[0],"Namespace",false,"value="+info[0],"title=AAF Namespace")
121 .input(fields[1],"Description*",true,"value="+info[1],"title=Full Application Name, Tool Name or Group")
122 .input(fields[2],"MOTS ID",false,"value="+info[2],"title=MOTS ID if this is an Application, and has MOTS");
123 Mark endTD = new Mark(),endTR=new Mark();
125 hgen.incr(endTR,HTMLGen.TR)
126 .incr(endTD,HTMLGen.TD)
127 .leaf("label","for="+fields[3]).text("Responsible Party")
129 .incr(endTD,HTMLGen.TD)
130 .tagOnly("input","id="+fields[3],"title=Owner of App, must be an Non-Bargained Employee");
131 if (own_adm[0]!=null) {
132 for (String s : (List<String>)own_adm[0]) {
133 hgen.incr("label",true).text(s).end();
139 hgen.incr(endTR,HTMLGen.TR)
140 .incr(endTD,HTMLGen.TD)
141 .leaf("label","for="+fields[4]).text("Administrators")
143 .incr(endTD,HTMLGen.TD)
144 .tagOnly("input","id="+fields[4],"title=Admins may be employees, contractors or mechIDs");
145 if (own_adm[1]!=null) {
146 for (String s : (List<String>)own_adm[1]) {
147 hgen.incr(HTMLGen.P,true).text(s).end();
155 hgen.tagOnly("input", "type=submit", "value=Submit")