// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/domain/Link.java
// @Entity
// @Table(name = "links")
// public class Link {
// 
//   @Id
//   @Column(name = "stub")
//   @Pattern(regexp = "^([a-zA-Z0-9]+(-[a-zA-Z0-9+])*)$")
//   private String stub;
// 
//   @Column(name = "url")
//   @NotBlank
//   @Size(max = 1024)
//   private String url;
// 
//   public String getStub() {
//     return stub;
//   }
// 
//   public void setStub(String stub) {
//     this.stub = stub;
//   }
// 
//   public String getUrl() {
//     return url;
//   }
// 
//   public void setUrl(String url) {
//     this.url = url;
//   }
// }
// 
// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/domain/LinkInfo.java
// public class LinkInfo {
// 
//   private boolean local;
//   private ThreatStatus threatStatus = ThreatStatus.UNKNOWN;
// 
//   public boolean isLocal() {
//     return local;
//   }
// 
//   public void setLocal(boolean local) {
//     this.local = local;
//   }
// 
//   public ThreatStatus getThreatStatus() {
//     return threatStatus;
//   }
// 
//   public void setThreatStatus(ThreatStatus threatStatus) {
//     this.threatStatus = threatStatus;
//   }
// }
// 
// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/repositories/LinkRepository.java
// @Repository
// public interface LinkRepository extends CrudRepository<Link, String> {
// 
// }
// 
// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/services/LinkInfoService.java
// @Service
// public class LinkInfoService {
// 
//   private static final Logger LOG = LoggerFactory.getLogger(LinkInfoService.class);
// 
//   @Value("${shortener.internal.domain}")
//   private String allowedUrlSuffix;
// 
//   @Autowired
//   private SafebrowsingService safebrowsingService;
// 
//   /**
//    * Get information about the given link.
//    *
//    * @param link the link to get information for
//    * @return data to augment the link, if the link is not local.
//    */
//   public LinkInfo getLinkInfo(final Link link) {
//     Objects.requireNonNull(link);
// 
//     final String url = link.getUrl();
// 
//     final LinkInfo output = new LinkInfo();
//     output.setLocal(isLocal(url));
// 
//     if (!output.isLocal()) {
//       output.setThreatStatus(safebrowsingService.threatStatus(url));
//     }
// 
//     return output;
//   }
// 
//   /**
//    * isLocal determines if the given URL is local to the domain (ends with allowedUrlSuffix).
//    *
//    * @param url the URL to check.
//    * @return true if the url ends with allowedUrlSuffix, false if the URL is bad or does not.
//    */
//   private boolean isLocal(final String url) {
//     Objects.requireNonNull(url);
// 
//     try {
//       return new URL(url)
//           .getHost()
//           .endsWith(allowedUrlSuffix);
//     } catch (MalformedURLException ex) {
//       LOG.error("couldn't parse URL", ex);
//       return false; // return false for safety
//     }
//   }
// }


import com.google.cloud.servicebroker.examples.linkshortener.domain.Link;
import com.google.cloud.servicebroker.examples.linkshortener.domain.LinkInfo;
import com.google.cloud.servicebroker.examples.linkshortener.repositories.LinkRepository;
import com.google.cloud.servicebroker.examples.linkshortener.services.LinkInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Optional;
/*
 * Copyright 2018 Google LLC
 *
 * 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
 *
 *     https://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.
 */

package com.google.cloud.servicebroker.examples.linkshortener.controllers;




/**
 * Contains the controller code for the main HTTP handlers.
 */
@Controller
@RequestMapping("/")
public class RouteController {

// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/domain/Link.java
// @Entity
// @Table(name = "links")
// public class Link {
// 
//   @Id
//   @Column(name = "stub")
//   @Pattern(regexp = "^([a-zA-Z0-9]+(-[a-zA-Z0-9+])*)$")
//   private String stub;
// 
//   @Column(name = "url")
//   @NotBlank
//   @Size(max = 1024)
//   private String url;
// 
//   public String getStub() {
//     return stub;
//   }
// 
//   public void setStub(String stub) {
//     this.stub = stub;
//   }
// 
//   public String getUrl() {
//     return url;
//   }
// 
//   public void setUrl(String url) {
//     this.url = url;
//   }
// }
// 
// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/domain/LinkInfo.java
// public class LinkInfo {
// 
//   private boolean local;
//   private ThreatStatus threatStatus = ThreatStatus.UNKNOWN;
// 
//   public boolean isLocal() {
//     return local;
//   }
// 
//   public void setLocal(boolean local) {
//     this.local = local;
//   }
// 
//   public ThreatStatus getThreatStatus() {
//     return threatStatus;
//   }
// 
//   public void setThreatStatus(ThreatStatus threatStatus) {
//     this.threatStatus = threatStatus;
//   }
// }
// 
// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/repositories/LinkRepository.java
// @Repository
// public interface LinkRepository extends CrudRepository<Link, String> {
// 
// }
// 
// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/services/LinkInfoService.java
// @Service
// public class LinkInfoService {
// 
//   private static final Logger LOG = LoggerFactory.getLogger(LinkInfoService.class);
// 
//   @Value("${shortener.internal.domain}")
//   private String allowedUrlSuffix;
// 
//   @Autowired
//   private SafebrowsingService safebrowsingService;
// 
//   /**
//    * Get information about the given link.
//    *
//    * @param link the link to get information for
//    * @return data to augment the link, if the link is not local.
//    */
//   public LinkInfo getLinkInfo(final Link link) {
//     Objects.requireNonNull(link);
// 
//     final String url = link.getUrl();
// 
//     final LinkInfo output = new LinkInfo();
//     output.setLocal(isLocal(url));
// 
//     if (!output.isLocal()) {
//       output.setThreatStatus(safebrowsingService.threatStatus(url));
//     }
// 
//     return output;
//   }
// 
//   /**
//    * isLocal determines if the given URL is local to the domain (ends with allowedUrlSuffix).
//    *
//    * @param url the URL to check.
//    * @return true if the url ends with allowedUrlSuffix, false if the URL is bad or does not.
//    */
//   private boolean isLocal(final String url) {
//     Objects.requireNonNull(url);
// 
//     try {
//       return new URL(url)
//           .getHost()
//           .endsWith(allowedUrlSuffix);
//     } catch (MalformedURLException ex) {
//       LOG.error("couldn't parse URL", ex);
//       return false; // return false for safety
//     }
//   }
// }


// Path: link-shortener/src/main/java/com/google/cloud/servicebroker/examples/linkshortener/controllers/RouteController.java
import com.google.cloud.servicebroker.examples.linkshortener.domain.Link;
import com.google.cloud.servicebroker.examples.linkshortener.domain.LinkInfo;
import com.google.cloud.servicebroker.examples.linkshortener.repositories.LinkRepository;
import com.google.cloud.servicebroker.examples.linkshortener.services.LinkInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Optional;

/*
 * Copyright 2018 Google LLC
 *
 * 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
 *
 *     https://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.
 */

package com.google.cloud.servicebroker.examples.linkshortener.controllers;




/**
 * Contains the controller code for the main HTTP handlers.
 */
@Controller
@RequestMapping("/")
public class RouteController {

  @Autowired