2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.gui.pages;
24 import java.io.IOException;
26 import org.onap.aaf.auth.env.AuthzTrans;
27 import org.onap.aaf.auth.gui.AAF_GUI;
28 import org.onap.aaf.auth.gui.BreadCrumbs;
29 import org.onap.aaf.auth.gui.NamedCode;
30 import org.onap.aaf.auth.gui.Page;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.client.Future;
33 import org.onap.aaf.cadi.client.Rcli;
34 import org.onap.aaf.cadi.client.Retryable;
35 import org.onap.aaf.misc.env.APIException;
36 import org.onap.aaf.misc.env.Env;
37 import org.onap.aaf.misc.env.Slot;
38 import org.onap.aaf.misc.env.TimeTaken;
39 import org.onap.aaf.misc.xgen.Cache;
40 import org.onap.aaf.misc.xgen.DynamicCode;
41 import org.onap.aaf.misc.xgen.html.HTMLGen;
43 import aaf.v2_0.Approval;
44 import aaf.v2_0.Approvals;
46 public class ApprovalAction extends Page {
47 public ApprovalAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
48 super(gui.env,"Approvals",ApprovalForm.HREF, ApprovalForm.FIELDS,
49 new BreadCrumbs(breadcrumbs),
50 new NamedCode(true,"content") {
51 final Slot sAppr = gui.env.slot(ApprovalForm.NAME+'.'+ApprovalForm.FIELDS[0]);
52 final Slot sUser = gui.env.slot(ApprovalForm.NAME+'.'+ApprovalForm.FIELDS[1]);
55 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
56 cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI, AuthzTrans>() {
58 public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
59 String[] appr = trans.get(sAppr,null);
60 String user = trans.get(sUser,null);
61 String lastPage = ApprovalForm.HREF;
63 lastPage += "?user="+user;
67 hgen.p("No Approvals have been selected.");
70 final Approvals apps = new Approvals();
72 for (String a : appr) {
74 int idx = a.indexOf('|');
77 app.setStatus(a.substring(0,idx));
78 app.setTicket(a.substring(++idx));
79 app.setApprover(trans.getUserPrincipal().getName());
80 apps.getApprovals().add(app);
85 if (apps.getApprovals().isEmpty()) {
86 hgen.p("No Approvals have been sent.");
88 TimeTaken tt = trans.start("AAF Update Approvals",Env.REMOTE);
90 final int total = count;
91 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Boolean>() {
93 public Boolean code(Rcli<?> client) throws APIException, CadiException {
95 Future<Approvals> fa = client.update("/authz/approval",gui.getDF(Approvals.class),apps);
96 if (fa.get(AAF_GUI.TIMEOUT)) {
99 hgen.p(total + (total==1?" Approval has":" Approvals have") + " been Saved");
101 gui.writeError(trans, fa, hgen, 0);
106 } catch (Exception e) {
114 hgen.incr("a",true,"class=greenbutton","href="+lastPage).text("Back").end();