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.springboot;
018
019import org.apache.juneau.commons.inject.*;
020import org.apache.juneau.http.response.*;
021import org.apache.juneau.marshall.html.*;
022import org.apache.juneau.marshall.serializer.*;
023import org.apache.juneau.petstore.console.*;
024import org.apache.juneau.petstore.console.data.*;
025import org.apache.juneau.petstore.rest.*;
026import org.apache.juneau.petstore.service.*;
027import org.apache.juneau.rest.server.*;
028import org.apache.juneau.rest.server.springboot.*;
029import org.apache.juneau.rest.server.widget.*;
030
031/**
032 * Root router resource for the Spring Boot deployment.
033 *
034 * <p>
035 * Extends {@link BasicSpringRestServletGroup} (i.e. {@link SpringRestServlet}) so child resources can be resolved
036 * as Spring beans — required for {@link HelloResource} to receive its {@code @Autowired} {@link HelloMessageProvider}.
037 * Mounts the deployment-agnostic {@link PetStoreResource} from {@code juneau-petstore-core} alongside the local
038 * {@link HelloResource} injection demo.
039 *
040 * <p>
041 * Note: this Spring Boot deployment intentionally does NOT mount the Jetty/Microservice admin trio
042 * ({@code ConfigResource}/{@code LogsResource}/{@code ShutdownResource}, now in the
043 * {@code juneau-microservice-examples} module) — those are Jetty-only and have no meaningful analogue here
044 * (Spring Boot has its own actuator surface).  This is the documented non-parity deployment-specific
045 * difference between the two petstore deployments.
046 *
047 * <h5 class='section'>See Also:</h5><ul>
048 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauPetstore">juneau-petstore</a>
049 * </ul>
050 *
051 * @serial exclude
052 */
053@Rest(
054   title="Juneau Petstore (Spring Boot)",
055   description="Apache Juneau petstore sample application running under Spring Boot.",
056   children={
057      PetstoreConsoleResource.class,
058      ConsoleAssetsRest.class,
059      PetStoreResource.class,
060      PetstoreUiResource.class,
061      HelloResource.class
062   }
063)
064@HtmlDocConfig(
065   widgets={
066      ContentTypeMenuItem.class
067   },
068   navlinks={
069      "api: servlet:/api",
070      "stats: servlet:/stats",
071      "$W{ContentTypeMenuItem}",
072      "source: $C{Source/gitHub}/org/apache/juneau/petstore/springboot/RootResources.java"
073   },
074   aside={
075      "<div class='text'>",
076      "\t<p>Apache Juneau petstore sample application — Spring Boot deployment.</p>",
077      "\t<p>This is the same Juneau REST surface as the Jetty deployment, deployed unchanged under Spring Boot",
078      "\t   (note: child resources resolve as Spring beans).</p>",
079      "</div>"
080   },
081   asideFloat="RIGHT"
082)
083@SerializerConfig(
084   // Single quotes for consistency with other Juneau samples — simplifies HTML/string assertions in tests.
085   quoteChar="'"
086)
087@SuppressWarnings({
088   "java:S110" // Inheritance depth acceptable for example/demo code
089})
090public class RootResources extends BasicSpringRestServletGroup {
091
092   private static final long serialVersionUID = 1L;
093
094   /**
095    * Registers the one {@link PetStore} shared by the {@code /petstore} API and the console tree, seeded with the
096    * deterministic demo data set.
097    *
098    * <p>
099    * Child resources inherit the group's beans, so a plain {@code @Bean} method is all that is needed.
100    *
101    * @return The seeded {@link PetStore}.
102    */
103   @Bean
104   public PetStore petStore() {
105      return PetstoreSeed.create().populate(new PetStore());
106   }
107
108   /**
109    * {@code GET /} goes to the console store page.
110    *
111    * @param req The request.
112    * @return A 303 to {@code /console/store}.
113    */
114   @RestGet(path="/")
115   public SeeOther index(RestRequest req) {
116      return new SeeOther().setLocation(req.getUriResolver().resolve("servlet:/console/store"));
117   }
118}