Documentation

This commit is contained in:
Francesco
2023-09-30 12:14:08 +02:00
parent fa51f11109
commit a6da47775f
8 changed files with 77 additions and 26 deletions

View File

@@ -10,18 +10,31 @@ import org.springframework.stereotype.Component;
import tech.ailef.dbadmin.internal.model.UserSetting;
import tech.ailef.dbadmin.internal.repository.UserSettingsRepository;
/**
* Wrapper class for the UserSettingsRepository that provides a better
* way of handling user settings.
*/
@Component
public class UserConfiguration {
@Autowired
private UserSettingsRepository repo;
/**
* Returns the value of the specific setting
* @param settingName the name of the setting
* @return the value, if found, otherwise the default value if present, otherwise an empty string
*/
public String get(String settingName) {
Optional<UserSetting> setting = repo.findById(settingName);
if (setting.isPresent())
return setting.get().getSettingValue();
return defaultValues().get(settingName);
return defaultValues().getOrDefault(settingName, "");
}
/**
* Returns a map filled with the default values of the settings.
* @return
*/
private Map<String, String> defaultValues() {
Map<String, String> values = new HashMap<>();
values.put("brandName", "Spring Boot Database Admin");

View File

@@ -11,6 +11,10 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
/**
* An action executed by any user from the web UI.
*
*/
@Entity
public class UserAction {
@Id

View File

@@ -3,11 +3,20 @@ package tech.ailef.dbadmin.internal.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
/**
* A single variable in the settings.
*/
@Entity
public class UserSetting {
/**
* The id of the variable (its name)
*/
@Id
private String id;
/**
* The value of the variable
*/
private String settingValue;
public UserSetting() {

View File

@@ -15,12 +15,22 @@ import jakarta.persistence.criteria.Root;
import tech.ailef.dbadmin.external.dto.LogsSearchRequest;
import tech.ailef.dbadmin.internal.model.UserAction;
/**
* A repository that provides custom queries for UserActions
*/
@Component
public class CustomActionRepositoryImpl implements CustomActionRepository {
@PersistenceContext(unitName = "internal")
private EntityManager entityManager;
/**
* Finds the UserAction that match the input search request.
* Implemented as a custom CriteriaQuery in order to put all the filter
* in an AND condition but ignore null value. The default JpaRepository
* behaviour is to test for equality to NULL when an AND condition is used,
* instead of ignoring the fields.
*/
@Override
public List<UserAction> findActions(LogsSearchRequest request) {
String table = request.getTable();
@@ -61,6 +71,10 @@ public class CustomActionRepositoryImpl implements CustomActionRepository {
.getResultList();
}
/**
* Returns the count that match the filtering parameters, used for pagination.
* @return
*/
@Override
public long countActions(String table, String actionType, String itemId) {