1 /*******************************************************************************
2 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 *******************************************************************************/
4 package com.att.authz.gui.pages;
6 import java.io.IOException;
8 import com.att.authz.env.AuthzTrans;
9 import com.att.authz.gui.AuthGUI;
10 import com.att.authz.gui.BreadCrumbs;
11 import com.att.authz.gui.NamedCode;
12 import com.att.authz.gui.Page;
13 import org.onap.aaf.cadi.Symm;
14 import org.onap.aaf.cadi.client.Future;
15 import org.onap.aaf.inno.env.APIException;
16 import org.onap.aaf.inno.env.Data.TYPE;
17 import org.onap.aaf.inno.env.Env;
18 import org.onap.aaf.inno.env.TimeTaken;
19 import com.att.xgen.Cache;
20 import com.att.xgen.DynamicCode;
21 import com.att.xgen.Mark;
22 import com.att.xgen.html.HTMLGen;
24 import aaf.v2_0.Error;
27 * Detail Page for Permissions
31 public class ApiExample extends Page {
32 public static final String HREF = "/gui/example/:tc";
33 public static final String NAME = "APIExample";
35 public ApiExample(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException {
36 super(gui.env, NAME, HREF, 2/*backdots*/, new String[] {"API Code Example"},
37 new BreadCrumbs(breadcrumbs),
42 private static class Model extends NamedCode {
43 private static final String WITH_OPTIONAL_PARAMETERS = "\n\n////////////\n Data with Optional Parameters \n////////////\n\n";
50 public void code(Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
51 Mark inner = xgen.divID("inner");
52 xgen.divID("example","class=std");
53 cache.dynamic(xgen, new DynamicCode<HTMLGen,AuthGUI,AuthzTrans>() {
55 public void code(final AuthGUI gui, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
56 TimeTaken tt = trans.start("Code Example",Env.REMOTE);
58 final String typecode;
59 int prefix = trans.path().lastIndexOf('/')+1;
60 String encoded = trans.path().substring(prefix);
61 typecode = Symm.base64noSplit.decode(encoded);
62 Future<String> fp = gui.client().read("/api/example/" + encoded,
63 "application/Void+json"
66 if(typecode.contains("Request+")) {
67 fs2 = gui.client().read("/api/example/" + typecode+"?optional=true",
68 "application/Void+json"
76 xgen.incr(HTMLGen.H1).text("Sample Code").end()
77 .incr(HTMLGen.H5).text(typecode).end();
79 if(typecode.contains("+xml")) {
81 if(fs2!=null && fs2.get(5000)) {
82 xgen.text(WITH_OPTIONAL_PARAMETERS);
87 if(fs2!=null && fs2.get(5000)) {
88 xgen.text(WITH_OPTIONAL_PARAMETERS);
89 xgen.text(fs2.body());
94 Error err = gui.errDF.newData().in(TYPE.JSON).load(fp.body()).asObject();
96 .textCR(2,"Error from AAF Service")
99 xgen.p("Error Code: ",err.getMessageId())
105 } catch (APIException e) {
107 } catch (IOException e) {
109 } catch (Exception e) {
110 throw new APIException(e);