1 /*******************************************************************************
2 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 *******************************************************************************/
4 package com.att.authz.gui.pages;
6 import java.io.IOException;
7 import java.net.ConnectException;
9 import com.att.authz.env.AuthzTrans;
10 import com.att.authz.gui.AuthGUI;
11 import com.att.authz.gui.BreadCrumbs;
12 import com.att.authz.gui.NamedCode;
13 import com.att.authz.gui.Page;
14 import org.onap.aaf.cadi.CadiException;
15 import org.onap.aaf.cadi.client.Future;
16 import org.onap.aaf.cadi.client.Rcli;
17 import org.onap.aaf.cadi.client.Retryable;
18 import org.onap.aaf.inno.env.APIException;
19 import org.onap.aaf.inno.env.Env;
20 import org.onap.aaf.inno.env.Slot;
21 import org.onap.aaf.inno.env.TimeTaken;
22 import com.att.xgen.Cache;
23 import com.att.xgen.DynamicCode;
24 import com.att.xgen.html.HTMLGen;
27 import aaf.v2_0.RolePermRequest;
29 public class PermGrantAction extends Page {
32 public PermGrantAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
33 super(gui.env,PermGrantForm.NAME, PermGrantForm.HREF, PermGrantForm.fields,
34 new BreadCrumbs(breadcrumbs),
35 new NamedCode(true,"content") {
36 final Slot sType = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[0]);
37 final Slot sInstance = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[1]);
38 final Slot sAction = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[2]);
39 final Slot sRole = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[3]);
42 public void code(Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
43 cache.dynamic(hgen, new DynamicCode<HTMLGen,AuthGUI, AuthzTrans>() {
45 public void code(final AuthGUI gui, final AuthzTrans trans,Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
47 String type = trans.get(sType,null);
48 String instance = trans.get(sInstance,null);
49 String action = trans.get(sAction,null);
50 String role = trans.get(sRole,null);
52 String lastPage = PermGrantForm.HREF
53 + "?type=" + type + "&instance=" + instance + "&action=" + action;
58 TimeTaken tt = trans.start("AAF Grant Permission to Role",Env.REMOTE);
61 final RolePermRequest grantReq = new RolePermRequest();
62 Pkey pkey = new Pkey();
64 pkey.setInstance(instance);
65 pkey.setAction(action);
66 grantReq.setPerm(pkey);
67 grantReq.setRole(role);
69 fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Boolean>() {
71 public Boolean code(Rcli<?> client) throws CadiException, ConnectException, APIException {
73 Future<RolePermRequest> fgrant = client.create(
79 if(fgrant.get(5000)) {
80 hgen.p("Permission has been granted to role.");
83 if (202==fgrant.code()) {
84 hgen.p("Permission Grant Request sent, but must be Approved before actualizing");
87 gui.writeError(trans, fgrant, hgen);
93 } catch (Exception e) {
94 hgen.p("Unknown Error");
101 hgen.incr("a",true,"href="+lastPage);
103 hgen.text("Try again");
105 hgen.text("Grant this Permission to Another Role");
109 .text("alterLink('permgrant', '"+lastPage + "');")