Skip to content

Commit 1a0c000

Browse files
author
Sergio Andres Mejia Tovar
committed
[WIT-2829] Implement the sync java tech adapter framework
# New features and improvements * Implements support for synchronous validation, provisioning, unprovisioning, update ACL and reverse provisioning on the framework * Provides autoconfiguration for ProvisionConfiguration and ValidationConfiguration classes with a failure behaviour, overridable by the user. * Provides `ComponentClassProviderImpl` and `SpecificClassProviderImpl` as base implementations of their interfaces to easily bootstrap simple use-cases Tech Adapters. * Provides a guide on how to bootstrap a brand new Tech Adapter, and how to migrate existing Tech Adapters that are based on the old Java Scaffold project. # Related issue Closes WIT-2829 # Definition of Done So you are going to put your MR in review, but are you sure you have done all things listed here? ## All Developments - [x] **Feature was implemented as per the requirements** - [x] **If some code parts are complex they must be commented with code documentation** - [x] **Unit, integration and E2E tests have been performed and code coverage is not reduced**, so that new code is covered - [x] **CI/CD is successful** - [x] **Exceptions and errors are handled, returning meaningful errors to the user**, without letting the underlying framework to respond with a generic Internal Server Error. Technical details are stored in the errors/problems and not in the user message - [x] **Documentation (user documentation, HLD and others) has been updated** - Documentation has been updated with explanation of the new feature if it's user-facing (e.g. component now has additional setting) or it impacts them in some other way (e.g. optional field that becomes mandatory) - If it is a breaking change, we have documented it as such in the MR description in a "Breaking Changes" section - [x] **Helm chart and other DevOps artifacts** have been updated and are valid deployment tools for the new version - [x] **Problematic information (sensitive information, credentials, customer information or other intellectual property) is not included in the changes** as they could end up being public (most SPs are already published and automatically mirrored on every merge) - [x] **Feature doesn't negatively affect any existing environments**, especially the clients Playgrounds. This means that merging it to master and deploying it to these environments will not break them and **no manual operations that are not reported in the documentation will be needed** - [x] **If dependencies were changed, be sure that they will not impact the project**, that their license is compatible, and that they introduce no vulnerabilities - [x] **Security, Authentication and Authorization have been considered**. No SQL injection, tokens handling, RBAC integration. Common security vulnerabilities identified and resolved ## API related Development - [x] **API Parameters and return body are compliant** with the API specification - [x] **Errors are correctly handled**, respecting the type of errors return bodies and responses for each endpoint - [x] **API is logging in compliance with audit standards**, presence of sensitive information for GDPR has been assessed and removed or managed in case is needed ## DB related Development - [ ] **The database schema is designed to accurately** represent the data model and meet the requirements - [ ] **Tables, relationships, and constraints (e.g. primary keys, foreign keys, unique constraints) are defined appropriately**, following best practices and a common naming convention - [ ] **Sensitive data is stored securely**, encrypted if required, and access is restricted to authorized users - [ ] **Migration scripts to upgrade and downgrade the database have been implemented and tested**
1 parent df5908c commit 1a0c000

File tree

96 files changed

+6033
-1064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+6033
-1064
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ target/
22
!.mvn/wrapper/maven-wrapper.jar
33
!**/src/main/**/target/
44
!**/src/test/**/target/
5+
.flattened-pom.xml
56

67
### IntelliJ IDEA ###
78
.idea/modules.xml

.gitlab-ci.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ include:
44
file: 'common/witboost.helm.gitlab-ci.yml'
55
- template: Security/SAST.gitlab-ci.yml
66
- template: Security/Secret-Detection.gitlab-ci.yml
7-
- template: Jobs/Container-Scanning.gitlab-ci.yml
87

98
image: maven:3.9.4-eclipse-temurin-17
109

1110
variables:
12-
MAVEN_CLI_OPTS: "-s ci_settings.xml --batch-mode"
13-
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
11+
MAVEN_CLI_OPTS: "--batch-mode"
12+
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Drevision=$VERSION"
1413

1514
cache:
1615
paths:
@@ -33,7 +32,6 @@ setup:
3332
- !reference [.witboost.helm.clone-scripts, script]
3433
- !reference [.witboost.helm.get-version, script]
3534
- echo "VERSION=${VERSION}" >> vars.env
36-
- echo "FRAMEWORK_VERSION=${VERSION}" >> vars.env
3735
artifacts:
3836
reports:
3937
dotenv: vars.env
@@ -151,7 +149,7 @@ package:
151149
paths:
152150
- common/target/*.jar
153151

154-
publish:
155-
stage: publish
156-
script:
157-
- mvn -DskipTests=true deploy -s ci_settings.xml
152+
#publish:
153+
# stage: publish
154+
# script:
155+
# - mvn -DskipTests=true deploy -s ci_settings.xml

README.md

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This repository is part of our [Starter Kit](https://github.com/agile-lab-dev/wi
1414
- [Using this library](#using-this-library)
1515
- [Building](#building)
1616
- [API specification](docs/API.md)
17+
- [Compatibility matrix](docs/compatibility_matrix.md)
1718
- [License](#license)
1819

1920

@@ -90,48 +91,41 @@ pre-commit install
9091

9192
## Using this library
9293

93-
Add the following dependency on your `pom.xml`:
94-
95-
```xml
96-
<dependency>
97-
<groupId>com.witboost.provisioning</groupId>
98-
<artifactId>java-tech-adapter-framework-core</artifactId>
99-
<version>${env.FRAMEWORK_VERSION}</version>
100-
</dependency>
101-
```
102-
103-
Where `${env.FRAMEWORK_VERSION}` is the library version.
104-
105-
To be able to use Spring Boot, you need to set Spring Boot 2.3.2 as a parent on your `pom.xml` and setup the actuator dependencies:
94+
Add the following on your `pom.xml`:
10695

10796
```xml
10897
<project ...>
98+
...
10999
<parent>
110100
<groupId>org.springframework.boot</groupId>
111101
<artifactId>spring-boot-starter-parent</artifactId>
112102
<version>3.2.3</version>
113103
<relativePath/> <!-- lookup parent from repository -->
114104
</parent>
115-
105+
...
116106
<dependencies>
117107
<dependency>
118-
<groupId>org.springframework.boot</groupId>
119-
<artifactId>spring-boot-starter-actuator</artifactId>
108+
<groupId>com.witboost.provisioning</groupId>
109+
<artifactId>java-tech-adapter-framework-core</artifactId>
110+
<version>X.X.X</version>
120111
</dependency>
121112
</dependencies>
113+
...
122114
</project>
123115
```
124116

117+
Where `X.X.X` is the library version you desire to use.
118+
125119
### Implementing server logic
126120

127121
The Java Tech Adapter Framework provides four interfaces to be implemented in order to plug your business logic into the provisioning workflow. These are:
128122

129-
`ProvisionService`: Provides the business logic for component provision, unprovision, update access control, and reverse provisioning.
130-
`ComponentValidationService`: Provides the business logic for component validation, executed for validation and (un)provisioning operations.
131-
`ComponentClassProvider`: Interface that maps a component's `useCaseTemplateId` with a Class that represents the Component model, allowing to use extensions of the provided Components.
132-
`SpecificClassProvider`: Interface that maps a component's `useCaseTemplateId` with a Class that represents the Specific model.
123+
- `ProvisionService`: Provides the business logic for component provision, unprovision, update access control, and reverse provisioning.
124+
- `ComponentValidationService`: Provides the business logic for component validation, executed for validation and (un)provisioning operations.
125+
- `ComponentClassProvider`: Interface that maps a component's `useCaseTemplateId` with a Class that represents the Component model, allowing to use extensions of the provided Components.
126+
- `SpecificClassProvider`: Interface that maps a component's `useCaseTemplateId` with a Class that represents the Specific model.
133127

134-
As of the current version, all four interfaces are mandatory, providing an failure default implementation for each method. To understand the details to implement these interfaces, check the guide.
128+
As of the current version, all four interfaces are mandatory, providing a failure default implementation for each method. To understand the details to implement these interfaces, check the [implementation and migration guide](docs/usage.md).
135129

136130
## Building
137131

@@ -140,10 +134,16 @@ As of the current version, all four interfaces are mandatory, providing an failu
140134
- Java 17
141135
- Apache Maven 3.9+
142136

143-
**Version:** the version is set dynamically via an environment variable, `FRAMEWORK_VERSION`. Make sure you have it exported, even for local development. Example:
137+
**Version:** the version is set dynamically via Maven configuration variables following the [CI Friendly Versions](https://maven.apache.org/maven-ci-friendly.html) setup, so be sure to configure your environment to include the Maven variable `revision` set to the version. For example, you can use the `MAVEN_OPTS` environment variable to set up this as:
144138

145139
```bash
146-
export FRAMEWORK_VERSION=0.0.0-SNAPHSOT
140+
export MAVEN_OPTS="-Drevision=0.0.0-SNAPHSOT"
141+
```
142+
143+
*Note:* When running in the CI/CD pipeline the version for the project is automatically computed using information gathered from Git, using branch name and tags. Unless you are on a release branch `1.2.x` or a tag `v1.2.3` it will end up being `0.0.0`. You can follow this branch/tag convention or update the version computation to match your preferred strategy. When running locally if you do not care about the version (ie, nothing gets published or similar) you can manually set the Maven configuration variable `revision` to avoid warnings and oddly-named artifacts; as an example you can set it to the build using a timestamp like this:
144+
145+
```bash
146+
export MAVEN_OPTS="-Drevision=$(date +%Y%m%d-%H%M%S)"
147147
```
148148

149149
**Build:**
@@ -172,24 +172,12 @@ mvn spotbugs:check
172172
mvn test
173173
```
174174

175-
**Artifacts & Docker image:** the project leverages Maven for packaging. Build artifacts (normal and fat jar) with:
176-
177-
```bash
178-
mvn package spring-boot:repackage
179-
```
180-
181-
The Docker image can be built with:
175+
**Artifacts:** the project leverages Maven for packaging. Build artifacts with:
182176

183177
```bash
184-
docker build .
178+
mvn package
185179
```
186180

187-
More details can be found [here](docs/docker.md).
188-
189-
*Note:* when running in the CI/CD pipeline the version for the project is automatically computed using information gathered from Git, using branch name and tags. Unless you are on a release branch `1.2.x` or a tag `v1.2.3` it will end up being `0.0.0`. You can follow this branch/tag convention or update the version computation to match your preferred strategy. When running locally if you do not care about the version (ie, nothing gets published or similar) you can manually set the environment variable `FRAMEWORK_VERSION` to avoid warnings and oddly-named artifacts; as an example you can set it to the build time like this:
190-
```bash
191-
export FRAMEWORK_VERSION=$(date +%Y%m%d-%H%M%S);
192-
```
193181

194182
**CI/CD:** the pipeline is based on GitLab CI as that's what we use internally. It's configured by the `.gitlab-ci.yaml` file in the root of the repository. You can use that as a starting point for your customizations.
195183

ci_settings.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

core/pom.xml

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.witboost.provisioning</groupId>
88
<artifactId>java-tech-adapter-framework</artifactId>
9-
<version>${env.FRAMEWORK_VERSION}</version>
9+
<version>${revision}</version>
1010
</parent>
1111

1212
<properties>
@@ -15,18 +15,11 @@
1515
</properties>
1616

1717
<artifactId>java-tech-adapter-framework-core</artifactId>
18+
<name>java-tech-adapter-framework-core</name>
1819
<packaging>jar</packaging>
1920

2021
<build>
2122
<plugins>
22-
<plugin>
23-
<groupId>org.springframework.boot</groupId>
24-
<artifactId>spring-boot-maven-plugin</artifactId>
25-
<configuration>
26-
<mainClass>com.witboost.provisioning.framework.Main</mainClass>
27-
<layout>JAR</layout>
28-
</configuration>
29-
</plugin>
3023
<plugin>
3124
<groupId>com.diffplug.spotless</groupId>
3225
<artifactId>spotless-maven-plugin</artifactId>
@@ -57,7 +50,7 @@
5750
<plugin>
5851
<groupId>org.openapitools</groupId>
5952
<artifactId>openapi-generator-maven-plugin</artifactId>
60-
<version>6.5.0</version>
53+
<version>7.5.0</version>
6154
<executions>
6255
<execution>
6356
<goals>
@@ -74,6 +67,7 @@
7467
<supportingFilesToGenerate>
7568
ApiUtil.java
7669
</supportingFilesToGenerate>
70+
7771
<configOptions>
7872
<sourceFolder>/src/main/java</sourceFolder>
7973
<implFolder>/src/main/java</implFolder>
@@ -93,49 +87,40 @@
9387
<dependency>
9488
<groupId>com.witboost.provisioning</groupId>
9589
<artifactId>java-tech-adapter-framework-model</artifactId>
96-
<version>${env.FRAMEWORK_VERSION}</version>
90+
<version>${project.parent.version}</version>
9791
</dependency>
92+
9893
<dependency>
9994
<groupId>org.springframework.boot</groupId>
10095
<artifactId>spring-boot-starter-actuator</artifactId>
10196
</dependency>
102-
<dependency>
103-
<groupId>io.swagger.parser.v3</groupId>
104-
<artifactId>swagger-parser</artifactId>
105-
</dependency>
106-
<dependency>
107-
<groupId>org.openapitools</groupId>
108-
<artifactId>jackson-databind-nullable</artifactId>
109-
</dependency>
11097
<dependency>
11198
<groupId>org.springframework.boot</groupId>
11299
<artifactId>spring-boot-starter-validation</artifactId>
113100
</dependency>
114-
115-
<dependency>
116-
<groupId>io.micrometer</groupId>
117-
<artifactId>micrometer-tracing-bridge-otel</artifactId>
118-
</dependency>
119101
<dependency>
120-
<groupId>io.micrometer</groupId>
121-
<artifactId>micrometer-registry-prometheus</artifactId>
122-
<scope>runtime</scope>
102+
<groupId>org.springframework.boot</groupId>
103+
<artifactId>spring-boot-starter-web</artifactId>
123104
</dependency>
124-
125105
<dependency>
126106
<groupId>org.springframework.boot</groupId>
127107
<artifactId>spring-boot-starter-test</artifactId>
128108
<scope>test</scope>
129109
</dependency>
130110

131111
<dependency>
132-
<groupId>org.springframework.boot</groupId>
133-
<artifactId>spring-boot-starter-web</artifactId>
112+
<groupId>io.swagger.parser.v3</groupId>
113+
<artifactId>swagger-parser</artifactId>
114+
</dependency>
115+
<dependency>
116+
<groupId>org.openapitools</groupId>
117+
<artifactId>jackson-databind-nullable</artifactId>
134118
</dependency>
135119

136120
<dependency>
137121
<groupId>org.projectlombok</groupId>
138122
<artifactId>lombok</artifactId>
123+
<version>1.18.34</version>
139124
<optional>true</optional>
140125
</dependency>
141126

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.witboost.provisioning.autoconfigure;
2+
3+
import com.witboost.provisioning.framework.service.ProvisionConfiguration;
4+
import com.witboost.provisioning.framework.service.ProvisionService;
5+
import com.witboost.provisioning.framework.service.SyncTechAdapterService;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
7+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
/**
12+
* Provides autoconfiguration for the {@link ProvisionConfiguration} class which encapsulates the set of {@link ProvisionService}
13+
* interfaces for the different types of supported components. Configures the behaviour as the interface default behaviour,
14+
* which returns an error explaining that provisioning operations are not supported for any component.
15+
*
16+
* @see ProvisionConfiguration
17+
* @see ProvisionService
18+
*/
19+
@Configuration
20+
@ConditionalOnClass(SyncTechAdapterService.class)
21+
public class ProvisionAutoConfiguration {
22+
23+
@Bean
24+
@ConditionalOnMissingBean
25+
public ProvisionConfiguration provisionConfiguration() {
26+
return new ProvisionConfiguration(
27+
new ProvisionService() {}, new ProvisionService() {}, new ProvisionService() {});
28+
}
29+
30+
@Bean
31+
@ConditionalOnMissingBean
32+
ProvisionService provisionService() {
33+
return new ProvisionService() {};
34+
}
35+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.witboost.provisioning.autoconfigure;
2+
3+
import com.witboost.provisioning.framework.service.ComponentClassProvider;
4+
import com.witboost.provisioning.framework.service.SpecificClassProvider;
5+
import com.witboost.provisioning.framework.service.impl.ComponentClassProviderImpl;
6+
import com.witboost.provisioning.framework.service.impl.SpecificClassProviderImpl;
7+
import com.witboost.provisioning.framework.service.validation.*;
8+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
13+
/**
14+
* Provides autoconfiguration for the validation and parsing interfaces, including the
15+
* {@link ValidationConfiguration} class which encapsulates the set of {@link ComponentValidationService} interfaces for
16+
* the different types of supported components, and the {@link ComponentClassProvider} and {@link SpecificClassProvider} for class mapping.
17+
* Configures the behaviour as the interface default behaviour, which returns an error explaining that validation is not supported for any component.
18+
*
19+
* @see ValidationConfiguration
20+
* @see ComponentValidationService
21+
* @see ComponentClassProvider
22+
* @see SpecificClassProvider
23+
*
24+
*/
25+
@Configuration
26+
@ConditionalOnClass(ValidationServiceImpl.class)
27+
public class ValidationAutoConfiguration {
28+
29+
@Bean
30+
@ConditionalOnMissingBean
31+
public ValidationConfiguration validationConfiguration() {
32+
return new ValidationConfiguration(
33+
new ComponentValidationService() {},
34+
new ComponentValidationService() {},
35+
new ComponentValidationService() {});
36+
}
37+
38+
@Bean
39+
@ConditionalOnMissingBean
40+
public SpecificClassProvider specificMapper() {
41+
return SpecificClassProviderImpl.builder().build();
42+
}
43+
44+
@Bean
45+
@ConditionalOnMissingBean
46+
public ComponentClassProvider componentClassProvider() {
47+
return ComponentClassProviderImpl.builder().build();
48+
}
49+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.witboost.provisioning.framework;
2+
3+
/**
4+
* Empty class to be used as a hook to enable package scanning by Spring Boot. It is intended to be part of the {@code @SpringBootApplication scanBasePackageClasses} and
5+
* {@code @ConfigurationPropertiesScan basePackageClasses} on your Main application
6+
*
7+
* @see org.springframework.boot.autoconfigure.SpringBootApplication
8+
* @see org.springframework.boot.context.properties.ConfigurationPropertiesScan
9+
*/
10+
public class JavaTechAdapterFramework {}

core/src/main/java/com/witboost/provisioning/framework/Main.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)