001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.petstore.console; 018 019import org.apache.juneau.petstore.console.pages.*; 020import org.apache.juneau.petstore.dto.*; 021import org.apache.juneau.rest.server.*; 022import org.apache.juneau.rest.server.beans.*; 023import org.apache.juneau.rest.server.view.*; 024import org.apache.juneau.rest.server.view.freemarker.*; 025 026/** 027 * About: what the petstore demonstrates, as prose cards, plus Juneau's REST utility beans shown against the 028 * {@link Pet} domain bean. 029 * 030 * <p> 031 * {@link BeanDescription}, {@link Hyperlink} and {@link SeeOtherRoot} are small beans meant for REST responses: 032 * {@code OPTIONS}-style introspection, navigational links and root-relative redirects. 033 * 034 * <h5 class='section'>Example:</h5> 035 * <p class='bjava'> 036 * <jc>// GET /console/about/beans/BeanDescription</jc> 037 * <ja>@RestGet</ja>(path=<js>"/beans/BeanDescription"</js>) 038 * <jk>public</jk> BeanDescription beanDescription() { 039 * <jk>return</jk> BeanDescription.<jsm>of</jsm>(Pet.<jk>class</jk>); 040 * } 041 * </p> 042 * <p class='bftl'> 043 * <@card id="overview" title="About the petstore"><div class="jc-prose">...</div></@card> 044 * </p> 045 * 046 * <h5 class='section'>See Also:</h5><ul> 047 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/UtilityBeans">Utility Beans</a> 048 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauPetstore">juneau-petstore</a> 049 * </ul> 050 */ 051@Rest(path="/about", title="About") 052@SuppressWarnings({ 053 "java:S110" // Inheritance depth comes from the BasicRestServlet hierarchy, not this page. 054}) 055public class AboutRest extends PetstoreConsolePage { 056 057 private static final long serialVersionUID = 1L; 058 059 /** 060 * The About page. 061 * 062 * @param req The request; {@code ?builder} renders the builder twin. 063 * @return The page. 064 */ 065 @RestGet(path="/") 066 public View page(RestRequest req) { 067 return builder(req) ? twin(req, AboutPageBuilders.about()) : FreemarkerView.of("about.ftlh"); 068 } 069 070 /** 071 * Lists the three utility-bean demos. 072 * 073 * <p> 074 * Each link is {@code servlet:/}-relative, so the uri carries the {@code beans/} segment. 075 * 076 * @return Descriptive links to the demos. 077 */ 078 @RestGet(path="/beans") 079 public ResourceDescriptions beans() { 080 return ResourceDescriptions.create() 081 .append("BeanDescription", "beans/BeanDescription", "Example of a BeanDescription bean, describing the Pet domain bean") 082 .append("Hyperlink", "beans/Hyperlink", "Example of a Hyperlink bean") 083 .append("SeeOtherRoot", "beans/SeeOtherRoot", "Example of a SeeOtherRoot bean"); 084 } 085 086 /** @return A {@link BeanDescription} of {@link Pet}. */ 087 @RestGet(path="/beans/BeanDescription") 088 public BeanDescription beanDescription() { 089 return BeanDescription.of(Pet.class); 090 } 091 092 /** @return A hyperlink back to this page. */ 093 @RestGet(path="/beans/Hyperlink") 094 public Hyperlink hyperlink() { 095 return Hyperlink.create("/console/about", "Back to About"); 096 } 097 098 /** @return A redirect to the servlet root. */ 099 @RestGet(path="/beans/SeeOtherRoot") 100 public SeeOtherRoot seeOtherRoot() { 101 return SeeOtherRoot.INSTANCE; 102 } 103}