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.Symm;
32 import org.onap.aaf.cadi.client.Future;
33 import org.onap.aaf.misc.env.APIException;
34 import org.onap.aaf.misc.env.Env;
35 import org.onap.aaf.misc.env.TimeTaken;
36 import org.onap.aaf.misc.xgen.Cache;
37 import org.onap.aaf.misc.xgen.DynamicCode;
38 import org.onap.aaf.misc.xgen.Mark;
39 import org.onap.aaf.misc.xgen.html.HTMLGen;
42 * Detail Page for Permissions
47 public class ApiExample extends Page {
48 public static final String HREF = "/gui/example/:tc";
49 public static final String NAME = "APIExample";
51 public ApiExample(final AAF_GUI gui, Page ... breadcrumbs) throws APIException, IOException {
52 super(gui.env, NAME, HREF, 2/*backdots*/, new String[] {"API Code Example"},
53 new BreadCrumbs(breadcrumbs),
58 private static class Model extends NamedCode {
59 private static final String WITH_OPTIONAL_PARAMETERS = "\n\n////////////\n Data with Optional Parameters \n////////////\n\n";
61 public Model(String name) {
66 public void code(Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
67 Mark inner = xgen.divID("inner");
68 xgen.divID("example","class=std");
69 cache.dynamic(xgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
71 public void code(final AAF_GUI gui, final AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
72 TimeTaken tt = trans.start("Code Example",Env.REMOTE);
74 final String typecode;
75 int prefix = trans.path().lastIndexOf('/')+1;
76 String encoded = trans.path().substring(prefix);
77 typecode = Symm.base64noSplit.decode(encoded);
78 Future<String> fp = gui.client().read("/api/example/" + encoded,
79 "application/Void+json"
82 if (typecode.contains("Request+")) {
83 fs2 = gui.client().read("/api/example/" + encoded+"?optional=true",
84 "application/Void+json"
92 xgen.incr(HTMLGen.H1).text("Sample Code").end()
93 .incr(HTMLGen.H5).text(typecode).end();
95 if (typecode.contains("+xml")) {
97 if (fs2!=null && fs2.get(5000)) {
98 xgen.text(WITH_OPTIONAL_PARAMETERS);
102 xgen.text(fp.body());
103 if (fs2!=null && fs2.get(5000)) {
104 xgen.text(WITH_OPTIONAL_PARAMETERS);
105 xgen.text(fs2.body());
110 xgen.incr(HTMLGen.H3)
111 .textCR(2,"Error from AAF Service")
113 gui.writeError(trans, fp, xgen, 0);
116 } catch (APIException e) {
118 } catch (IOException e) {
120 } catch (Exception e) {
121 throw new APIException(e);