summaryrefslogtreecommitdiffstats
path: root/authz-gui/src/main/java/com/att/authz/gui/pages/NsInfoForm.java
blob: 5cb8ff2c682f0970c50e6e6164e34052c966b0dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
 *******************************************************************************/
package com.att.authz.gui.pages;

import static com.att.xgen.html.HTMLGen.A;
import static com.att.xgen.html.HTMLGen.TABLE;

import java.io.IOException;
import java.net.ConnectException;
import java.util.List;

import com.att.authz.env.AuthzTrans;
import com.att.authz.gui.AuthGUI;
import com.att.authz.gui.BreadCrumbs;
import com.att.authz.gui.NamedCode;
import com.att.authz.gui.Page;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.cadi.client.Rcli;
import org.onap.aaf.cadi.client.Retryable;
import org.onap.aaf.inno.env.APIException;
import org.onap.aaf.inno.env.Env;
import org.onap.aaf.inno.env.Slot;
import org.onap.aaf.inno.env.TimeTaken;
import com.att.xgen.Cache;
import com.att.xgen.DynamicCode;
import com.att.xgen.Mark;
import com.att.xgen.html.HTMLGen;

import aaf.v2_0.Nss;
import aaf.v2_0.Nss.Ns;
import aaf.v2_0.Nss.Ns.Attrib;

public class NsInfoForm extends Page {
	// Package on purpose
	static final String HREF = "/gui/onboard";
	static final String NAME = "Onboarding";
	static final String fields[] = {"ns","description","mots","owners","admins"};
	
	public NsInfoForm(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
		super(gui.env,NAME,HREF, fields,
			new BreadCrumbs(breadcrumbs),
			new NamedCode(true,"content") {

			private final Slot sID = gui.env.slot(NsInfoForm.NAME+'.'+NsInfoForm.fields[0]);
			@Override
			public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
				// p tags not closing right using .p() - causes issues in IE8 password form - so using leaf for the moment
				hgen.leaf(HTMLGen.H2).text("Namespace Info").end()
				     .leaf("p").text("Hover over Fields for Tool Tips, or click ")
				     	.leaf(A,"href="+gui.env.getProperty("aaf_url.gui_onboard","")).text("Here").end()
				     	.text(" for more information")
				     .end()
					.incr("form","method=post");
				Mark table = new Mark(TABLE);
				hgen.incr(table);
				cache.dynamic(hgen, new DynamicCode<HTMLGen, AuthGUI, AuthzTrans>() {
					@SuppressWarnings("unchecked")
					@Override
					public void code(final AuthGUI gui, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen hgen)	throws APIException, IOException {
						final String incomingID= trans.get(sID, "");
						final String[] info = new String[fields.length];
						final Object own_adm[] = new Object[2]; 
						for(int i=0;i<info.length;++i) {
							info[i]="";
						}
						if(incomingID.length()>0) {
							TimeTaken tt = trans.start("AAF Namespace Info",Env.REMOTE);
							try {
								gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
									@Override
									public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
										Future<Nss> fn = client.read("/authz/nss/"+incomingID,gui.nssDF);
										if(fn.get(AuthGUI.TIMEOUT)) {
											for(Ns ns : fn.value.getNs()) {
												info[0]=ns.getName();
												info[1]=ns.getDescription();
												for(Attrib attr: ns.getAttrib()) {
													switch(attr.getKey()) {
														case "mots":
															info[2]=attr.getValue();
														default:
													}
												}
												own_adm[0]=ns.getResponsible();
												own_adm[1]=ns.getAdmin();
											}
										} else {
											trans.error().log(fn.body());
										}
										return null;
									}
								});
							} catch (Exception e) {
								trans.error().log("Unable to access AAF for NS Info",incomingID);
								e.printStackTrace();
							} finally {
								tt.done();
							}
						}
						hgen.input(fields[0],"Namespace",false,"value="+info[0],"title=AAF Namespace")
							.input(fields[1],"Description*",true,"value="+info[1],"title=Full Application Name, Tool Name or Group")
							.input(fields[2],"MOTS ID",false,"value="+info[2],"title=MOTS ID if this is an Application, and has MOTS");
						Mark endTD = new Mark(),endTR=new Mark();
						// Owners
						hgen.incr(endTR,HTMLGen.TR)
								.incr(endTD,HTMLGen.TD)
									.leaf("label","for="+fields[3]).text("Responsible Party")
								.end(endTD)
								.incr(endTD,HTMLGen.TD)
									.tagOnly("input","id="+fields[3],"title=Owner of App, must be an Non-Bargained Employee");
									if(own_adm[0]!=null) {
										for(String s : (List<String>)own_adm[0]) {
											hgen.incr("label",true).text(s).end();
										}
									}
							hgen.end(endTR);

							// Admins
							hgen.incr(endTR,HTMLGen.TR)
								.incr(endTD,HTMLGen.TD)
									.leaf("label","for="+fields[4]).text("Administrators")
								.end(endTD)
								.incr(endTD,HTMLGen.TD)
									.tagOnly("input","id="+fields[4],"title=Admins may be employees, contractors or mechIDs");
									if(own_adm[1]!=null) {
										for(String s : (List<String>)own_adm[1]) {
											hgen.incr(HTMLGen.P,true).text(s).end();
										}
									}
								hgen.end(endTR)
						.end();
					}
				});
				hgen.end();
				hgen.tagOnly("input", "type=submit", "value=Submit")
					.end();

			}
		});
	}

}