From 572bd7c2c2a784f399c55f38a6310d9b5e256e24 Mon Sep 17 00:00:00 2001 From: Pawel Date: Wed, 21 Nov 2018 09:32:19 -0500 Subject: refactor in ApiDocs.java Change-Id: Ie2e0d768344103bdb7758a423838094f1506b26a Issue-ID: AAF-640 Signed-off-by: Pawel --- .../java/org/onap/aaf/auth/gui/pages/ApiDocs.java | 95 +++++++++++----------- 1 file changed, 46 insertions(+), 49 deletions(-) (limited to 'auth') diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/ApiDocs.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/ApiDocs.java index 7d57b3d8..969505bb 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/ApiDocs.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/ApiDocs.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. @@ -66,7 +66,7 @@ public class ApiDocs extends Page { // + Symm.base64noSplit().encode("application/Error+xml") + "\">XML "; - + public ApiDocs(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { super(gui.env,NAME,HREF, fields, new BreadCrumbs(breadcrumbs), @@ -74,15 +74,15 @@ public class ApiDocs extends Page { new Table("AAF API Reference",gui.env.newTransNoAvg(),new Model(), "class=std") ); } - + private static class Preamble extends NamedCode { private static final String I = "i"; - private final String fs_url; + private final String fsUrl; public Preamble(AAF_GUI gui) { super(false, "preamble"); - fs_url = gui.access.getProperty("fs_url", ""); + fsUrl = gui.access.getProperty("fs_url", ""); } @Override @@ -108,11 +108,11 @@ public class ApiDocs extends Page { + "+json after the type for JSON or +xml after the Type for XML").end() .leaf(HTMLGen.LI).text("XSDs for Versions").end() .incr(HTMLGen.UL) - .leaf(HTMLGen.LI).leaf(HTMLGen.A,"href=" + fs_url + "/aaf_2_0.xsd").text("API 2.0").end().end() + .leaf(HTMLGen.LI).leaf(HTMLGen.A,"href=" + fsUrl + "/aaf_2_0.xsd").text("API 2.0").end().end() .end() .leaf(HTMLGen.LI).text("AAF can support multiple Versions of the API. Choose the ContentType/Accept that has " + "the appropriate version=?.?").end() - .leaf(HTMLGen.LI).text("All Errors coming from AAF return AT&T Standard Error Message as a String: " + ERROR_LINK + .leaf(HTMLGen.LI).text("All Errors coming from AAF return AT&T Standard Error Message as a String: " + ERROR_LINK + " (does not apply to errors from Container)").end() .end() .leaf(HTMLGen.LI).text("Character Restrictions").end() @@ -131,7 +131,7 @@ public class ApiDocs extends Page { .end() .end(); /* - + The Content is defined in the AAF XSD - TODO Add aaf.xsd”; Character Restrictions @@ -141,24 +141,24 @@ public class ApiDocs extends Page { “/“ is used to separate fields */ } - + }; /** * Implement the Table Content for Permissions by User - * + * * @author Jonathan * */ private static class Model extends TableData { public static final String[] HEADERS = new String[] {"Entity","Method","Path Info","Description"}; private static final TextCell BLANK = new TextCell(""); - + @Override public String[] headers() { return HEADERS; } - - + + @Override public Cells get(final AuthzTrans trans, final AAF_GUI gui) { final ArrayList ns = new ArrayList<>(); @@ -167,8 +167,8 @@ public class ApiDocs extends Page { final ArrayList user = new ArrayList<>(); final ArrayList aafOnly = new ArrayList<>(); final ArrayList rv = new ArrayList<>(); - - + + final TimeTaken tt = trans.start("AAF APIs",Env.REMOTE); try { gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { @@ -184,20 +184,20 @@ public class ApiDocs extends Page { String path = r.getPath(); // Build info StringBuilder desc = new StringBuilder(); - + desc.append("

"); desc.append(r.getDesc()); - - if (r.getComments().size()>0) { + + if (!r.getComments().isEmpty()) { for (String ct : r.getComments()) { desc.append("

"); desc.append(ct); } } - - if (r.getParam().size()>0) { + + if (!r.getParam().isEmpty()) { desc.append("


Parameters

"); - + for (String params : r.getParam()) { String param[] = params.split("\\s*\\|\\s*"); desc.append("

"); @@ -209,14 +209,14 @@ public class ApiDocs extends Page { } } } - - + + if (r.getExpected()!=0) { desc.append("

Expected HTTP Code

"); desc.append(r.getExpected()); - } - - if (r.getExplicitErr().size()!=0) { + } + + if (!r.getExplicitErr().isEmpty()) { desc.append("

Explicit HTTP Error Codes

"); boolean first = true; for (int ee : r.getExplicitErr()) { @@ -228,7 +228,7 @@ public class ApiDocs extends Page { desc.append(ee); } } - + desc.append("

"); desc.append("GET".equals(r.getMeth())?"Accept:":"ContentType:"); Collections.sort(r.getContentType()); @@ -249,31 +249,31 @@ public class ApiDocs extends Page { } } desc.append("

"); - - + + AbsCell[] sa = new AbsCell[] { null, new TextCell(r.getMeth(),"class=right"), new TextCell(r.getPath()), new TextCell(desc.toString()), }; - + if (path.startsWith("/authz/perm")) { - sa[0] = perms.size()==0?new TextCell("PERMISSION"):BLANK; + sa[0] = perms.isEmpty()?new TextCell("PERMISSION"):BLANK; perms.add(sa); } else if (path.startsWith("/authz/role") || path.startsWith("/authz/userRole")) { - sa[0] = roles.size()==0?new TextCell("ROLE"):BLANK; + sa[0] = roles.isEmpty()?new TextCell("ROLE"):BLANK; roles.add(sa); } else if (path.startsWith("/authz/ns")) { - sa[0] = ns.size()==0?new TextCell("NAMESPACE"):BLANK; + sa[0] = ns.isEmpty()?new TextCell("NAMESPACE"):BLANK; ns.add(sa); - } else if (path.startsWith("/authn/basicAuth") + } else if (path.startsWith("/authn/basicAuth") || path.startsWith("/authn/validate") || path.startsWith("/authz/user")) { - sa[0] = user.size()==0?new TextCell("USER"):BLANK; + sa[0] = user.isEmpty()?new TextCell("USER"):BLANK; user.add(sa); } else { - sa[0] = aafOnly.size()==0?new TextCell("AAF ONLY"):BLANK; + sa[0] = aafOnly.isEmpty()?new TextCell("AAF ONLY"):BLANK; aafOnly.add(sa); } } @@ -293,7 +293,7 @@ public class ApiDocs extends Page { } finally { tt.done(); } - + return new Cells(rv,null); } @@ -307,17 +307,14 @@ public class ApiDocs extends Page { lead = row[0]; row[0]=BLANK; al.get(0).clone()[0]=BLANK; - Collections.sort(al, new Comparator() { - @Override - public int compare(AbsCell[] ca1, AbsCell[] ca2) { - int meth = ((TextCell)ca1[2]).name.compareTo( - ((TextCell)ca2[2]).name); - if (meth == 0) { - return (HttpMethods.valueOf(((TextCell)ca1[1]).name).compareTo( - HttpMethods.valueOf(((TextCell)ca2[1]).name))); - } else { - return meth; - } + Collections.sort(al, (ca1, ca2) -> { + int meth = ((TextCell)ca1[2]).name.compareTo( + ((TextCell)ca2[2]).name); + if (meth == 0) { + return (HttpMethods.valueOf(((TextCell)ca1[1]).name).compareTo( + HttpMethods.valueOf(((TextCell)ca2[1]).name))); + } else { + return meth; } }); // set new first row -- cgit 1.2.3-korg