Skip to content

Commit b31b87d

Browse files
author
NikolayAvramov
committed
fix build issues and add dependency resolving in data module
1 parent 4d015f4 commit b31b87d

File tree

17 files changed

+328
-80
lines changed

17 files changed

+328
-80
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

bellatrix.data/src/main/java/solutions/bellatrix/data/annotations/Dependency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Optional: Custom factory method name to use for creating the dependency.
2626
* If not specified, the default factory method will be used.
2727
*/
28-
String factoryMethod() default "createDefault";
28+
String factoryMethod() default "buildDefault";
2929

3030
/**
3131
* Optional: Whether to create the dependency even if the field is not null.
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)) {

bellatrix.data/src/main/java/solutions/bellatrix/data/http/contracts/EntityFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public interface EntityFactory<T extends Entity> {
77

88
T buildDefault();
99

10-
default T createWithDependencies() {
10+
default T buildDefaultWithDependencies() {
1111
T entity = buildDefault();
12-
return DependencyResolver.resolveDependencies(entity);
12+
return DependencyResolver.buildDependencies(entity);
1313
}
1414
}

0 commit comments

Comments
 (0)