/**
* ============LICENSE_START====================================================
* org.onap.aaf
* ===========================================================================
* Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
* ===========================================================================
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END====================================================
*
*/
package org.onap.aaf.auth.gui.pages;
import java.io.IOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Collections;
import org.onap.aaf.auth.env.AuthzTrans;
import org.onap.aaf.auth.gui.AAF_GUI;
import org.onap.aaf.auth.gui.BreadCrumbs;
import org.onap.aaf.auth.gui.NamedCode;
import org.onap.aaf.auth.gui.Page;
import org.onap.aaf.auth.gui.Table;
import org.onap.aaf.auth.gui.Table.Cells;
import org.onap.aaf.auth.gui.table.AbsCell;
import org.onap.aaf.auth.gui.table.TableData;
import org.onap.aaf.auth.gui.table.TextCell;
import org.onap.aaf.auth.rserv.HttpMethods;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Symm;
import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.cadi.client.Rcli;
import org.onap.aaf.cadi.client.Retryable;
import org.onap.aaf.cadi.config.Config;
import org.onap.aaf.misc.env.APIException;
import org.onap.aaf.misc.env.Env;
import org.onap.aaf.misc.env.TimeTaken;
import org.onap.aaf.misc.xgen.Cache;
import org.onap.aaf.misc.xgen.html.HTMLGen;
import aaf.v2_0.Api;
import aaf.v2_0.Api.Route;
public class ApiDocs extends Page {
// Package on purpose
private static final String HREF = "/gui/api";
private static final String NAME = "AAF RESTful API";
private static final String fields[] = {};
private static final String ERROR_LINK = "JSON "
+ "XML ";
public ApiDocs(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
super(gui.env,NAME,HREF, fields,
new BreadCrumbs(breadcrumbs),
new Preamble(gui),
new Table ");
desc.append(r.getDesc());
if (!r.getComments().isEmpty()) {
for (String ct : r.getComments()) {
desc.append(" ");
desc.append(ct);
}
}
if (!r.getParam().isEmpty()) {
desc.append(" Parameters
"); desc.append(param[0]); desc.append(" : "); desc.append(param[1]); if ("true".equalsIgnoreCase(param[2])) { desc.append(" (Required)"); } } } if (r.getExpected()!=0) { desc.append("
Expected HTTP Code
"); desc.append(r.getExpected()); } if (!r.getExplicitErr().isEmpty()) { desc.append("
Explicit HTTP Error Codes
"); boolean first = true; for (int ee : r.getExplicitErr()) { if (first) { first = false; } else { desc.append(", "); } desc.append(ee); } } desc.append("
"); desc.append("GET".equals(r.getMeth())?"Accept:":"ContentType:"); Collections.sort(r.getContentType()); if (r.getPath().startsWith("/authn/basicAuth")) { desc.append("
text/plain"); } for (String ct : r.getContentType()) { if (ct.contains("version=2")) { desc.append("
"); desc.append(ct); desc.append(""); } } 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.isEmpty()?new TextCell("PERMISSION"):BLANK; perms.add(sa); } else if (path.startsWith("/authz/role") || path.startsWith("/authz/userRole")) { sa[0] = roles.isEmpty()?new TextCell("ROLE"):BLANK; roles.add(sa); } else if (path.startsWith("/authz/ns")) { sa[0] = ns.isEmpty()?new TextCell("NAMESPACE"):BLANK; ns.add(sa); } else if (path.startsWith("/authn/basicAuth") || path.startsWith("/authn/validate") || path.startsWith("/authz/user")) { sa[0] = user.isEmpty()?new TextCell("USER"):BLANK; user.add(sa); } else { sa[0] = aafOnly.isEmpty()?new TextCell("AAF ONLY"):BLANK; aafOnly.add(sa); } } //TODO if (trans.fish(p)) prepare(rv, perms,roles,ns,user); } finally { tt2.done(); } } else { gui.writeError(trans, fa, null, 0); } return null; } }); } catch (Exception e) { trans.error().log(e.getMessage()); } finally { tt.done(); } return new Cells(rv,null); } @SuppressWarnings("unchecked") private void prepare(ArrayList