|
1 | | -[](https://circleci.com/gh/GreenButtonAlliance/OpenESPI-DataCustodian-java/tree/master) |
| 1 | +[](https://github.com/GreenButtonAlliance/OpenESPI-DataCustodian-java/actions) |
| 2 | +[](https://github.com/GreenButtonAlliance/OpenESPI-DataCustodian-java/actions/workflows/ci.yml) |
2 | 3 | [](https://sonarcloud.io/dashboard?id=GreenButtonAlliance_OpenESPI-DataCustodian-java) |
3 | | - |
| 4 | +[](https://spring.io/projects/spring-boot) |
| 5 | +[](https://openjdk.org/) |
| 6 | +[](https://maven.apache.org/) |
| 7 | +[](https://jakarta.ee/) |
| 8 | +[](https://hibernate.org/) |
| 9 | +[](https://mapstruct.org/) |
| 10 | +[](https://projectlombok.org/) |
| 11 | +[](https://www.apache.org/licenses/LICENSE-2.0) |
| 12 | +[](https://www.naesb.org/) |
4 | 13 |
|
5 | 14 | # OpenESPI-DataCustodian |
6 | 15 |
|
7 | | -The Open Energy Services Provider Interface (ESPI) Data Custodian Repository Providing implementations of the interface used to provide energy usage information to retail customers and third parties. |
| 16 | +A modern Spring Boot 3.5 implementation of the Open Energy Services Provider Interface (ESPI) Data Custodian, providing OAuth2 Resource Server capabilities for secure energy usage data access according to the North American Energy Standards Board (NAESB) REQ.21 ESPI specification. |
8 | 17 |
|
9 | | -An operational sandbox with these services operating may be found at: |
10 | | -<a href="https://sandbox.greenbuttonalliance.org:8443/DataCustodian">sandbox.greenbuttonalliance.org:8443/DataCustodian</a> |
| 18 | +## Overview |
11 | 19 |
|
12 | | -## Setup |
| 20 | +The OpenESPI-DataCustodian serves as a secure OAuth2 Resource Server that: |
13 | 21 |
|
14 | | -Note: You need to download and install [OpenESPI-Common-java](https://github.com/GreenButtonAlliance/OpenESPI-Common-java) into your local Maven repository to build this project. |
| 22 | +- **Protects energy usage data** with scope-based authorization (FB=1_3_4_5_13_14_15_39, FB=4_5_15) |
| 23 | +- **Provides RESTful APIs** for retail customers and third-party applications |
| 24 | +- **Implements ESPI 4.0 specification** with ATOM XML data formats |
| 25 | +- **Supports multiple databases** (MySQL, PostgreSQL, H2) with Flyway migrations |
| 26 | +- **Offers modern web interface** with Thymeleaf templates and Spring Security 6 |
15 | 27 |
|
16 | | -First clone the project from github: |
| 28 | +## Architecture |
17 | 29 |
|
18 | | -```bash |
19 | | -git clone https://github.com/GreenButtonAlliance/OpenESPI-DataCustodian-java.git |
20 | | -cd OpenESPI-DataCustodian/ |
21 | | -``` |
| 30 | +Built on **Spring Boot 3.5** with modern architectural patterns: |
22 | 31 |
|
| 32 | +- **OAuth2 Resource Server** with opaque token introspection |
| 33 | +- **Entity-based data model** with UUID primary keys (48-bit+ ESPI compliance) |
| 34 | +- **Service layer architecture** with DTO mapping via MapStruct |
| 35 | +- **Multi-profile configuration** for development, testing, and production |
| 36 | +- **Comprehensive testing** with TestContainers and Cucumber BDD |
23 | 37 |
|
24 | | -Build and start tomcat7 using maven (note: you must have first built the OpenESPI-Common-java jar): |
| 38 | +## Quick Start |
25 | 39 |
|
26 | | -```bash |
27 | | -mvn tomcat7:run |
28 | | -``` |
| 40 | +### Prerequisites |
| 41 | + |
| 42 | +- **Java 21+** (OpenJDK recommended) |
| 43 | +- **Maven 3.9+** |
| 44 | +- **MySQL 8.0+** or **PostgreSQL 15+** (for production) |
| 45 | +- **OpenESPI-Common-java** dependency (built automatically) |
29 | 46 |
|
30 | | -Now the application should be available at [http://localhost:8080/retailcustomers](http://localhost:8080/DataCustodian). |
| 47 | +### Clone and Build |
31 | 48 |
|
32 | | -## Building |
33 | 49 | ```bash |
34 | | -# for the default test profile |
| 50 | +git clone https://github.com/GreenButtonAlliance/OpenESPI-DataCustodian-java.git |
| 51 | +cd OpenESPI-DataCustodian-java |
| 52 | + |
| 53 | +# Build with default MySQL profile |
35 | 54 | mvn clean install |
36 | 55 |
|
37 | | -# or for a specific profile |
38 | | -mvn -P <profile name> -Dmaven.test.skip=true clean install |
| 56 | +# Or skip tests for faster build |
| 57 | +mvn clean install -DskipTests |
39 | 58 | ``` |
40 | 59 |
|
41 | | -## IDE Setup |
| 60 | +### Run Application |
42 | 61 |
|
43 | | -### Eclipse Setup |
| 62 | +```bash |
| 63 | +# Start with MySQL (default) |
| 64 | +mvn spring-boot:run |
44 | 65 |
|
45 | | -Open Eclipse and import a Maven project (File > Import... > Maven > Existing Maven Projects). |
| 66 | +# Start with PostgreSQL |
| 67 | +mvn spring-boot:run -Pdev-postgresql |
46 | 68 |
|
47 | | -### Spring Tool Suite Setup |
| 69 | +# Start with H2 (local development) |
| 70 | +mvn spring-boot:run -Plocal |
| 71 | +``` |
48 | 72 |
|
49 | | -Open Spring Tool Suite and import a Maven project (File > Import... > Maven > Existing Maven Projects). |
50 | | -To Run from within STS: |
| 73 | +The application will be available at: **http://localhost:8080** |
51 | 74 |
|
52 | | -right click on project and select RunOnServer |
| 75 | +## Configuration Profiles |
53 | 76 |
|
| 77 | +| Profile | Database | Use Case | |
| 78 | +|---------|----------|----------| |
| 79 | +| `dev-mysql` | MySQL | Default development (active by default) | |
| 80 | +| `dev-postgresql` | PostgreSQL | PostgreSQL development | |
| 81 | +| `local` | H2 | Local development/testing | |
| 82 | +| `prod` | MySQL | Production deployment | |
| 83 | +| `docker` | MySQL | Container deployment | |
| 84 | +| `aws-sandbox` | MySQL | AWS GBA Sandbox | |
54 | 85 |
|
55 | | -To run the DC and/or the TP: |
| 86 | +## Testing |
56 | 87 |
|
57 | | -do a maven build and install accordingly. Then the WAR files will be in the right position. |
| 88 | +### Unit Tests |
| 89 | +```bash |
| 90 | +mvn test |
| 91 | +``` |
| 92 | + |
| 93 | +### Integration Tests with TestContainers |
| 94 | +```bash |
| 95 | +# MySQL integration tests |
| 96 | +mvn verify -Ptestcontainers-mysql |
58 | 97 |
|
59 | | -To Start server: |
| 98 | +# PostgreSQL integration tests |
| 99 | +mvn verify -Ptestcontainers-postgresql |
| 100 | +``` |
60 | 101 |
|
| 102 | +### BDD Tests with Cucumber |
61 | 103 | ```bash |
62 | | -sudo /home/bitnami/springsource/vfabric-tc-server-developer-2.9.3.RELEASE/base-instance/bin/tcruntime-ctl.sh start |
| 104 | +mvn verify |
63 | 105 | ``` |
64 | | -To Stop server: |
65 | 106 |
|
| 107 | +### Code Coverage |
66 | 108 | ```bash |
67 | | -sudo /home/bitnami/springsource/vfabric-tc-server-developer-2.9.3.RELEASE/base-instance/bin/tcruntime-ctl.sh stop |
| 109 | +mvn verify jacoco:report |
| 110 | +# Reports available in target/site/jacoco/ |
68 | 111 | ``` |
69 | 112 |
|
70 | | -### IntelliJ Setup |
| 113 | +## API Documentation |
71 | 114 |
|
72 | | -Open IntelliJ and open the project (File > Open...). |
| 115 | +Interactive API documentation is available via **Swagger UI**: |
| 116 | +- **Development**: http://localhost:8080/swagger-ui.html |
| 117 | +- **Production**: Configure accordingly per environment |
73 | 118 |
|
74 | | -## Testing |
| 119 | +## Security |
75 | 120 |
|
76 | | -### Unit Tests |
| 121 | +This implementation follows **OAuth2 Resource Server** patterns: |
| 122 | + |
| 123 | +- **Opaque access tokens** (no JWT) per ESPI specification |
| 124 | +- **Scope-based authorization** with fine-grained permissions |
| 125 | +- **Spring Security 6** with modern security configurations |
| 126 | +- **OWASP dependency scanning** integrated in CI/CD |
| 127 | + |
| 128 | +## Development |
77 | 129 |
|
78 | | -To run all Unit tests: |
| 130 | +### IDE Setup |
79 | 131 |
|
| 132 | +**IntelliJ IDEA** (Recommended): |
80 | 133 | ```bash |
81 | | -mvn test |
82 | | -``` |
| 134 | +# Open project |
| 135 | +File → Open → select pom.xml |
83 | 136 |
|
84 | | -Run a single test class: |
| 137 | +# Enable annotation processing for Lombok/MapStruct |
| 138 | +Settings → Build → Compiler → Annotation Processors → Enable |
| 139 | +``` |
85 | 140 |
|
| 141 | +**Eclipse/Spring Tool Suite**: |
86 | 142 | ```bash |
87 | | -mvn -Dtest=<TestClassName> test |
88 | | -mvn -Dtest=HomeControllerTests test |
| 143 | +File → Import → Maven → Existing Maven Projects |
89 | 144 | ``` |
90 | 145 |
|
91 | | -Run a single test in a single class: |
| 146 | +### Code Quality |
92 | 147 |
|
93 | 148 | ```bash |
94 | | -mvn -Dtest=<TestClassName>#<testMethodName> testMethodName |
95 | | -mvn -Dtest=HomeControllerTests#index_shouldDisplayHomePage test |
96 | | -``` |
| 149 | +# Run OWASP security scan |
| 150 | +mvn org.owasp:dependency-check-maven:check |
97 | 151 |
|
98 | | -### Cucumber Features |
| 152 | +# Static analysis with SpotBugs |
| 153 | +mvn compile spotbugs:check |
| 154 | +``` |
99 | 155 |
|
100 | | -To run all Cucumber features: |
| 156 | +## Deployment |
101 | 157 |
|
| 158 | +### Docker |
102 | 159 | ```bash |
103 | | -mvn verify |
| 160 | +# Build application JAR |
| 161 | +mvn clean package -DskipTests |
| 162 | + |
| 163 | +# Run with Docker profile |
| 164 | +java -jar target/OpenESPI-DataCustodian.jar --spring.profiles.active=docker |
104 | 165 | ``` |
| 166 | +
|
| 167 | +### Production |
| 168 | +Configure production database and OAuth2 authorization server endpoints in: |
| 169 | +- `src/main/resources/application-prod.yml` |
| 170 | +- Environment variables or external configuration |
| 171 | +
|
| 172 | +## Contributing |
| 173 | +
|
| 174 | +1. **Fork** the repository |
| 175 | +2. **Create** a feature branch (`git checkout -b feature/amazing-feature`) |
| 176 | +3. **Follow** code style and add tests |
| 177 | +4. **Commit** changes (`git commit -m 'Add amazing feature'`) |
| 178 | +5. **Push** to branch (`git push origin feature/amazing-feature`) |
| 179 | +6. **Open** a Pull Request |
| 180 | +
|
| 181 | +## License |
| 182 | +
|
| 183 | +Licensed under the **Apache License 2.0**. See [LICENSE](LICENSE) for details. |
| 184 | +
|
| 185 | +## Support |
| 186 | +
|
| 187 | +- **Issues**: [GitHub Issues](https://github.com/GreenButtonAlliance/OpenESPI-DataCustodian-java/issues) |
| 188 | +- **Documentation**: [Green Button Alliance](https://www.greenbuttonalliance.org) |
| 189 | +- **Sandbox**: [https://sandbox.greenbuttonalliance.org:8443/DataCustodian](https://sandbox.greenbuttonalliance.org:8443/DataCustodian) |
0 commit comments