diff --git a/.github/rulesets/master.json b/.github/rulesets/master.json index 47d684a..ebb46a8 100644 --- a/.github/rulesets/master.json +++ b/.github/rulesets/master.json @@ -1,5 +1,5 @@ { - "id": 4327583, + "id": 4559383, "name": "master", "target": "branch", "source_type": "Repository", @@ -43,7 +43,15 @@ "do_not_enforce_on_create": false, "required_status_checks": [ { - "context": "lint", + "context": "build (check)", + "integration_id": 15368 + }, + { + "context": "build (test)", + "integration_id": 15368 + }, + { + "context": "Analyze (java)", "integration_id": 15368 } ] diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 867d05b..ee6f471 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -9,14 +9,12 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: CodeQL on: - push: - branches: [ "master" ] pull_request: - # The branches below must be a subset of the branches above - branches: [ "master" ] + branches: + - master schedule: - cron: '36 5 * * 4' @@ -61,7 +59,6 @@ jobs: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild diff --git a/README.md b/README.md index e0bf622..27b6cd1 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,16 @@ ## Purpose -The purpose of this template is to speed up the creation of new Spring applications within HMCTS -and help keep the same standards across multiple teams. If you need to create a new app, you can -simply use this one as a starting point and build on top of it. +The purpose of this template is to speed up the creation of new Spring applications within HMCTS. ## What's inside The template is a working application with a minimal setup. It contains: * application skeleton * setup script to prepare project -* common plugins and libraries +* Standard plugins and libraries * [HMCTS Java plugin](https://github.com/hmcts/gradle-java-plugin) * docker setup -* automatically publishes API documentation to [hmcts/cnp-api-docs](https://github.com/hmcts/cnp-api-docs) -* code quality tools already set up * MIT license and contribution information * Helm chart using chart-java. @@ -85,10 +81,6 @@ The template contains the following plugins: ./gradlew dependencyUpdates -Drevision=release ``` -## Setup - -Located in `./bin/init.sh`. Simply run and follow the explanation how to execute it. - ## Building and deploying the application ### Building the application @@ -110,9 +102,10 @@ Create the image of the application by executing the following command: ./gradlew assemble ``` -Note: Docker Compose V2 is highly recommended for building and running the application. -In the Compose V2 old `docker-compose` command is replaced with `docker compose`. +Local installation of docker: [Get Docker](https://docs.docker.com/get-started/get-docker/) +``` +``` Create docker image: ```bash diff --git a/build.gradle b/build.gradle index 2516344..0882016 100644 --- a/build.gradle +++ b/build.gradle @@ -218,12 +218,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-json' implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.6' - implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: '6.1.8' - - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4JVersion - implementation group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: log4JVersion - implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion - implementation group: 'ch.qos.logback', name: 'logback-core', version: logbackVersion + implementation 'com.microsoft.azure:applicationinsights-spring-boot-starter:2.6.4' + implementation 'net.logstash.logback:logstash-logback-encoder:7.4' implementation group: 'io.rest-assured', name: 'rest-assured', version: '5.5.1' diff --git a/src/main/java/uk/gov/hmcts/cp/Application.java b/src/main/java/uk/gov/hmcts/cp/Application.java index f0e388d..896b655 100644 --- a/src/main/java/uk/gov/hmcts/cp/Application.java +++ b/src/main/java/uk/gov/hmcts/cp/Application.java @@ -2,12 +2,17 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @SpringBootApplication @SuppressWarnings("HideUtilityClassConstructor") public class Application { + private static final Logger logger = LoggerFactory.getLogger(Application.class); + public static void main(final String[] args) { + logger.info("Starting Spring Boot application..."); SpringApplication.run(Application.class, args); } } diff --git a/src/main/java/uk/gov/hmcts/cp/config/ApplicationConfig.java b/src/main/java/uk/gov/hmcts/cp/config/ApplicationConfig.java new file mode 100644 index 0000000..0f680da --- /dev/null +++ b/src/main/java/uk/gov/hmcts/cp/config/ApplicationConfig.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.cp.config; + +import com.microsoft.applicationinsights.TelemetryClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ApplicationConfig { + + @Bean + public TelemetryClient getTelemetryClient() { + return new TelemetryClient(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/cp/controllers/OpenApiController.java b/src/main/java/uk/gov/hmcts/cp/controllers/OpenApiController.java index 677594b..79149a2 100644 --- a/src/main/java/uk/gov/hmcts/cp/controllers/OpenApiController.java +++ b/src/main/java/uk/gov/hmcts/cp/controllers/OpenApiController.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.cp.controllers; +import com.microsoft.applicationinsights.TelemetryClient; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -8,14 +9,18 @@ import uk.gov.hmcts.cp.openapi.model.CourtHousesschema; import uk.gov.hmcts.cp.services.OpenApiService; +import java.util.Map; + @RestController @RequiredArgsConstructor public class OpenApiController implements DefaultApi { private final OpenApiService openApiService; + private final TelemetryClient telemetryClient; @Override public ResponseEntity courthousesCourtIdGet(String courtId) { + telemetryClient.trackEvent("GETCourthouseCourt", Map.of("courtId", courtId), null); CourtHousesschema courtHousesschema = openApiService.getCourtHouse(courtId); return new ResponseEntity<>(courtHousesschema, HttpStatus.OK); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 1fd2ec0..a5b395e 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -2,14 +2,10 @@ server: port: 4550 shutdown: "graceful" -# If you use a database then uncomment the `group:, readiness: and include: "db"` lines in the health probes and uncomment the datasource section management: endpoint: health: show-details: "always" - # group: - # readiness: - # include: "db" endpoints: web: base-path: / @@ -24,29 +20,12 @@ spring: config: import: "optional:configtree:/mnt/secrets/rpe/" application: - name: Spring Boot Template -# datasource: -# driver-class-name: org.postgresql.Driver -# url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}${DB_OPTIONS:} -# username: ${DB_USER_NAME} -# password: ${DB_PASSWORD} -# properties: -# charSet: UTF-8 -# hikari: -# minimumIdle: 2 -# maximumPoolSize: 10 -# idleTimeout: 10000 -# poolName: {to-be-defined}HikariCP -# maxLifetime: 7200000 -# connectionTimeout: 30000 -# jpa: -# properties: -# hibernate: -# jdbc: -# lob: -# # silence the 'wall-of-text' - unnecessary exception throw about blob types -# non_contextual_creation: true + name: ${APP_NAME:Spring Boot Template} azure: application-insights: instrumentation-key: ${rpe.AppInsightsInstrumentationKey:00000000-0000-0000-0000-000000000000} +# cosmos: +# uri: https://.documents.azure.com:443/ +# key: ${COSMOS_KEY} +# database: my-database-name diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..ab632f3 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + +