Skip to content

Commit f9511a2

Browse files
committed
Merge branch 'main' into feature/service-now-uib-setup
2 parents fbd92b8 + 01697fb commit f9511a2

File tree

20 files changed

+1083
-52
lines changed

20 files changed

+1083
-52
lines changed

bellatrix.core/src/main/java/solutions/bellatrix/core/configuration/ConfigurationService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package solutions.bellatrix.core.configuration;
1515

1616
import com.google.gson.Gson;
17+
import com.google.gson.JsonElement;
1718
import com.google.gson.JsonParser;
1819
import lombok.SneakyThrows;
1920
import lombok.experimental.UtilityClass;
@@ -57,7 +58,11 @@ public static <T> T get(Class<T> configSection) {
5758
String jsonFileContent = getFileAsString(fileName);
5859
String sectionName = getSectionName(configSection);
5960

60-
var jsonObject = JsonParser.parseString(jsonFileContent).getAsJsonObject().get(sectionName).toString();
61+
JsonElement sectionFound = JsonParser.parseString(jsonFileContent).getAsJsonObject().get(sectionName);
62+
if (sectionFound == null) {
63+
return mappedObject;
64+
}
65+
var jsonObject = sectionFound.toString();
6166

6267
var gson = new Gson();
6368

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package solutions.bellatrix.data.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Annotation to mark fields that require automatic dependency creation.
10+
* When a field is marked with this annotation and its value is null,
11+
* the system will automatically create the dependent entity using
12+
* the registered factory and repository.
13+
*/
14+
@Target(ElementType.FIELD)
15+
@Retention(RetentionPolicy.RUNTIME)
16+
public @interface Dependency {
17+
18+
/**
19+
* The entity class that should be created as a dependency.
20+
* This class must have a registered factory and repository.
21+
*/
22+
Class<?> entityType();
23+
24+
/**
25+
* Optional: Custom factory method name to use for creating the dependency.
26+
* If not specified, the default factory method will be used.
27+
*/
28+
String factoryMethod() default "buildDefault";
29+
30+
/**
31+
* Optional: Whether to create the dependency even if the field is not null.
32+
* Default is false (only create if field is null).
33+
*/
34+
boolean forceCreate() default false;
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package solutions.bellatrix.data.configuration;
2+
3+
import solutions.bellatrix.core.utilities.SingletonFactory;
4+
import solutions.bellatrix.data.http.contracts.EntityFactory;
5+
import solutions.bellatrix.data.http.infrastructure.Entity;
6+
7+
import java.util.Map;
8+
import java.util.Objects;
9+
import java.util.concurrent.ConcurrentHashMap;
10+
11+
public enum FactoryProvider {
12+
INSTANCE;
13+
14+
private final Map<Class<? extends Entity>, Class<? extends EntityFactory>> factories = new ConcurrentHashMap<>();
15+
16+
public <T extends Entity> void register(Class<T> entityClass, Class<? extends EntityFactory<T>> factoryClass) {
17+
factories.put(entityClass, factoryClass);
18+
}
19+
20+
public <T extends Entity> EntityFactory<T> get(Class<T> entityClass) {
21+
var factoryClassType = factories.get(entityClass);
22+
23+
if (Objects.isNull(factoryClassType)) {
24+
throw new IllegalArgumentException("No factory registered for entity class: " + entityClass.getName());
25+
}
26+
27+
return (EntityFactory<T>)SingletonFactory.getInstance(factoryClassType);
28+
}
29+
}

bellatrix.data/src/main/java/solutions/bellatrix/data/configuration/RepositoryFactory.java renamed to bellatrix.data/src/main/java/solutions/bellatrix/data/configuration/RepositoryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
import java.util.Objects;
99
import java.util.concurrent.ConcurrentHashMap;
1010

11-
public enum RepositoryFactory {
11+
public enum RepositoryProvider {
1212
INSTANCE;
1313

1414
private final Map<Class<? extends Entity>, Class<? extends Repository>> repositories = new ConcurrentHashMap<>();
1515

16-
public <T extends Entity> void registerRepository(Class<T> entityClass, Class<? extends Repository<T>> repositoryClass) {
16+
public <T extends Entity> void register(Class<T> entityClass, Class<? extends Repository<T>> repositoryClass) {
1717
repositories.put(entityClass, repositoryClass);
1818
}
1919

20-
public <T extends Entity> Repository<T> getRepository(Class<T> entityClass) {
20+
public <T extends Entity> Repository<T> get(Class<T> entityClass) {
2121
var repositoryClassType = repositories.get(entityClass);
2222

2323
if (Objects.isNull(repositoryClassType)) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package solutions.bellatrix.data.http.contracts;
2+
3+
import solutions.bellatrix.data.http.infrastructure.DependencyResolver;
4+
import solutions.bellatrix.data.http.infrastructure.Entity;
5+
6+
public interface EntityFactory<T extends Entity> {
7+
8+
T buildDefault();
9+
10+
default T buildDefaultWithDependencies() {
11+
T entity = buildDefault();
12+
return DependencyResolver.buildDependencies(entity);
13+
}
14+
}

bellatrix.data/src/main/java/solutions/bellatrix/data/http/httpContext/HttpContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import solutions.bellatrix.data.http.infrastructure.HTTPMethod;
1212
import solutions.bellatrix.data.http.infrastructure.HttpHeader;
1313
import solutions.bellatrix.data.http.infrastructure.QueryParameter;
14+
import solutions.bellatrix.core.utilities.SecretsResolver;
1415

1516
import java.util.*;
1617
import java.util.function.Consumer;
@@ -77,9 +78,8 @@ public RequestSpecification requestSpecification() {
7778
specBuilder.setBody(requestBody);
7879
}
7980

80-
if (!queryParameters.isEmpty()) {
81-
specBuilder.addQueryParams(getRequestQueryParameters());
82-
}
81+
// Always add query parameters (including authentication parameters)
82+
specBuilder.addQueryParams(getRequestQueryParameters());
8383

8484
specBuilder.addHeaders(getRequestHeaders());
8585

@@ -136,7 +136,8 @@ private Map<String, String> getRequestQueryParameters() {
136136
if (insertionOrder.equals("start")) {
137137
for (var key : option.keySet()) {
138138
if (!key.equals("type") && !key.equals("insertionOrder")) {
139-
queryParams.put(key, option.get(key).toString());
139+
String value = SecretsResolver.getSecret(option.get(key).toString());
140+
queryParams.put(key, value);
140141
}
141142
}
142143
for (QueryParameter queryParameter : queryParameters) {
@@ -148,7 +149,8 @@ private Map<String, String> getRequestQueryParameters() {
148149
}
149150
for (var key : option.keySet()) {
150151
if (!key.equals("type") && !key.equals("insertionOrder")) {
151-
queryParams.put(key, option.get(key).toString());
152+
String value = SecretsResolver.getSecret(option.get(key).toString());
153+
queryParams.put(key, value);
152154
}
153155
}
154156

0 commit comments

Comments
 (0)