1 /*******************************************************************************
2 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 *******************************************************************************/
4 package com.att.authz.gui.pages;
6 import static com.att.xgen.html.HTMLGen.A;
7 import static com.att.xgen.html.HTMLGen.TABLE;
9 import java.io.IOException;
10 import java.net.ConnectException;
11 import java.util.List;
13 import com.att.authz.env.AuthzTrans;
14 import com.att.authz.gui.AuthGUI;
15 import com.att.authz.gui.BreadCrumbs;
16 import com.att.authz.gui.NamedCode;
17 import com.att.authz.gui.Page;
18 import org.onap.aaf.cadi.CadiException;
19 import org.onap.aaf.cadi.client.Future;
20 import org.onap.aaf.cadi.client.Rcli;
21 import org.onap.aaf.cadi.client.Retryable;
22 import org.onap.aaf.inno.env.APIException;
23 import org.onap.aaf.inno.env.Env;
24 import org.onap.aaf.inno.env.Slot;
25 import org.onap.aaf.inno.env.TimeTaken;
26 import com.att.xgen.Cache;
27 import com.att.xgen.DynamicCode;
28 import com.att.xgen.Mark;
29 import com.att.xgen.html.HTMLGen;
32 import aaf.v2_0.Nss.Ns;
33 import aaf.v2_0.Nss.Ns.Attrib;
35 public class NsInfoForm extends Page {
37 static final String HREF = "/gui/onboard";
38 static final String NAME = "Onboarding";
39 static final String fields[] = {"ns","description","mots","owners","admins"};
41 public NsInfoForm(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
42 super(gui.env,NAME,HREF, fields,
43 new BreadCrumbs(breadcrumbs),
44 new NamedCode(true,"content") {
46 private final Slot sID = gui.env.slot(NsInfoForm.NAME+'.'+NsInfoForm.fields[0]);
48 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
49 // p tags not closing right using .p() - causes issues in IE8 password form - so using leaf for the moment
50 hgen.leaf(HTMLGen.H2).text("Namespace Info").end()
51 .leaf("p").text("Hover over Fields for Tool Tips, or click ")
52 .leaf(A,"href="+gui.env.getProperty("aaf_url.gui_onboard","")).text("Here").end()
53 .text(" for more information")
55 .incr("form","method=post");
56 Mark table = new Mark(TABLE);
58 cache.dynamic(hgen, new DynamicCode<HTMLGen, AuthGUI, AuthzTrans>() {
59 @SuppressWarnings("unchecked")
61 public void code(final AuthGUI gui, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
62 final String incomingID= trans.get(sID, "");
63 final String[] info = new String[fields.length];
64 final Object own_adm[] = new Object[2];
65 for(int i=0;i<info.length;++i) {
68 if(incomingID.length()>0) {
69 TimeTaken tt = trans.start("AAF Namespace Info",Env.REMOTE);
71 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
73 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
74 Future<Nss> fn = client.read("/authz/nss/"+incomingID,gui.nssDF);
75 if(fn.get(AuthGUI.TIMEOUT)) {
76 for(Ns ns : fn.value.getNs()) {
78 info[1]=ns.getDescription();
79 for(Attrib attr: ns.getAttrib()) {
80 switch(attr.getKey()) {
82 info[2]=attr.getValue();
86 own_adm[0]=ns.getResponsible();
87 own_adm[1]=ns.getAdmin();
90 trans.error().log(fn.body());
95 } catch (Exception e) {
96 trans.error().log("Unable to access AAF for NS Info",incomingID);
102 hgen.input(fields[0],"Namespace",false,"value="+info[0],"title=AAF Namespace")
103 .input(fields[1],"Description*",true,"value="+info[1],"title=Full Application Name, Tool Name or Group")
104 .input(fields[2],"MOTS ID",false,"value="+info[2],"title=MOTS ID if this is an Application, and has MOTS");
105 Mark endTD = new Mark(),endTR=new Mark();
107 hgen.incr(endTR,HTMLGen.TR)
108 .incr(endTD,HTMLGen.TD)
109 .leaf("label","for="+fields[3]).text("Responsible Party")
111 .incr(endTD,HTMLGen.TD)
112 .tagOnly("input","id="+fields[3],"title=Owner of App, must be an Non-Bargained Employee");
113 if(own_adm[0]!=null) {
114 for(String s : (List<String>)own_adm[0]) {
115 hgen.incr("label",true).text(s).end();
121 hgen.incr(endTR,HTMLGen.TR)
122 .incr(endTD,HTMLGen.TD)
123 .leaf("label","for="+fields[4]).text("Administrators")
125 .incr(endTD,HTMLGen.TD)
126 .tagOnly("input","id="+fields[4],"title=Admins may be employees, contractors or mechIDs");
127 if(own_adm[1]!=null) {
128 for(String s : (List<String>)own_adm[1]) {
129 hgen.incr(HTMLGen.P,true).text(s).end();
137 hgen.tagOnly("input", "type=submit", "value=Submit")