mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
WIP
This commit is contained in:
parent
5c521609d8
commit
f83adbf601
@ -1,23 +0,0 @@
|
|||||||
package tech.ailef.dbadmin;
|
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class the get the ApplicationContext
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class ApplicationContextUtils implements ApplicationContextAware {
|
|
||||||
|
|
||||||
private static ApplicationContext ctx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(ApplicationContext appContext) {
|
|
||||||
ctx = appContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApplicationContext getApplicationContext() {
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import java.lang.reflect.ParameterizedType;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -25,8 +24,6 @@ import jakarta.persistence.ManyToOne;
|
|||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import jakarta.persistence.PersistenceContext;
|
||||||
import tech.ailef.dbadmin.annotations.DbAdminAppConfiguration;
|
|
||||||
import tech.ailef.dbadmin.annotations.DbAdminConfiguration;
|
|
||||||
import tech.ailef.dbadmin.annotations.DisplayFormat;
|
import tech.ailef.dbadmin.annotations.DisplayFormat;
|
||||||
import tech.ailef.dbadmin.dbmapping.AdvancedJpaRepository;
|
import tech.ailef.dbadmin.dbmapping.AdvancedJpaRepository;
|
||||||
import tech.ailef.dbadmin.dbmapping.DbField;
|
import tech.ailef.dbadmin.dbmapping.DbField;
|
||||||
@ -46,6 +43,8 @@ import tech.ailef.dbadmin.misc.Utils;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class DbAdmin {
|
public class DbAdmin {
|
||||||
|
private DbAdminProperties properties;
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
@ -53,17 +52,9 @@ public class DbAdmin {
|
|||||||
|
|
||||||
private String modelsPackage;
|
private String modelsPackage;
|
||||||
|
|
||||||
public DbAdmin(@Autowired EntityManager entityManager) {
|
public DbAdmin(@Autowired EntityManager entityManager, @Autowired DbAdminProperties properties) {
|
||||||
Map<String, Object> beansWithAnnotation =
|
this.properties = properties;
|
||||||
ApplicationContextUtils.getApplicationContext().getBeansWithAnnotation(DbAdminConfiguration.class);
|
this.modelsPackage = properties.getModelsPackage();
|
||||||
|
|
||||||
if (beansWithAnnotation.size() != 1) {
|
|
||||||
throw new DbAdminException("Found " + beansWithAnnotation.size() + " beans with annotation @DbAdminConfiguration, but must be unique");
|
|
||||||
}
|
|
||||||
|
|
||||||
DbAdminAppConfiguration applicationClass = (DbAdminAppConfiguration) beansWithAnnotation.values().iterator().next();
|
|
||||||
|
|
||||||
this.modelsPackage = applicationClass.getModelsPackage();
|
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
|
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package tech.ailef.dbadmin;
|
package tech.ailef.dbadmin;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -8,6 +8,8 @@ public class DbAdminProperties {
|
|||||||
|
|
||||||
private String baseUrl;
|
private String baseUrl;
|
||||||
|
|
||||||
|
private String modelsPackage;
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
@ -24,5 +26,13 @@ public class DbAdminProperties {
|
|||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getModelsPackage() {
|
||||||
|
return modelsPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModelsPackage(String modelsPackage) {
|
||||||
|
this.modelsPackage = modelsPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package tech.ailef.dbadmin.annotations;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface that includes all the configuration methods that
|
|
||||||
* the user has to implement in order to integrate DbAdmin.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface DbAdminAppConfiguration {
|
|
||||||
public String getModelsPackage();
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package tech.ailef.dbadmin.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the class that holds the DbAdmin configuration.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface DbAdminConfiguration {
|
|
||||||
}
|
|
@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user