X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-gui%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fgui%2Fpages%2FRoleHistory.java;h=ce3083543905430d5a5c73be3933f0744559b9af;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=4a9bd362f4740130da9560af73adfcdf0eeab1b8;hpb=f85f0889b3b0e5e9694afab4dd01a4a97a155188;p=aaf%2Fauthz.git diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleHistory.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleHistory.java index 4a9bd362..ce308354 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleHistory.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleHistory.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -57,170 +57,168 @@ import aaf.v2_0.History.Item; public class RoleHistory extends Page { - static final String NAME="RoleHistory"; - static final String HREF = "/gui/roleHistory"; - static final String FIELDS[] = {"role","dates"}; - static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id="; - static enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, - AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER }; - - public RoleHistory(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { - super(gui.env,NAME,HREF, FIELDS, - new BreadCrumbs(breadcrumbs), - new Table("History", gui.env.newTransNoAvg(),new Model(gui.env),"class=std"), - new NamedCode(true, "content") { - @Override - public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { - final Slot role = gui.env.slot(NAME+".role"); - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(final AAF_GUI gui, final AuthzTrans trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { - String obRole = trans.get(role, null); - - // Use Javascript to make the table title more descriptive - hgen.js() - .text("var caption = document.querySelector(\".title\");") - .text("caption.innerHTML='History for Role [ " + obRole + " ]';") - .done(); - - // Use Javascript to change Link Target to our last visited Detail page - String lastPage = RoleDetail.HREF + "?role=" + obRole; - hgen.js() - .text("alterLink('roledetail', '"+lastPage + "');") - .done(); - - hgen.br(); - hgen.leaf("a", "href=#advanced_search","onclick=divVisibility('advanced_search');").text("Advanced Search").end() - .divID("advanced_search", "style=display:none"); - hgen.incr("table"); - - addDateRow(hgen,"Start Date"); - addDateRow(hgen,"End Date"); - hgen.incr("tr").incr("td"); - hgen.tagOnly("input", "type=button","value=Get History", - "onclick=datesURL('"+HREF+"?role=" + obRole+"');"); - hgen.end().end(); - hgen.end(); - hgen.end(); - } - }); - } - } - - ); - - } - - private static void addDateRow(HTMLGen hgen, String s) { - hgen - .incr("tr") - .incr("td") - .incr("label", "for=month", "required").text(s+"*").end() - .end() - .incr("td") - .incr("select", "name=month"+s.substring(0, s.indexOf(' ')), "id=month"+s.substring(0, s.indexOf(' ')), "required") - .incr("option", "value=").text("Month").end(); - for (Month m : Month.values()) { - if (Calendar.getInstance().get(Calendar.MONTH) == m.ordinal()) { - hgen.incr("option", "selected", "value="+(m.ordinal()+1)).text(m.name()).end(); - } else { - hgen.incr("option", "value="+(m.ordinal()+1)).text(m.name()).end(); - } - } - hgen.end() - .end() - .incr("td") - .tagOnly("input","type=number","id=year"+s.substring(0, s.indexOf(' ')),"required", - "value="+Calendar.getInstance().get(Calendar.YEAR), "min=1900", - "max="+Calendar.getInstance().get(Calendar.YEAR), - "placeholder=Year").end() - .end(); - } - - - /** - * Implement the Table Content for History - * - * @author Jeremiah - * - */ - private static class Model extends TableData { - private static final String[] headers = new String[] {"Date","User","Memo"}; - private Slot role; - private Slot dates; - - public Model(AuthzEnv env) { - role = env.slot(NAME+".role"); - dates = env.slot(NAME+".dates"); - } - - @Override - public String[] headers() { - return headers; - } - - @Override - public Cells get(final AuthzTrans trans, final AAF_GUI gui) { - final String oName = trans.get(role,null); - final String oDates = trans.get(dates,null); - - Cells rv = Cells.EMPTY; - if(oName!=null) { - - try { - rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { - @Override - public Cells code(Rcli client) throws CadiException, ConnectException, APIException { - ArrayList rv = new ArrayList<>(); - TimeTaken tt = trans.start("AAF Get History for Namespace ["+oName+"]",Env.REMOTE); - String msg = null; - try { - if (oDates != null) { - client.setQueryParams("yyyymm="+oDates); - } - Future fh = client.read("/authz/hist/role/"+oName,gui.getDF(History.class)); - if (fh.get(AAF_GUI.TIMEOUT)) { - tt.done(); - tt = trans.start("Load History Data", Env.SUB); - List histItems = fh.value.getItem(); - - java.util.Collections.sort(histItems, new Comparator() { - @Override - public int compare(Item o1, Item o2) { - return o2.getTimestamp().compare(o1.getTimestamp()); - } - }); - - for (Item i : histItems) { - String user = i.getUser(); - AbsCell userCell = new TextCell(user); - - String memo = i.getMemo().replace("", "</script>"); - rv.add(new AbsCell[] { - new TextCell(i.getTimestamp().toGregorianCalendar().getTime().toString()), - userCell, - new TextCell(memo) - }); - } - } else { - if (fh.code()==403) { - rv.add(new AbsCell[] {new TextCell("You may not view History of Permission [" + oName + "]", "colspan = 3", "class=center")}); - } else { - rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***", "colspan = 3", "class=center")}); - } - } - } finally { - tt.done(); - } - return new Cells(rv,msg); - } - }); - } catch (Exception e) { - trans.error().log(e); - } - } - return rv; - } - } + static final String NAME="RoleHistory"; + static final String HREF = "/gui/roleHistory"; + static final String FIELDS[] = {"role","dates"}; + + + public RoleHistory(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,NAME,HREF, FIELDS, + new BreadCrumbs(breadcrumbs), + new Table("History", gui.env.newTransNoAvg(),new Model(gui.env),"class=std"), + new NamedCode(true, "content") { + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final Slot role = gui.env.slot(NAME+".role"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AAF_GUI gui, final AuthzTrans trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { + String obRole = trans.get(role, null); + + // Use Javascript to make the table title more descriptive + hgen.js() + .text("var caption = document.querySelector(\".title\");") + .text("caption.innerHTML='History for Role [ " + obRole + " ]';") + .done(); + + // Use Javascript to change Link Target to our last visited Detail page + String lastPage = RoleDetail.HREF + "?role=" + obRole; + hgen.js() + .text("alterLink('roledetail', '"+lastPage + "');") + .done(); + + hgen.br(); + hgen.leaf("a", "href=#advanced_search","onclick=divVisibility('advanced_search');","class=greenbutton").text("Advanced Search").end() + .divID("advanced_search", "style=display:none"); + hgen.incr("table"); + + addDateRow(hgen,"Start Date"); + addDateRow(hgen,"End Date"); + hgen.incr("tr").incr("td"); + hgen.tagOnly("input", "type=button","value=Get History", + "onclick=datesURL('"+HREF+"?role=" + obRole+"');","class=greenbutton"); + hgen.end().end(); + hgen.end(); + hgen.end(); + } + }); + } + } + + ); + + } + + private static void addDateRow(HTMLGen hgen, String s) { + hgen + .incr("tr") + .incr("td") + .incr("label", "for=month", "required").text(s+"*").end() + .end() + .incr("td") + .incr("select", "name=month"+s.substring(0, s.indexOf(' ')), "id=month"+s.substring(0, s.indexOf(' ')), "required") + .incr("option", "value=").text("Month").end(); + for (NsHistory.Month m : NsHistory.Month.values()) { + if (Calendar.getInstance().get(Calendar.MONTH) == m.ordinal()) { + hgen.incr("option", "selected", "value="+(m.ordinal()+1)).text(m.name()).end(); + } else { + hgen.incr("option", "value="+(m.ordinal()+1)).text(m.name()).end(); + } + } + hgen.end() + .end() + .incr("td") + .tagOnly("input","type=number","id=year"+s.substring(0, s.indexOf(' ')),"required", + "value="+Calendar.getInstance().get(Calendar.YEAR), "min=1900", + "max="+Calendar.getInstance().get(Calendar.YEAR), + "placeholder=Year").end() + .end(); + } + + + /** + * Implement the Table Content for History + * + * @author Jeremiah + * + */ + private static class Model extends TableData { + private static final String[] headers = new String[] {"Date","User","Memo"}; + private Slot role; + private Slot dates; + + public Model(AuthzEnv env) { + role = env.slot(NAME+".role"); + dates = env.slot(NAME+".dates"); + } + + @Override + public String[] headers() { + return headers; + } + + @Override + public Cells get(final AuthzTrans trans, final AAF_GUI gui) { + final String oName = trans.get(role,null); + final String oDates = trans.get(dates,null); + + Cells rv = Cells.EMPTY; + if (oName!=null) { + + try { + rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Cells code(Rcli client) throws CadiException, ConnectException, APIException { + ArrayList rv = new ArrayList<>(); + TimeTaken tt = trans.start("AAF Get History for Namespace ["+oName+"]",Env.REMOTE); + String msg = null; + try { + if (oDates != null) { + client.setQueryParams("yyyymm="+oDates); + } + Future fh = client.read("/authz/hist/role/"+oName,gui.getDF(History.class)); + if (fh.get(AAF_GUI.TIMEOUT)) { + tt.done(); + tt = trans.start("Load History Data", Env.SUB); + List histItems = fh.value.getItem(); + + java.util.Collections.sort(histItems, new Comparator() { + @Override + public int compare(Item o1, Item o2) { + return o2.getTimestamp().compare(o1.getTimestamp()); + } + }); + + for (Item i : histItems) { + String user = i.getUser(); + AbsCell userCell = new TextCell(user); + + String memo = i.getMemo().replace("", "</script>"); + rv.add(new AbsCell[] { + new TextCell(i.getTimestamp().toGregorianCalendar().getTime().toString()), + userCell, + new TextCell(memo) + }); + } + } else { + if (fh.code()==403) { + rv.add(new AbsCell[] {new TextCell("You may not view History of Permission [" + oName + "]", "colspan = 3", "class=center")}); + } else { + rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***", "colspan = 3", "class=center")}); + } + } + } finally { + tt.done(); + } + return new Cells(rv,msg); + } + }); + } catch (Exception e) { + trans.error().log(e); + } + } + return rv; + } + } }