Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package solutions.bellatrix.core.configuration;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
Expand Down Expand Up @@ -57,7 +58,11 @@ public static <T> T get(Class<T> configSection) {
String jsonFileContent = getFileAsString(fileName);
String sectionName = getSectionName(configSection);

var jsonObject = JsonParser.parseString(jsonFileContent).getAsJsonObject().get(sectionName).toString();
JsonElement sectionFound = JsonParser.parseString(jsonFileContent).getAsJsonObject().get(sectionName);
if (sectionFound == null) {
return mappedObject;
}
var jsonObject = sectionFound.toString();

var gson = new Gson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Optional: Custom factory method name to use for creating the dependency.
* If not specified, the default factory method will be used.
*/
String factoryMethod() default "createDefault";
String factoryMethod() default "buildDefault";

/**
* Optional: Whether to create the dependency even if the field is not null.
Expand Down
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.http.contracts.EntityFactory;
import solutions.bellatrix.data.http.infrastructure.Entity;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public enum FactoryProvider {
INSTANCE;

private final Map<Class<? extends Entity>, Class<? extends EntityFactory>> factories = new ConcurrentHashMap<>();

public <T extends Entity> void register(Class<T> entityClass, Class<? extends EntityFactory<T>> factoryClass) {
factories.put(entityClass, factoryClass);
}

public <T extends Entity> EntityFactory<T> get(Class<T> entityClass) {
var factoryClassType = factories.get(entityClass);

if (Objects.isNull(factoryClassType)) {
throw new IllegalArgumentException("No factory registered for entity class: " + entityClass.getName());
}

return (EntityFactory<T>)SingletonFactory.getInstance(factoryClassType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public enum RepositoryFactory {
public enum RepositoryProvider {
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) {
public <T extends Entity> void register(Class<T> entityClass, Class<? extends Repository<T>> repositoryClass) {
repositories.put(entityClass, repositoryClass);
}

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

if (Objects.isNull(repositoryClassType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public interface EntityFactory<T extends Entity> {

T buildDefault();

default T createWithDependencies() {
default T buildDefaultWithDependencies() {
T entity = buildDefault();
return DependencyResolver.resolveDependencies(entity);
return DependencyResolver.buildDependencies(entity);
}
}
Loading