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;
8 import com.att.authz.env.AuthzTrans;
9 import com.att.authz.gui.AuthGUI;
10 import com.att.authz.gui.BreadCrumbs;
11 import com.att.authz.gui.NamedCode;
12 import com.att.authz.gui.Page;
13 import org.onap.aaf.cadi.CadiException;
14 import org.onap.aaf.cadi.client.Future;
15 import org.onap.aaf.cadi.client.Rcli;
16 import org.onap.aaf.cadi.client.Retryable;
17 import org.onap.aaf.inno.env.APIException;
18 import org.onap.aaf.inno.env.Env;
19 import org.onap.aaf.inno.env.Slot;
20 import org.onap.aaf.inno.env.TimeTaken;
21 import com.att.xgen.Cache;
22 import com.att.xgen.DynamicCode;
23 import com.att.xgen.html.HTMLGen;
25 import aaf.v2_0.Approval;
26 import aaf.v2_0.Approvals;
28 public class ApprovalAction extends Page {
29 public ApprovalAction(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
30 super(gui.env,"Approvals",ApprovalForm.HREF, ApprovalForm.FIELDS,
31 new BreadCrumbs(breadcrumbs),
32 new NamedCode(true,"content") {
33 final Slot sAppr = gui.env.slot(ApprovalForm.NAME+'.'+ApprovalForm.FIELDS[0]);
34 final Slot sUser = gui.env.slot(ApprovalForm.NAME+'.'+ApprovalForm.FIELDS[1]);
37 public void code(Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
38 cache.dynamic(hgen, new DynamicCode<HTMLGen,AuthGUI, AuthzTrans>() {
40 public void code(final AuthGUI gui, final AuthzTrans trans,Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
42 String[] appr = trans.get(sAppr,null);
43 String user = trans.get(sUser,null);
44 String lastPage = ApprovalForm.HREF;
46 lastPage += "?user="+user;
50 hgen.p("No Approvals have been selected.");
53 final Approvals apps = new Approvals();
55 for(String a : appr) {
57 int idx = a.indexOf('|');
60 app.setStatus(a.substring(0,idx));
61 app.setTicket(a.substring(++idx));
62 app.setApprover(trans.getUserPrincipal().getName());
63 apps.getApprovals().add(app);
68 if(apps.getApprovals().isEmpty()) {
69 hgen.p("No Approvals have been sent.");
71 TimeTaken tt = trans.start("AAF Update Approvals",Env.REMOTE);
73 final int total = count;
74 fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Boolean>() {
76 public Boolean code(Rcli<?> client) throws APIException, CadiException {
78 Future<Approvals> fa = client.update("/authz/approval",gui.approvalsDF,apps);
79 if(fa.get(AuthGUI.TIMEOUT)) {
82 hgen.p(total + (total==1?" Approval has":" Approvals have") + " been Saved");
84 gui.writeError(trans, fa, hgen);
89 } catch (Exception e) {
98 hgen.incr("a",true,"href="+lastPage).text("Try again").end();
100 hgen.incr("a",true,"href="+Home.HREF).text("Home").end();