mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
Documentation
This commit is contained in:
parent
fa51f11109
commit
a6da47775f
@ -6,6 +6,11 @@ import java.util.Set;
|
|||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The filter request for faceted search. It is implemented as a
|
||||||
|
* set of filters that can be stacked on top of each other.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class FacetedSearchRequest implements FilterRequest {
|
public class FacetedSearchRequest implements FilterRequest {
|
||||||
private Set<QueryFilter> filters;
|
private Set<QueryFilter> filters;
|
||||||
|
|
||||||
|
@ -3,9 +3,23 @@ package tech.ailef.dbadmin.external.dto;
|
|||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes a request that contains parameters that are used
|
||||||
|
* to filter results.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public interface FilterRequest {
|
public interface FilterRequest {
|
||||||
|
/**
|
||||||
|
* Converts the request to a MultiValue map that can be
|
||||||
|
* later converted into a query string
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public MultiValueMap<String, String> computeParams();
|
public MultiValueMap<String, String> computeParams();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty filtering request
|
||||||
|
* @return an empty map
|
||||||
|
*/
|
||||||
public static MultiValueMap<String, String> empty() {
|
public static MultiValueMap<String, String> empty() {
|
||||||
return new LinkedMultiValueMap<>();
|
return new LinkedMultiValueMap<>();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import tech.ailef.dbadmin.external.dbmapping.DbField;
|
import tech.ailef.dbadmin.external.dbmapping.DbField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single filter in a FacetedSearchRequest. This describes a
|
||||||
|
* single boolean condition on the value of a specific field.
|
||||||
|
*/
|
||||||
public class QueryFilter {
|
public class QueryFilter {
|
||||||
private DbField field;
|
private DbField field;
|
||||||
|
|
||||||
@ -17,14 +21,26 @@ public class QueryFilter {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the field of the boolean condition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public DbField getField() {
|
public DbField getField() {
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the operator of the boolean condition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public CompareOperator getOp() {
|
public CompareOperator getOp() {
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the boolean condition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -53,30 +53,6 @@ public interface Utils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a set of query filters applied with the faceted search feature
|
|
||||||
* to a multi value map
|
|
||||||
* @param filters
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
// public static MultiValueMap<String, String> computeParams(Set<QueryFilter> filters) {
|
|
||||||
// MultiValueMap<String, String> r = new LinkedMultiValueMap<>();
|
|
||||||
// if (filters == null)
|
|
||||||
// return r;
|
|
||||||
//
|
|
||||||
// r.put("filter_field", new ArrayList<>());
|
|
||||||
// r.put("filter_op", new ArrayList<>());
|
|
||||||
// r.put("filter_value", new ArrayList<>());
|
|
||||||
//
|
|
||||||
// for (QueryFilter filter : filters) {
|
|
||||||
// r.get("filter_field").add(filter.getField().getJavaName());
|
|
||||||
// r.get("filter_op").add(filter.getOp().toString());
|
|
||||||
// r.get("filter_value").add(filter.getValue());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return r;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a multi value map of parameters containing query filters applied
|
* Converts a multi value map of parameters containing query filters applied
|
||||||
* with the faceted search feature into a set of QueryFilter objects
|
* with the faceted search feature into a set of QueryFilter objects
|
||||||
|
@ -10,18 +10,31 @@ import org.springframework.stereotype.Component;
|
|||||||
import tech.ailef.dbadmin.internal.model.UserSetting;
|
import tech.ailef.dbadmin.internal.model.UserSetting;
|
||||||
import tech.ailef.dbadmin.internal.repository.UserSettingsRepository;
|
import tech.ailef.dbadmin.internal.repository.UserSettingsRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper class for the UserSettingsRepository that provides a better
|
||||||
|
* way of handling user settings.
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class UserConfiguration {
|
public class UserConfiguration {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserSettingsRepository repo;
|
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) {
|
public String get(String settingName) {
|
||||||
Optional<UserSetting> setting = repo.findById(settingName);
|
Optional<UserSetting> setting = repo.findById(settingName);
|
||||||
if (setting.isPresent())
|
if (setting.isPresent())
|
||||||
return setting.get().getSettingValue();
|
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() {
|
private Map<String, String> defaultValues() {
|
||||||
Map<String, String> values = new HashMap<>();
|
Map<String, String> values = new HashMap<>();
|
||||||
values.put("brandName", "Spring Boot Database Admin");
|
values.put("brandName", "Spring Boot Database Admin");
|
||||||
|
@ -11,6 +11,10 @@ import jakarta.persistence.GenerationType;
|
|||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Lob;
|
import jakarta.persistence.Lob;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An action executed by any user from the web UI.
|
||||||
|
*
|
||||||
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class UserAction {
|
public class UserAction {
|
||||||
@Id
|
@Id
|
||||||
|
@ -3,11 +3,20 @@ package tech.ailef.dbadmin.internal.model;
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single variable in the settings.
|
||||||
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class UserSetting {
|
public class UserSetting {
|
||||||
|
/**
|
||||||
|
* The id of the variable (its name)
|
||||||
|
*/
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of the variable
|
||||||
|
*/
|
||||||
private String settingValue;
|
private String settingValue;
|
||||||
|
|
||||||
public UserSetting() {
|
public UserSetting() {
|
||||||
|
@ -15,12 +15,22 @@ import jakarta.persistence.criteria.Root;
|
|||||||
import tech.ailef.dbadmin.external.dto.LogsSearchRequest;
|
import tech.ailef.dbadmin.external.dto.LogsSearchRequest;
|
||||||
import tech.ailef.dbadmin.internal.model.UserAction;
|
import tech.ailef.dbadmin.internal.model.UserAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A repository that provides custom queries for UserActions
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class CustomActionRepositoryImpl implements CustomActionRepository {
|
public class CustomActionRepositoryImpl implements CustomActionRepository {
|
||||||
|
|
||||||
@PersistenceContext(unitName = "internal")
|
@PersistenceContext(unitName = "internal")
|
||||||
private EntityManager entityManager;
|
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
|
@Override
|
||||||
public List<UserAction> findActions(LogsSearchRequest request) {
|
public List<UserAction> findActions(LogsSearchRequest request) {
|
||||||
String table = request.getTable();
|
String table = request.getTable();
|
||||||
@ -61,6 +71,10 @@ public class CustomActionRepositoryImpl implements CustomActionRepository {
|
|||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the count that match the filtering parameters, used for pagination.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long countActions(String table, String actionType, String itemId) {
|
public long countActions(String table, String actionType, String itemId) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user