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;
26 public class UserRoleRemove extends Page {
27 public static final String HREF = "/gui/urRemove";
28 static final String NAME = "Remove User Role";
29 static final String fields[] = {"user","role"};
31 public UserRoleRemove(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
32 super(gui.env,NAME, HREF, fields,
33 new BreadCrumbs(breadcrumbs),
34 new NamedCode(true, "content") {
36 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
37 final Slot sUser = gui.env.slot(NAME+".user");
38 final Slot sRole = gui.env.slot(NAME+".role");
41 cache.dynamic(hgen, new DynamicCode<HTMLGen, AuthGUI, AuthzTrans>() {
43 public void code(AuthGUI gui, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
44 final String user = trans.get(sUser, "");
45 final String role = trans.get(sRole, "");
47 TimeTaken tt = trans.start("Request a user role delete",Env.REMOTE);
49 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
51 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
52 Future<Void> fv = client.setQueryParams("request=true").delete(
53 "/authz/userRole/"+user+"/"+role,Void.class);
56 // not sure if we'll ever hit this
57 hgen.p("User ["+ user+"] Removed from Role [" +role+"]");
59 if (fv.code() == 202 ) {
60 hgen.p("User ["+ user+"] Removal from Role [" +role+"] sent for Approval");
62 gui.writeError(trans, fv, hgen);
68 } catch (Exception e) {