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.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 {
|
||||
private Set<QueryFilter> filters;
|
||||
|
||||
|
@ -3,9 +3,23 @@ package tech.ailef.dbadmin.external.dto;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Describes a request that contains parameters that are used
|
||||
* to filter results.
|
||||
*
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Empty filtering request
|
||||
* @return an empty map
|
||||
*/
|
||||
public static MultiValueMap<String, String> empty() {
|
||||
return new LinkedMultiValueMap<>();
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ import java.util.Objects;
|
||||
|
||||
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 {
|
||||
private DbField field;
|
||||
|
||||
@ -17,14 +21,26 @@ public class QueryFilter {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field of the boolean condition
|
||||
* @return
|
||||
*/
|
||||
public DbField getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the operator of the boolean condition
|
||||
* @return
|
||||
*/
|
||||
public CompareOperator getOp() {
|
||||
return op;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the boolean condition
|
||||
* @return
|
||||
*/
|
||||
public String getValue() {
|
||||
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
|
||||
* 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.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");
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user