-
Notifications
You must be signed in to change notification settings - Fork 12
Feature/data module extraction #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fb66abe
initial branch version
vktr7601 65ed0f6
fix defect with RestAssured config
vktr7601 6206c35
save changes before refactoring
vktr7601 96adb73
adding repository implementation
vktr7601 29269ba
save changes
vktr7601 3bc8bbf
adding repository implementatiom
vktr7601 73eedf3
Refactor folder structure
vktr7601 b433c3b
Folder structure updated
vktr7601 4a0eab2
before big refactor
vktr7601 079669f
adding new things
vktr7601 ed77b6d
adding fixes for http repository
vktr7601 651f1c9
adding new config
vktr7601 876a8b6
add events
vktr7601 e035037
fix before merge
vktr7601 132c3ed
Exception added when missing http settings in config file
vktr7601 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,4 +86,4 @@ public static String getFileAsString(String fileName) { | |
| return ""; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>solutions.bellatrix</groupId> | ||
| <artifactId>bellatrix</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>bellatrix.data</artifactId> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>19</maven.compiler.source> | ||
| <maven.compiler.target>19</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <rest.assured.version>5.5.5</rest.assured.version> | ||
| <gson.version>2.13.1</gson.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.google.code.gson</groupId> | ||
| <artifactId>gson</artifactId> | ||
| <version>${gson.version}</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>${lombok.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>solutions.bellatrix</groupId> | ||
| <artifactId>bellatrix.core</artifactId> | ||
| <version>1.0</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.rest-assured</groupId> | ||
| <artifactId>rest-assured</artifactId> | ||
| <version>${rest.assured.version}</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
13 changes: 13 additions & 0 deletions
13
bellatrix.data/src/main/java/solutions/bellatrix/data/configuration/DataSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package solutions.bellatrix.data.configuration; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.Data; | ||
| import solutions.bellatrix.data.http.configuration.HttpSettings; | ||
|
|
||
| @Data | ||
| public class DataSettings { | ||
| @SerializedName("dataSourceType") | ||
| private String datasourceType; | ||
| @SerializedName("httpSettings") | ||
| private HttpSettings httpSettings; | ||
| } |
29 changes: 29 additions & 0 deletions
29
bellatrix.data/src/main/java/solutions/bellatrix/data/configuration/RepositoryFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package solutions.bellatrix.data.configuration; | ||
|
|
||
| import solutions.bellatrix.core.utilities.SingletonFactory; | ||
| import solutions.bellatrix.data.contracts.Repository; | ||
| import solutions.bellatrix.data.http.infrastructure.Entity; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| public enum RepositoryFactory { | ||
| INSTANCE; | ||
|
|
||
| private final Map<Class<? extends Entity>, Class<? extends Repository>> repositories = new ConcurrentHashMap<>(); | ||
|
|
||
| public <T extends Entity> void registerRepository(Class<T> entityClass, Class<? extends Repository<T>> repositoryClass) { | ||
| repositories.put(entityClass, repositoryClass); | ||
| } | ||
|
|
||
| public <T extends Entity> Repository<T> getRepository(Class<T> entityClass) { | ||
| var repositoryClassType = repositories.get(entityClass); | ||
|
|
||
| if (Objects.isNull(repositoryClassType)) { | ||
| throw new IllegalArgumentException("No repository registered for entity class: " + entityClass.getName()); | ||
| } | ||
|
|
||
| return (Repository<T>)SingletonFactory.getInstance(repositoryClassType); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
bellatrix.data/src/main/java/solutions/bellatrix/data/contracts/Repository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package solutions.bellatrix.data.contracts; | ||
|
|
||
| import solutions.bellatrix.data.http.infrastructure.Entity; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface Repository<T extends Entity> { | ||
| T getById(T entity); | ||
|
|
||
| List<T> getAll(); | ||
|
|
||
| T create(T entity); | ||
|
|
||
| T update(T entity); | ||
|
|
||
| void delete(T entity); | ||
| } |
39 changes: 39 additions & 0 deletions
39
...ix.data/src/main/java/solutions/bellatrix/data/http/authentication/AuthSchemaFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package solutions.bellatrix.data.http.authentication; | ||
|
|
||
| import io.restassured.authentication.AuthenticationScheme; | ||
| import io.restassured.authentication.BasicAuthScheme; | ||
| import io.restassured.authentication.NoAuthScheme; | ||
| import io.restassured.authentication.PreemptiveOAuth2HeaderScheme; | ||
|
|
||
| public class AuthSchemaFactory { | ||
| public static AuthenticationScheme getAuthenticationScheme(Authentication authentication) { | ||
| var authType = authentication.getAuthenticationMethod(); | ||
| var option = authentication.getAuthenticationOptions().stream().filter(x -> x.get("type").equals(authType.getMethod())).findFirst(); | ||
| if (option.isEmpty()) { | ||
| throw new IllegalArgumentException("Authentication type not found: %s, Supported types : ".formatted(authType)); | ||
| } | ||
|
|
||
| switch (authType) { | ||
| case BASIC -> { | ||
| var basicAuth = option.get(); | ||
| String username = basicAuth.get("username").toString(); | ||
| String password = basicAuth.get("password").toString(); | ||
| var basicSchema = new BasicAuthScheme(); | ||
| basicSchema.setUserName(username); | ||
| basicSchema.setPassword(password); | ||
| return basicSchema; | ||
| } | ||
| case BEARER -> { | ||
| var bearerAuth = option.get(); | ||
| String token = bearerAuth.get("token").toString(); | ||
| var bearerSchema = new PreemptiveOAuth2HeaderScheme(); | ||
| bearerSchema.setAccessToken(token); | ||
| return bearerSchema; | ||
| } | ||
| case QUERY_PARAMETER -> { | ||
| return new NoAuthScheme(); | ||
| } | ||
| default -> throw new IllegalArgumentException("Unsupported authentication type: %s".formatted(authType)); | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...atrix.data/src/main/java/solutions/bellatrix/data/http/authentication/Authentication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package solutions.bellatrix.data.http.authentication; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedList; | ||
|
|
||
| public class Authentication { | ||
| @SerializedName("method") | ||
| private String method; | ||
| @SerializedName("options") | ||
| @Getter private LinkedList<LinkedHashMap<String, Object>> authenticationOptions; | ||
|
|
||
| @Setter(AccessLevel.PRIVATE) | ||
| private transient AuthenticationMethod authenticationMethod; | ||
|
|
||
| public AuthenticationMethod getAuthenticationMethod() { | ||
| setAuthenticationMethod(AuthenticationMethod.parse(method)); | ||
| return authenticationMethod; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
...data/src/main/java/solutions/bellatrix/data/http/authentication/AuthenticationMethod.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package solutions.bellatrix.data.http.authentication; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public enum AuthenticationMethod { | ||
| BEARER("Bearer"), | ||
| BASIC("Basic"), | ||
| QUERY_PARAMETER("QueryParameters"); | ||
|
|
||
| private final String method; | ||
|
|
||
| AuthenticationMethod(String method) { | ||
| this.method = method; | ||
| } | ||
|
|
||
| public static AuthenticationMethod parse(String y) { | ||
| for (var state : values()) { | ||
| String enumDisplayValue = state.getMethod(); | ||
| if (enumDisplayValue != null && enumDisplayValue.equalsIgnoreCase(y)) { | ||
| return state; | ||
| } | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("No enum constant with value: %s".formatted(y)); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
bellatrix.data/src/main/java/solutions/bellatrix/data/http/configuration/HttpSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package solutions.bellatrix.data.http.configuration; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import lombok.Data; | ||
| import solutions.bellatrix.core.configuration.ConfigurationService; | ||
| import solutions.bellatrix.data.configuration.DataSettings; | ||
| import solutions.bellatrix.data.http.authentication.Authentication; | ||
| import solutions.bellatrix.data.http.authentication.AuthenticationMethod; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
|
||
| @Data | ||
| public class HttpSettings { | ||
| @SerializedName("baseUrl") | ||
| private String baseUrl; | ||
| @SerializedName("basePath") | ||
| private String basePath; | ||
| @SerializedName("contentType") | ||
| private String contentType; | ||
| @SerializedName("authentication") | ||
| private Authentication authentication; | ||
| @SerializedName("urlEncoderEnabled") | ||
| private boolean urlEncoderEnabled; | ||
|
|
||
| public HttpSettings(HttpSettings httpSettings) { | ||
| setBaseUrl(httpSettings.getBaseUrl()); | ||
| setBasePath(httpSettings.getBasePath()); | ||
| setContentType(httpSettings.getContentType()); | ||
| setUrlEncoderEnabled(httpSettings.isUrlEncoderEnabled()); | ||
| setAuthentication(httpSettings.getAuthentication()); | ||
| } | ||
|
|
||
| public static HttpSettings custom(Consumer<HttpSettings> httpSettings) { | ||
| var settings = ConfigurationService.get(DataSettings.class).getHttpSettings(); | ||
| if (settings == null) { | ||
| throw new IllegalStateException("Include the httpSettings section in your config file"); | ||
|
|
||
| } | ||
| httpSettings.accept(settings); | ||
| return settings; | ||
| } | ||
|
|
||
| public AuthenticationMethod getAuthenticationMethod() { | ||
| return authentication.getAuthenticationMethod(); | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
bellatrix.data/src/main/java/solutions/bellatrix/data/http/contracts/ObjectConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package solutions.bellatrix.data.http.contracts; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ObjectConverter { | ||
| <T> String toString(T object); | ||
|
|
||
| <T> T fromString(String data, Class<T> type); | ||
|
|
||
| <T> List<T> fromStringToList(String json, Class<T> elementType); | ||
| } |
38 changes: 38 additions & 0 deletions
38
bellatrix.data/src/main/java/solutions/bellatrix/data/http/contracts/Queryable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package solutions.bellatrix.data.http.contracts; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import solutions.bellatrix.data.http.infrastructure.QueryParameter; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.Arrays; | ||
| import java.util.LinkedList; | ||
| import java.util.Objects; | ||
|
|
||
| public interface Queryable { | ||
| default LinkedList<QueryParameter> toQueryParams() { | ||
| try { | ||
| var queryParameters = new LinkedList<QueryParameter>(); | ||
| Class<?> clazz = this.getClass(); | ||
|
|
||
| while (clazz!=null) { | ||
| Field[] fields = clazz.getDeclaredFields(); | ||
| Arrays.stream(fields).forEach(x -> x.setAccessible(true)); | ||
| for (Field field : fields) { | ||
| if (field.isAnnotationPresent(SerializedName.class)) { | ||
| var queryParameterName = field.getAnnotation(SerializedName.class).value(); | ||
| var value = field.get(this); | ||
| if (Objects.nonNull(value)) { | ||
| queryParameters.add(new QueryParameter(queryParameterName, value)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| clazz = clazz.getSuperclass(); | ||
| } | ||
|
|
||
| return queryParameters; | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle the case when such settings are not present in the config - maybe Log warning or throw specific exception, but this will happen in all existing projects, so its better not to break the execution if the module is not used