Refactor DbAdmin names to SnapAdmin

This commit is contained in:
Francesco 2023-11-07 15:19:29 +01:00
parent 6eb572f72c
commit 83541b49da
32 changed files with 124 additions and 124 deletions

View File

@ -59,13 +59,13 @@ import tech.ailef.snapadmin.external.dbmapping.fields.EnumFieldType;
import tech.ailef.snapadmin.external.dbmapping.fields.StringFieldType;
import tech.ailef.snapadmin.external.dbmapping.fields.TextFieldType;
import tech.ailef.snapadmin.external.dto.MappingError;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.DbAdminNotFoundException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminNotFoundException;
import tech.ailef.snapadmin.external.exceptions.UnsupportedFieldTypeException;
import tech.ailef.snapadmin.external.misc.Utils;
/**
* The main DbAdmin class responsible for the initialization phase. This class scans
* The main SnapAdmin class is responsible for the initialization phase. This class scans
* the user provided package containing the {@code Entity} definitions and tries to map each
* entity to a {@link DbObjectSchema} instance.
*
@ -90,7 +90,7 @@ public class SnapAdmin {
private static final String VERSION = "0.1.9";
/**
* Builds the DbAdmin instance by scanning the `@Entity` beans and loading
* Builds the SnapAdmin instance by scanning the `@Entity` beans and loading
* the schemas.
* @param entityManager the entity manager
* @param properties the configuration properties
@ -152,11 +152,11 @@ public class SnapAdmin {
* Finds a schema by its full class name
* @param className qualified class name
* @return the schema with this class name
* @throws DbAdminException if corresponding schema not found
* @throws SnapAdminException if corresponding schema not found
*/
public DbObjectSchema findSchemaByClassName(String className) {
return schemas.stream().filter(s -> s.getClassName().equals(className)).findFirst().orElseThrow(() -> {
return new DbAdminNotFoundException("Schema " + className + " not found.");
return new SnapAdminNotFoundException("Schema " + className + " not found.");
});
}
@ -164,11 +164,11 @@ public class SnapAdmin {
* Finds a schema by its table name
* @param tableName the table name on the database
* @return the schema with this table name
* @throws DbAdminException if corresponding schema not found
* @throws SnapAdminException if corresponding schema not found
*/
public DbObjectSchema findSchemaByTableName(String tableName) {
return schemas.stream().filter(s -> s.getTableName().equals(tableName)).findFirst().orElseThrow(() -> {
return new DbAdminException("Schema " + tableName + " not found.");
return new SnapAdminException("Schema " + tableName + " not found.");
});
}
@ -176,7 +176,7 @@ public class SnapAdmin {
* Finds a schema by its class object
* @param klass the `@Entity` class you want to find the schema for
* @return the schema for the `@Entity` class
* @throws DbAdminException if corresponding schema not found
* @throws SnapAdminException if corresponding schema not found
*/
public DbObjectSchema findSchemaByClass(Class<?> klass) {
return findSchemaByClassName(klass.getName());
@ -310,7 +310,7 @@ public class SnapAdmin {
// If failure, we try to map a relationship on this field later
}
}
} catch (DbAdminException e) {
} catch (SnapAdminException e) {
// If failure, we try to map a relationship on this field later
}
@ -392,12 +392,12 @@ public class SnapAdmin {
}
if (linkType == null)
throw new DbAdminException("Unable to find @Id field in Entity class " + entityClass);
throw new SnapAdminException("Unable to find @Id field in Entity class " + entityClass);
return DbFieldType.fromClass(linkType).getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}

View File

@ -38,7 +38,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.TransactionTemplate;
import tech.ailef.snapadmin.internal.InternalDbAdminConfiguration;
import tech.ailef.snapadmin.internal.InternalSnapAdminConfiguration;
/**
* The configuration class for "internal" data source. This is not the
@ -55,7 +55,7 @@ import tech.ailef.snapadmin.internal.InternalDbAdminConfiguration;
basePackages = { "tech.ailef.snapadmin.internal.repository" }
)
@EnableTransactionManagement
@Import(InternalDbAdminConfiguration.class)
@Import(InternalSnapAdminConfiguration.class)
public class SnapAdminAutoConfiguration {
@Autowired
private SnapAdminProperties props;

View File

@ -30,7 +30,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
/**
* Runs at startup to determine if SnapAdmin is protected with authentication.
@ -70,7 +70,7 @@ public class StartupAuthCheckRunner {
}
} catch (IOException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
};

View File

@ -64,8 +64,8 @@ import tech.ailef.snapadmin.external.dbmapping.query.DbQueryResult;
import tech.ailef.snapadmin.external.dbmapping.query.DbQueryResultRow;
import tech.ailef.snapadmin.external.dto.DataExportFormat;
import tech.ailef.snapadmin.external.dto.QueryFilter;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.DbAdminNotFoundException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminNotFoundException;
import tech.ailef.snapadmin.external.misc.Utils;
import tech.ailef.snapadmin.internal.model.ConsoleQuery;
import tech.ailef.snapadmin.internal.repository.ConsoleQueryRepository;
@ -90,13 +90,13 @@ public class DataExportController {
@GetMapping("/console/export/{queryId}")
public ResponseEntity<byte[]> export(@PathVariable String queryId, @RequestParam String format,
@RequestParam MultiValueMap<String, String> otherParams) {
ConsoleQuery query = queryRepository.findById(queryId).orElseThrow(() -> new DbAdminNotFoundException("Query not found: " + queryId));
ConsoleQuery query = queryRepository.findById(queryId).orElseThrow(() -> new SnapAdminNotFoundException("Query not found: " + queryId));
DataExportFormat exportFormat = null;
try {
exportFormat = DataExportFormat.valueOf(format.toUpperCase());
} catch (IllegalArgumentException e) {
throw new DbAdminException("Unsupported export format: " + format);
throw new SnapAdminException("Unsupported export format: " + format);
}
List<String> fieldsToInclude = otherParams.getOrDefault("fields[]", new ArrayList<>());
@ -120,7 +120,7 @@ public class DataExportController {
"attachment; filename=\"export_" + query.getTitle().replaceAll("[^a-zA-Z0-9.-]", "_") + ".jsonl\"")
.body(toJsonlQuery(results, fieldsToInclude).getBytes());
default:
throw new DbAdminException("Invalid DataExportFormat");
throw new SnapAdminException("Invalid DataExportFormat");
}
}
@ -134,7 +134,7 @@ public class DataExportController {
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
if (!schema.isExportEnabled()) {
throw new DbAdminException("Export is not enabled for this table: " + schema.getTableName());
throw new SnapAdminException("Export is not enabled for this table: " + schema.getTableName());
}
List<String> fieldsToInclude = otherParams.getOrDefault("fields[]", new ArrayList<>());
@ -143,7 +143,7 @@ public class DataExportController {
try {
exportFormat = DataExportFormat.valueOf(format.toUpperCase());
} catch (IllegalArgumentException e) {
throw new DbAdminException("Unsupported export format: " + format);
throw new SnapAdminException("Unsupported export format: " + format);
}
Set<QueryFilter> queryFilters = Utils.computeFilters(schema, otherParams);
@ -168,7 +168,7 @@ public class DataExportController {
.body(toJsonl(results, fieldsToInclude, raw).getBytes());
default:
throw new DbAdminException("Invalid DataExportFormat");
throw new SnapAdminException("Invalid DataExportFormat");
}
}
@ -209,7 +209,7 @@ public class DataExportController {
fos.close();
workbook.close();
} catch (IOException e) {
throw new DbAdminException("Error during serialization for XLSX workbook", e);
throw new SnapAdminException("Error during serialization for XLSX workbook", e);
}
@ -252,7 +252,7 @@ public class DataExportController {
fos.close();
workbook.close();
} catch (IOException e) {
throw new DbAdminException("Error during serialization for XLSX workbook", e);
throw new SnapAdminException("Error during serialization for XLSX workbook", e);
}
@ -279,7 +279,7 @@ public class DataExportController {
String json = mapper.writeValueAsString(map);
sb.append(json);
} catch (JsonProcessingException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
sb.append("\n");
@ -300,7 +300,7 @@ public class DataExportController {
String json = mapper.writeValueAsString(map);
sb.append(json);
} catch (JsonProcessingException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
sb.append("\n");
@ -328,7 +328,7 @@ public class DataExportController {
return sw.toString();
} catch (IOException e) {
throw new DbAdminException("Error during creation of CSV file", e);
throw new SnapAdminException("Error during creation of CSV file", e);
}
}
@ -350,7 +350,7 @@ public class DataExportController {
return sw.toString();
} catch (IOException e) {
throw new DbAdminException("Error during creation of CSV file", e);
throw new SnapAdminException("Error during creation of CSV file", e);
}
}

View File

@ -41,7 +41,7 @@ import tech.ailef.snapadmin.external.dbmapping.SnapAdminRepository;
import tech.ailef.snapadmin.external.dbmapping.DbFieldValue;
import tech.ailef.snapadmin.external.dbmapping.DbObject;
import tech.ailef.snapadmin.external.dbmapping.DbObjectSchema;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
/**
* Controller to serve file or images (`@DisplayImage`)
@ -109,7 +109,7 @@ public class FileDownloadController {
DbFieldValue dbFieldValue;
try {
dbFieldValue = dbObject.get(fieldName);
} catch (DbAdminException e) {
} catch (SnapAdminException e) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Field not found", e);
}

View File

@ -31,8 +31,8 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import tech.ailef.snapadmin.external.SnapAdmin;
import tech.ailef.snapadmin.external.SnapAdminProperties;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.DbAdminNotFoundException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminNotFoundException;
import tech.ailef.snapadmin.internal.UserConfiguration;
/**
@ -51,7 +51,7 @@ public class GlobalController {
@Autowired
private SnapAdmin dbAdmin;
@ExceptionHandler(DbAdminException.class)
@ExceptionHandler(SnapAdminException.class)
public String handleException(Exception e, Model model, HttpServletResponse response) {
model.addAttribute("status", "");
model.addAttribute("error", "Error");
@ -63,7 +63,7 @@ public class GlobalController {
return "other/error";
}
@ExceptionHandler(DbAdminNotFoundException.class)
@ExceptionHandler(SnapAdminNotFoundException.class)
public String handleNotFound(Exception e, Model model, HttpServletResponse response) {
model.addAttribute("status", "404");
model.addAttribute("error", "Error");

View File

@ -68,8 +68,8 @@ import tech.ailef.snapadmin.external.dto.PaginatedResult;
import tech.ailef.snapadmin.external.dto.PaginationInfo;
import tech.ailef.snapadmin.external.dto.QueryFilter;
import tech.ailef.snapadmin.external.dto.ValidationErrorsContainer;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.DbAdminNotFoundException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminNotFoundException;
import tech.ailef.snapadmin.external.exceptions.InvalidPageException;
import tech.ailef.snapadmin.external.misc.Utils;
import tech.ailef.snapadmin.internal.model.ConsoleQuery;
@ -81,12 +81,12 @@ import tech.ailef.snapadmin.internal.service.UserActionService;
import tech.ailef.snapadmin.internal.service.UserSettingsService;
/**
* The main DbAdmin controller that register most of the routes of the web interface.
* The main SnapAdmin controller that register most of the routes of the web interface.
*/
@Controller
@RequestMapping(value= {"/${snapadmin.baseUrl}", "/${snapadmin.baseUrl}/"})
public class DefaultSnapAdminController {
private static final Logger logger = LoggerFactory.getLogger(DefaultSnapAdminController.class);
public class SnapAdminController {
private static final Logger logger = LoggerFactory.getLogger(SnapAdminController.class);
@Autowired
private SnapAdminProperties properties;
@ -229,7 +229,7 @@ public class DefaultSnapAdminController {
} catch (InvalidPageException e) {
return "redirect:/" + properties.getBaseUrl() + "/model/" + className;
} catch (DbAdminException e) {
} catch (SnapAdminException e) {
model.addAttribute("error", e.getMessage());
model.addAttribute("errorTitle", "Invalid request");
model.addAttribute("schema", schema);
@ -272,7 +272,7 @@ public class DefaultSnapAdminController {
Object pkValue = schema.getPrimaryKey().getType().parseValue(id);
DbObject object = repository.findById(schema, pkValue).orElseThrow(() -> {
return new DbAdminNotFoundException(
return new SnapAdminNotFoundException(
schema.getJavaClass().getSimpleName() + " with ID " + id + " not found."
);
});
@ -318,7 +318,7 @@ public class DefaultSnapAdminController {
}
DbObject object = repository.findById(schema, pkValue).orElseThrow(() -> {
return new DbAdminNotFoundException(
return new SnapAdminNotFoundException(
"Object " + className + " with id " + id + " not found"
);
});
@ -500,7 +500,7 @@ public class DefaultSnapAdminController {
attr.addFlashAttribute("error", "See below for details");
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
attr.addFlashAttribute("params", params);
} catch (DbAdminException e) {
} catch (SnapAdminException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
logger.error(Arrays.toString(cause.getStackTrace()));
attr.addFlashAttribute("errorTitle", "Error");
@ -557,7 +557,7 @@ public class DefaultSnapAdminController {
@GetMapping("/console/new")
public String consoleNew(Model model) {
if (!properties.isSqlConsoleEnabled()) {
throw new DbAdminException("SQL console not enabled");
throw new SnapAdminException("SQL console not enabled");
}
ConsoleQuery q = new ConsoleQuery();
@ -568,7 +568,7 @@ public class DefaultSnapAdminController {
@GetMapping("/console")
public String console() {
if (!properties.isSqlConsoleEnabled()) {
throw new DbAdminException("SQL console not enabled");
throw new SnapAdminException("SQL console not enabled");
}
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
@ -585,7 +585,7 @@ public class DefaultSnapAdminController {
@PostMapping("/console/delete/{queryId}")
public String consoleDelete(@PathVariable String queryId, Model model) {
if (!properties.isSqlConsoleEnabled()) {
throw new DbAdminException("SQL console not enabled");
throw new SnapAdminException("SQL console not enabled");
}
consoleQueryRepository.deleteById(queryId);
@ -604,11 +604,11 @@ public class DefaultSnapAdminController {
long startTime = System.currentTimeMillis();
if (!properties.isSqlConsoleEnabled()) {
throw new DbAdminException("SQL console not enabled");
throw new SnapAdminException("SQL console not enabled");
}
ConsoleQuery activeQuery = consoleQueryRepository.findById(queryId).orElseThrow(() -> {
return new DbAdminNotFoundException("Query with ID " + queryId + " not found.");
return new SnapAdminNotFoundException("Query with ID " + queryId + " not found.");
});
if (query != null && !query.isBlank()) {

View File

@ -45,7 +45,7 @@ import tech.ailef.snapadmin.external.dbmapping.fields.StringFieldType;
import tech.ailef.snapadmin.external.dbmapping.fields.TextFieldType;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.dto.QueryFilter;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
@SuppressWarnings("rawtypes")
public class CustomJpaRepository extends SimpleJpaRepository {
@ -140,7 +140,7 @@ public class CustomJpaRepository extends SimpleJpaRepository {
else value = file.getBytes();
}
} catch (IOException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}
@ -194,7 +194,7 @@ public class CustomJpaRepository extends SimpleJpaRepository {
try {
value = dbField.getType().parseValue(v);
} catch (Exception e) {
throw new DbAdminException("Invalid value `" + v + "` specified for field `" + dbField.getName() + "`");
throw new SnapAdminException("Invalid value `" + v + "` specified for field `" + dbField.getName() + "`");
}
}

View File

@ -35,7 +35,7 @@ import jakarta.persistence.OneToOne;
import tech.ailef.snapadmin.external.annotations.DisplayName;
import tech.ailef.snapadmin.external.dbmapping.fields.BooleanFieldType;
import tech.ailef.snapadmin.external.dbmapping.fields.DbField;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
/**
* Wrapper for all objects retrieved from the database.
@ -54,7 +54,7 @@ public class DbObject {
public DbObject(Object instance, DbObjectSchema schema) {
if (instance == null)
throw new DbAdminException("Trying to build object with instance == null");
throw new SnapAdminException("Trying to build object with instance == null");
this.instance = instance;
this.schema = schema;
@ -94,7 +94,7 @@ public class DbObject {
DbObject linkedDbObject = new DbObject(linkedObject, field.getConnectedSchema());
return linkedDbObject;
} else {
throw new DbAdminException("Cannot traverse field " + field.getName() + " in class " + schema.getClassName());
throw new SnapAdminException("Cannot traverse field " + field.getName() + " in class " + schema.getClassName());
}
}
@ -112,7 +112,7 @@ public class DbObject {
return linkedObjects.stream().map(o -> new DbObject(o, field.getConnectedSchema()))
.collect(Collectors.toList());
} else {
throw new DbAdminException("Cannot traverse field " + field.getName() + " in class " + schema.getClassName());
throw new SnapAdminException("Cannot traverse field " + field.getName() + " in class " + schema.getClassName());
}
}
@ -120,14 +120,14 @@ public class DbObject {
Method getter = findGetter(name);
if (getter == null)
throw new DbAdminException("Unable to find getter method for field `"
throw new SnapAdminException("Unable to find getter method for field `"
+ name + "` in class " + instance.getClass());
try {
Object result = getter.invoke(instance);
return new DbFieldValue(result, schema.getFieldByJavaName(name));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}
@ -136,14 +136,14 @@ public class DbObject {
Method getter = findGetter(primaryKeyField.getJavaName());
if (getter == null)
throw new DbAdminException("Unable to find getter method for field `"
throw new SnapAdminException("Unable to find getter method for field `"
+ primaryKeyField.getJavaName() + "` in class " + instance.getClass());
try {
Object result = getter.invoke(instance);
return result;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}
@ -161,7 +161,7 @@ public class DbObject {
if (displayName == null) return null;
else return displayName.toString();
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
} else {
return getPrimaryKeyValue().toString();
@ -180,12 +180,12 @@ public class DbObject {
Method method = schema.getComputedColumn(column);
if (method == null)
throw new DbAdminException("Unable to find mapped method for @ComputedColumn " + column);
throw new SnapAdminException("Unable to find mapped method for @ComputedColumn " + column);
try {
return method.invoke(instance);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new DbAdminException("Error while calling @ComputedColumn " + column
throw new SnapAdminException("Error while calling @ComputedColumn " + column
+ " on class " + schema.getClassName());
}
}
@ -197,14 +197,14 @@ public class DbObject {
Optional<?> obj = linkedSchema.getJpaRepository().findById(primaryKeyValue);
if (!obj.isPresent()) {
throw new DbAdminException("Invalid value " + primaryKeyValue + " for " + fieldName
throw new SnapAdminException("Invalid value " + primaryKeyValue + " for " + fieldName
+ ": item does not exist.");
}
Method setter = findSetter(field.getJavaName());
if (setter == null) {
throw new DbAdminException("Unable to find setter method for " + fieldName + " in " + schema.getClassName());
throw new SnapAdminException("Unable to find setter method for " + fieldName + " in " + schema.getClassName());
}
try {
@ -217,7 +217,7 @@ public class DbObject {
Method setter = findSetter(fieldName);
if (setter == null) {
throw new DbAdminException("Unable to find setter method for " + fieldName + " in " + schema.getClassName());
throw new SnapAdminException("Unable to find setter method for " + fieldName + " in " + schema.getClassName());
}
try {

View File

@ -48,7 +48,7 @@ import tech.ailef.snapadmin.external.annotations.DisableExport;
import tech.ailef.snapadmin.external.annotations.HiddenColumn;
import tech.ailef.snapadmin.external.dbmapping.fields.DbField;
import tech.ailef.snapadmin.external.dto.MappingError;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.misc.Utils;
/**
@ -75,7 +75,7 @@ public class DbObjectSchema {
*/
private CustomJpaRepository jpaRepository;
private SnapAdmin dbAdmin;
private SnapAdmin snapAdmin;
/**
* The corresponding `@Entity` class that this schema describes
@ -95,10 +95,10 @@ public class DbObjectSchema {
* Determines the table name from the `@Table` annotation and also
* which methods are `@ComputedColumn`s
* @param klass the `@Entity` class
* @param dbAdmin the DbAdmin instance
* @param snapAdmin the SnapAdmin instance
*/
public DbObjectSchema(Class<?> klass, SnapAdmin dbAdmin) {
this.dbAdmin = dbAdmin;
public DbObjectSchema(Class<?> klass, SnapAdmin snapAdmin) {
this.snapAdmin = snapAdmin;
this.entityClass = klass;
Table tableAnnotation = klass.getAnnotation(Table.class);
@ -116,7 +116,7 @@ public class DbObjectSchema {
.collect(Collectors.toList());
for (Method m : methods) {
if (m.getParameterCount() > 0)
throw new DbAdminException("@ComputedColumn can only be applied on no-args methods");
throw new SnapAdminException("@ComputedColumn can only be applied on no-args methods");
String name = m.getAnnotation(ComputedColumn.class).name();
if (name.isBlank())
@ -131,11 +131,11 @@ public class DbObjectSchema {
}
/**
* Returns the DbAdmin instance
* @return the DbAdmin instance
* Returns the SnapAdmin instance
* @return the SnapAdmin instance
*/
public SnapAdmin getDbAdmin() {
return dbAdmin;
public SnapAdmin getSnapAdmin() {
return snapAdmin;
}
/**
@ -191,7 +191,7 @@ public class DbObjectSchema {
}
/**
* Adds a field to this schema. This is used by the DbAdmin instance
* Adds a field to this schema. This is used by the SnapAdmin instance
* during initialization and it's not supposed to be called afterwards
* @param f the DbField to add
*/
@ -417,7 +417,7 @@ public class DbObjectSchema {
return dbObject;
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}

View File

@ -54,7 +54,7 @@ import tech.ailef.snapadmin.external.dto.FacetedSearchRequest;
import tech.ailef.snapadmin.external.dto.PaginatedResult;
import tech.ailef.snapadmin.external.dto.PaginationInfo;
import tech.ailef.snapadmin.external.dto.QueryFilter;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.InvalidPageException;
/**
@ -206,7 +206,7 @@ public class SnapAdminRepository {
Optional<DbObject> optional = findById(schema, id);
DbObject dbObject = optional.orElseThrow(() -> {
return new DbAdminException("Unable to retrieve newly inserted item");
return new SnapAdminException("Unable to retrieve newly inserted item");
});
for (String mParam : params.keySet()) {

View File

@ -24,7 +24,7 @@ import java.util.List;
import org.springframework.web.multipart.MultipartFile;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class ByteArrayFieldType extends DbFieldType {
@Override
@ -38,7 +38,7 @@ public class ByteArrayFieldType extends DbFieldType {
try {
return ((MultipartFile)value).getBytes();
} catch (IOException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}
@ -49,6 +49,6 @@ public class ByteArrayFieldType extends DbFieldType {
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException("Binary fields are not comparable");
throw new SnapAdminException("Binary fields are not comparable");
}
}

View File

@ -21,7 +21,7 @@ package tech.ailef.snapadmin.external.dbmapping.fields;
import java.util.List;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class ByteFieldType extends DbFieldType {
@Override
@ -42,6 +42,6 @@ public class ByteFieldType extends DbFieldType {
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException("Binary fields are not comparable");
throw new SnapAdminException("Binary fields are not comparable");
}
}

View File

@ -21,7 +21,7 @@ package tech.ailef.snapadmin.external.dbmapping.fields;
import java.util.List;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class ComputedFieldType extends DbFieldType {
@Override
@ -41,6 +41,6 @@ public class ComputedFieldType extends DbFieldType {
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException();
throw new SnapAdminException();
}
}

View File

@ -24,7 +24,7 @@ import java.time.format.DateTimeParseException;
import java.util.List;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class DateFieldType extends DbFieldType {
@Override
@ -39,7 +39,7 @@ public class DateFieldType extends DbFieldType {
LocalDate localDate = LocalDate.parse(value.toString());
return Date.valueOf(localDate);
} catch (DateTimeParseException e) {
throw new DbAdminException("Invalid date " + value, e);
throw new SnapAdminException("Invalid date " + value, e);
}
}

View File

@ -113,7 +113,7 @@ public class DbField {
public DbObjectSchema getConnectedSchema() {
if (connectedType == null) return null;
return schema.getDbAdmin().findSchemaByClass(connectedType);
return schema.getSnapAdmin().findSchemaByClass(connectedType);
}
public void setSchema(DbObjectSchema schema) {

View File

@ -26,7 +26,7 @@ import java.util.stream.Collectors;
import jakarta.persistence.EnumType;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class EnumFieldType extends DbFieldType {
@ -52,7 +52,7 @@ public class EnumFieldType extends DbFieldType {
return Arrays.stream(invoke).collect(Collectors.toList());
} catch (NoSuchMethodException | SecurityException | InvocationTargetException
| IllegalAccessException | IllegalArgumentException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}
@ -65,11 +65,11 @@ public class EnumFieldType extends DbFieldType {
return valueOf.invoke(null, value.toString());
} catch (InvocationTargetException e) {
if (e.getCause() instanceof IllegalArgumentException)
throw new DbAdminException("Invalid value " + value + " for enum type " + getJavaClass().getSimpleName());
throw new SnapAdminException("Invalid value " + value + " for enum type " + getJavaClass().getSimpleName());
else
throw new DbAdminException(e);
throw new SnapAdminException(e);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException e) {
throw new DbAdminException(e);
throw new SnapAdminException(e);
}
}

View File

@ -22,7 +22,7 @@ import java.util.List;
import jakarta.persistence.ManyToMany;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class ManyToManyFieldType extends DbFieldType {
@Override
@ -52,6 +52,6 @@ public class ManyToManyFieldType extends DbFieldType {
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException();
throw new SnapAdminException();
}
}

View File

@ -22,7 +22,7 @@ import java.util.List;
import jakarta.persistence.OneToMany;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class OneToManyFieldType extends DbFieldType {
@Override
@ -52,6 +52,6 @@ public class OneToManyFieldType extends DbFieldType {
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException();
throw new SnapAdminException();
}
}

View File

@ -22,7 +22,7 @@ import java.util.List;
import jakarta.persistence.OneToOne;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class OneToOneFieldType extends DbFieldType {
@Override
@ -52,6 +52,6 @@ public class OneToOneFieldType extends DbFieldType {
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException();
throw new SnapAdminException();
}
}

View File

@ -27,7 +27,7 @@ import tech.ailef.snapadmin.external.SnapAdmin;
import tech.ailef.snapadmin.external.dbmapping.DbObjectSchema;
import tech.ailef.snapadmin.external.dbmapping.fields.DbField;
import tech.ailef.snapadmin.external.dbmapping.fields.DbFieldType;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.external.exceptions.UnsupportedFieldTypeException;
public class DbQueryOutputField {
@ -47,7 +47,7 @@ public class DbQueryOutputField {
DbObjectSchema schema = dbAdmin.findSchemaByTableName(table);
DbField dbField = schema.getFieldByName(name);
this.dbField = dbField;
} catch (DbAdminException e) {
} catch (SnapAdminException e) {
// We were unable to map this result column to a table, this happens
// for example with COUNT(*) results and similar. We ignore this
// as the dbField will be null and handled as such in the rest of the code

View File

@ -24,7 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
public class DbQueryResultRow {
private Map<DbQueryOutputField, Object> values;
@ -60,7 +60,7 @@ public class DbQueryResultRow {
DbQueryOutputField key =
values.keySet().stream().filter(f -> f.getName().equals(field)).findFirst().orElse(null);
if (key == null) {
throw new DbAdminException("Field " + field + " not found");
throw new SnapAdminException("Field " + field + " not found");
}
return get(key);
}

View File

@ -22,7 +22,7 @@ package tech.ailef.snapadmin.external.dto;
import java.util.Objects;
import tech.ailef.snapadmin.external.dbmapping.fields.DbField;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
/**
* A single filter in a FacetedSearchRequest. This describes a
@ -37,7 +37,7 @@ public class QueryFilter {
public QueryFilter(DbField field, CompareOperator op, String value) {
if (field == null)
throw new DbAdminException("Trying to build QueryFilter with null `field`");
throw new SnapAdminException("Trying to build QueryFilter with null `field`");
this.field = field;
this.op = op;
this.value = value;

View File

@ -25,7 +25,7 @@ package tech.ailef.snapadmin.external.exceptions;
* than the maximum available page). Used internally to redirect the
* user to a default page.
*/
public class InvalidPageException extends DbAdminException {
public class InvalidPageException extends SnapAdminException {
private static final long serialVersionUID = -8891734807568233099L;
public InvalidPageException() {

View File

@ -23,21 +23,21 @@ package tech.ailef.snapadmin.external.exceptions;
* Generic top-level exception for everything thrown by us
*
*/
public class DbAdminException extends RuntimeException {
public class SnapAdminException extends RuntimeException {
private static final long serialVersionUID = 8120227031645804467L;
public DbAdminException() {
public SnapAdminException() {
}
public DbAdminException(String msg, Throwable e) {
public SnapAdminException(String msg, Throwable e) {
super(msg, e);
}
public DbAdminException(Throwable e) {
public SnapAdminException(Throwable e) {
super(e);
}
public DbAdminException(String msg) {
public SnapAdminException(String msg) {
super(msg);
}
}

View File

@ -23,10 +23,10 @@ package tech.ailef.snapadmin.external.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
public class DbAdminNotFoundException extends ResponseStatusException {
public class SnapAdminNotFoundException extends ResponseStatusException {
private static final long serialVersionUID = 4090093290330473479L;
public DbAdminNotFoundException(String message) {
public SnapAdminNotFoundException(String message) {
super(HttpStatus.NOT_FOUND, message);
}

View File

@ -22,7 +22,7 @@ package tech.ailef.snapadmin.external.exceptions;
* Thrown when a field of an `@Entity` class has a type that is not
* supported.
*/
public class UnsupportedFieldTypeException extends DbAdminException {
public class UnsupportedFieldTypeException extends SnapAdminException {
private static final long serialVersionUID = -8891734807568233099L;
public UnsupportedFieldTypeException() {

View File

@ -30,7 +30,7 @@ import tech.ailef.snapadmin.external.dbmapping.DbObjectSchema;
import tech.ailef.snapadmin.external.dbmapping.fields.DbField;
import tech.ailef.snapadmin.external.dto.CompareOperator;
import tech.ailef.snapadmin.external.dto.QueryFilter;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
/**
* Collection of utility functions used across the project
@ -93,7 +93,7 @@ public interface Utils {
if (ops.size() != fields.size() || fields.size() != values.size()
|| ops.size() != values.size()) {
throw new DbAdminException("Filtering parameters must have the same size");
throw new SnapAdminException("Filtering parameters must have the same size");
}
Set<QueryFilter> filters = new HashSet<>();

View File

@ -30,6 +30,6 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(name = "snapadmin.enabled", matchIfMissing = true)
@ComponentScan
@Configuration
public class InternalDbAdminConfiguration {
public class InternalSnapAdminConfiguration {
}

View File

@ -26,7 +26,7 @@ import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.ailef.snapadmin.external.exceptions.DbAdminException;
import tech.ailef.snapadmin.external.exceptions.SnapAdminException;
import tech.ailef.snapadmin.internal.model.UserSetting;
import tech.ailef.snapadmin.internal.repository.UserSettingsRepository;
@ -51,7 +51,7 @@ public class UserConfiguration {
String settingDefaultValue = defaultValues().get(settingName);
if (settingDefaultValue == null)
throw new DbAdminException("Trying to access setting `" + settingName + "` but it has no default value");
throw new SnapAdminException("Trying to access setting `" + settingName + "` but it has no default value");
return settingDefaultValue;
}

View File

@ -23,7 +23,7 @@
* Boot Database Admin in order to save information.
*
* Due to the way Spring Boot component scanning works, it is needed to create this package and the
* respective {@link tech.ailef.snapadmin.internal.InternalDbAdminConfiguration} in order to
* respective {@link tech.ailef.snapadmin.internal.InternalSnapAdminConfiguration} in order to
* have the component scanning only pick the correct entities/repositories.
*/
package tech.ailef.snapadmin.internal;

View File

@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringBootDbAdminApplicationTests {
class SpringBootSNapAdminApplicationTests {
@Test
void contextLoads() {