Skip to content

Commit

Permalink
Stabilisation13 (#734)
Browse files Browse the repository at this point in the history
* Updated Ballot reports to be ordered by juror last name (#730)

* update daily-utilisation-jurors to not fill up a null column if there is no entries for that specific day (#731)

* Fixed issue where attendance and payment history would show the incorrect data (#733)

* Hotfix/jm 8074 (#735)

* hotfix/JM-8074 Technical error when changing the deferral date using the "Change" button on the overview page

* reverting unwanted update for flyway

* Update build.gradle

* Update build.gradle

* updates for PMD and checkstyles

* Update README.md (#574)

* Update README.md

* Update README.md

* Update CreatePoolControllerITest.java

* Use Lazy loading instead of Eager to reduce database calls (#740)

* Updated Many classes to use Lazy Loading

* Removed comment

* Applied review comments

* Updated the way we show the jurors location to only show if they are checked in or on a trial (#745)

* Filtering on service start date on active pool screen only applies to page you filter on (#732)

* Updated pools-requested endpoint to use pagination Utils

* Fixed styles

* Updated active pools to use pagination utils

* Applied review comments

* update filters to add missing and update wrong ones (#743)

* update filters to add missing and update wrong ones

* update how we group-by on active pools filtering

* Fixed styles

---------

Co-authored-by: Ricardo <140706972+ricardofreitasrocha@users.noreply.github.com>

* Added includePanelMembers to person attending summary and detailed reports (#746)

* Fixed tests

* Remove JurorPoolUtils.getSingleActiveJurorPool() and replace with jurorPoolSerive.getActiveRecordFromUser() (#744)

* Updated the way we retrieve juror pools to prevent non-unique entry errors

* Applied review comments

* Fixed styles / merged stabilisation13

* fix_random_fail_test (#747)

* Permission change to allow the Bureau general users to edit change name / fix error in name option (#748)

* Updated permissions needed to fix error in current name

* Applied review comments

* hotfix/JM-8103 update to utilisation report functions (#749)

* hotfix/JM-8103 update to utilisation report functions

* updating tests

* updates following business review

* Added comments to sql file

* Active Pools Not Displaying Records (#750)

* Removed limits for active pool and pool requests

* Fixed styles

* Fixed styles

* Fixed issue where attendance audit number would incorrectly be added

* Fixed issue where attendance audit number would incorrectly be added

* Fixed styles

---------

Co-authored-by: Ricardo <140706972+ricardofreitasrocha@users.noreply.github.com>
Co-authored-by: akikrahman1 <149579836+akikrahman1@users.noreply.github.com>
Co-authored-by: akikrahman1 <akhlaqur.rahman1@hmcts.net>
  • Loading branch information
4 people authored Aug 28, 2024
1 parent b45348f commit a44626f
Show file tree
Hide file tree
Showing 131 changed files with 4,532 additions and 4,593 deletions.
145 changes: 144 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,146 @@
# Juror Backend API

# Juror Digital - API
This is the API for the Juror Modernisation project. It is a Spring Boot application that provides RESTful endpoints for
managing jurors.

# Building and deploying the application

## Prerequisites

- [Java 17](https://www.oracle.com/java)
- [Docker](https://www.docker.com)

### Environment variables

The following application settings are required to run the application. They can be set in the
`application-local.yaml` file or as environment variables. The application will look for the environment variables first.

```
DB_PASSWORD=postgres
DB_URL=jdbc:postgresql://localhost:5432/juror
DB_USERNAME=juror
JWT_SECRET_BUREAU=
JWT_SECRET_HMAC=
JWT_SECRET_PUBLIC=
NOTIFY_KEY=
NOTIFY_REGION_KEY_1=
NOTIFY_REGION_KEY_2=
NOTIFY_REGION_KEY_3=
NOTIFY_REGION_KEY_4=
NOTIFY_REGION_KEY_5=
NOTIFY_REGION_KEY_6=
NOTIFY_REGION_KEY_7=
PNC_CHECK_SERVICE_HOST=localhost
PNC_CHECK_SERVICE_PORT=8081
PNC_CHECK_SERVICE_SECRET=
PNC_CHECK_SERVICE_SUBJECT=juror-back-end
PROXY_HOST=10.100.1.4
PROXY_PORT=3182
SMART_SURVEY_SECRET=
SMART_SURVEY_TOKEN=
```

It is possible to configure IntelliJ to use these environment variables when running the application by setting up
default configurations. This can be done by going to `Run -> Edit Configurations` and setting the environment variables

Alternatively, its possible export the environment variables in the terminal before running the application. For example:

```bash
export DB_PASSWORD=secret
export DB_URL=jdbc:postgresql://localhost:5432/juror
export DB_USERNAME=juror
......
```

## Database setup

The application requires a Postgres database.

The latest official image of Postgres can be run from Docker Hub (https://hub.docker.com/_/postgres). To install, run the following command

```bash
docker pull postgres
```

create a local data folder, e.g. in the home directory
```bash
mkdir ~/postgres/data
```
Then to spin up a container run the following command:
```bash
docker run -d --name juror-postgres -e POSTGRES_USER=juror -e POSTGRES_PASSWORD=postgres -v ~/postgres/data:/var/lib/postgresql/data -p 5432:5432 postgres
```
From the root of the project, run the following command to create the database schema:
```bash
./gradlew flywayMigrate
```

## Building the application

The project uses [Gradle](https://gradle.org) as a build tool. It already contains
`./gradlew` wrapper script, so there's no need to install gradle.

To build the project execute the following command:

```bash
./gradlew build
```

### Jacoco Coverage Report

A local jacoco coverage report can be generated using the following command:-

```bash
./gradlew jacocoTestReport
```

The report will be available under ./build/jacocoHtml/index.html. The report incorporates both unit test
and integration test coverage

### Running the application locally via the terminal

The application can be run locally using the following command:

```bash
./gradlew bootRun
```

This will start the API exposing the application's port
(set to `8080` in this template app).

In order to test if the application is up, you can call its health endpoint:

```bash
curl http://localhost:8080/health
```

You should get a response similar to this:

```
{"status":"UP","components":{"db":{"status":"UP","details":{"database":"PostgreSQL","validationQuery":"isValid()"}}
,"diskSpace":{"status":"UP","details":{"total":250685575168,"free":108429410304,"threshold":10485760,
"path":"/Users/<user_name>/github/juror-api/.","exists":true}},"livenessState":{"status":"UP"},"ping":{"status":"UP"},
"readinessState":{"status":"UP"}},"groups":["liveness","readiness"]}%
```

It is possible to debug the application through Intellij selecting the appropriate run configuration or through gradle.

### Swagger UI

The application has Swagger enabled. To access the Swagger UI, navigate to `http://localhost:8080/swagger-ui.html`

## Spring Profiles

The following Spring Profiles are defined. "External Components" are defined as any service upon which the application
is dependent, such as web services, Notify etc.

| Profile | Purpose | External Components |
|---------------|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| `development` | For running the application in the Pull Request (dev) environment. | Interaction permitted with "real" components, which may be services deployed to a test environment. |
| `test` | For running application in build pipelines | No interaction required or permitted, all external calls are mocked , an embedded database (for db queries) |
| `production` | For running application in a live environment | Connected to real external interfaces as per live environments |


## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ checkstyle {
}

pmdTest {
maxFailures = 294
maxFailures = 292
}
pmdMain {
maxFailures = 776
maxFailures = 763
}
pmd {
maxFailures = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import uk.gov.hmcts.juror.api.config.bureau.BureauJwtPayload;
import uk.gov.hmcts.juror.api.moj.domain.Role;
import uk.gov.hmcts.juror.api.moj.domain.UserType;
Expand All @@ -31,6 +33,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -49,13 +52,31 @@ public abstract class AbstractIntegrationTest extends ContainerTest {
@SuppressWarnings("SpringJavaAutowiredMembersInspection")
@Autowired
protected JdbcTemplate jdbcTemplate;
@Autowired
private PlatformTransactionManager transactionManager;
private TransactionTemplate transactionTemplate;

@Value("${jwt.secret.bureau}")
protected String bureauSecret;

@Value("${jwt.secret.hmac}")
protected String hmacSecret;


protected void executeInTransaction(Runnable supplier) {
executeInTransaction(() -> {
supplier.run();
return null;
});
}

protected <R> R executeInTransaction(Supplier<R> supplier) {
if (transactionTemplate == null) {
transactionTemplate = new TransactionTemplate(transactionManager);
}
return transactionTemplate.execute(status -> supplier.get());
}

protected HttpHeaders initialiseHeaders(String loginUser, UserType userType, Set<Role> roles, String owner) {
BureauJwtPayload payload = createBureauJwtPayload(loginUser, userType, roles, owner);
return buildHttpHeaders(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ public void setUp() throws Exception {
@Test
@Sql("/db/truncate.sql")
@Sql("/db/BureauJurorSpecialNeedsRepository_findByJurorNumber.sql")
//FALSE positive
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void findByJurorNumberWithValidJurorNumberReturnsJurorSpecialNeeds() {
List<JurorReasonableAdjustment> actualReasonableAdjustment = jurorReasonableAdjustmentRepository
.findByJurorNumber("209092530");
assertThat(actualReasonableAdjustment).hasSize(1);
assertThat(actualReasonableAdjustment).extracting("jurorNumber", "reasonableAdjustment.code",
"reasonableAdjustment.description", "reasonableAdjustmentDetail")
.contains(tuple(reasonableAdjustment.getJurorNumber(),
reasonableAdjustment.getReasonableAdjustment().getCode(),
reasonableAdjustment.getReasonableAdjustment().getDescription(),
reasonableAdjustment.getReasonableAdjustmentDetail()));
executeInTransaction(() -> {
List<JurorReasonableAdjustment> actualReasonableAdjustment = jurorReasonableAdjustmentRepository
.findByJurorNumber("209092530");
assertThat(actualReasonableAdjustment).hasSize(1);
assertThat(actualReasonableAdjustment).extracting("jurorNumber", "reasonableAdjustment.code",
"reasonableAdjustment.description", "reasonableAdjustmentDetail")
.contains(tuple(reasonableAdjustment.getJurorNumber(),
reasonableAdjustment.getReasonableAdjustment().getCode(),
reasonableAdjustment.getReasonableAdjustment().getDescription(),
reasonableAdjustment.getReasonableAdjustmentDetail()));
});
}
}
Loading

0 comments on commit a44626f

Please sign in to comment.