SystemInfoServiceImpl.java

  1. package edu.ucsb.cs156.courses.services;

  2. import edu.ucsb.cs156.courses.models.SystemInfo;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.boot.context.properties.ConfigurationProperties;
  6. import org.springframework.stereotype.Service;

  7. // This class relies on property values
  8. // For hints on testing, see: https://www.baeldung.com/spring-boot-testing-configurationproperties

  9. @Slf4j
  10. @Service("systemInfo")
  11. @ConfigurationProperties
  12. public class SystemInfoServiceImpl extends SystemInfoService {

  13.   @Value("${spring.h2.console.enabled:false}")
  14.   private boolean springH2ConsoleEnabled;

  15.   @Value("${app.showSwaggerUILink:false}")
  16.   private boolean showSwaggerUILink;

  17.   @Value("${app.startQtrYYYYQ:20221}")
  18.   private String startQtrYYYYQ;

  19.   @Value("${app.endQtrYYYYQ:20222}")
  20.   private String endQtrYYYYQ;

  21.   @Value("${app.sourceRepo:https://github.com/ucsb-cs156/proj-courses}")
  22.   private String sourceRepo;

  23.   @Value("${git.commit.message.short:unknown}")
  24.   private String commitMessage;

  25.   @Value("${git.commit.id.abbrev:unknown}")
  26.   private String commitId;

  27.   public static String githubUrl(String repo, String commit) {
  28.     return commit != null && repo != null ? repo + "/commit/" + commit : null;
  29.   }

  30.   public SystemInfo getSystemInfo() {
  31.     SystemInfo si =
  32.         SystemInfo.builder()
  33.             .springH2ConsoleEnabled(this.springH2ConsoleEnabled)
  34.             .showSwaggerUILink(this.showSwaggerUILink)
  35.             .startQtrYYYYQ(this.startQtrYYYYQ)
  36.             .endQtrYYYYQ(this.endQtrYYYYQ)
  37.             .sourceRepo(this.sourceRepo)
  38.             .commitMessage(this.commitMessage)
  39.             .commitId(this.commitId)
  40.             .githubUrl(githubUrl(this.sourceRepo, this.commitId))
  41.             .build();
  42.     log.info("getSystemInfo returns {}", si);
  43.     return si;
  44.   }
  45. }