diff --git a/pom.xml b/pom.xml
index 024f723..cecdf60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,19 @@
1.16.10
+
+ org.apache.poi
+ poi
+ 3.14
+
+
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.14
+
+
diff --git a/src/main/java/com/codesdream/ase/component/ASESpringUtil.java b/src/main/java/com/codesdream/ase/component/ASESpringUtil.java
new file mode 100644
index 0000000..e4b44cf
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/ASESpringUtil.java
@@ -0,0 +1,22 @@
+package com.codesdream.ase.component;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * 手动获得Bean的工具类
+ */
+@Component
+public class ASESpringUtil {
+ @Resource
+ private ApplicationContext applicationContext;
+
+ public T getBean(Class tClass){
+ return applicationContext.getBean(tClass);
+ }
+
+}
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataModelRepositorySearcher.java b/src/main/java/com/codesdream/ase/component/datamanager/DataModelRepositorySearcher.java
new file mode 100644
index 0000000..c3b9c63
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/datamanager/DataModelRepositorySearcher.java
@@ -0,0 +1,58 @@
+package com.codesdream.ase.component.datamanager;
+
+import com.codesdream.ase.component.ASESpringUtil;
+import lombok.Data;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * DataModel对应Repository层查询器
+ */
+@Data
+@Component
+@Scope("prototype")
+public class DataModelRepositorySearcher {
+ @Resource
+ ASESpringUtil springUtil;
+
+ public final String repositoryPath = "com.codesdream.ase.repository.";
+
+ private Class> repositoryClass = null;
+
+ private boolean present;
+
+ public void getDataModelRepositoryClass(String subSystem, String dataModel){
+ dataModel = doCheckName(dataModel);
+ try {
+ this.repositoryClass = Class.forName(dataModelFullNameGenerator(subSystem, dataModel));
+ this.setPresent(true);
+ } catch (ClassNotFoundException e) {
+ this.setPresent(false);
+ }
+ }
+
+ public T getDataModelRepositoryInstance() {
+ // 确保可以引用
+ if(isPresent()) {
+ @SuppressWarnings("unchecked")
+ T repository = (T) springUtil.getBean(repositoryClass);
+ return repository;
+ }
+ return null;
+ }
+
+
+ public static String doCheckName(String string) {
+ char[] charArray = string.toCharArray();
+ if(Character.isLowerCase(charArray[0])) charArray[0] -= 32;
+ else return string;
+ return String.valueOf(charArray);
+ }
+
+ private String dataModelFullNameGenerator(String subSystem, String dataModel){
+ return new String(repositoryPath + subSystem + "." + dataModel + "Repository");
+ }
+
+}
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataModelSearcher.java b/src/main/java/com/codesdream/ase/component/datamanager/DataModelSearcher.java
new file mode 100644
index 0000000..d4c7925
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/datamanager/DataModelSearcher.java
@@ -0,0 +1,70 @@
+package com.codesdream.ase.component.datamanager;
+
+import lombok.Data;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.swing.text.html.parser.Entity;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * 根据子系统及名称查找特定的Data Model
+ */
+@Data
+@Component
+@Scope("prototype")
+public class DataModelSearcher {
+ public final String modelPath = "com.codesdream.ase.model.";
+ private Class> dataModelClass = null;
+
+ private boolean present;
+
+ public void getDataModelClass(String subSystem, String dataModel) {
+ dataModel = doCheckName(dataModel);
+ try {
+ dataModelClass = Class.forName(dataModelFullNameGenerator(subSystem, dataModel));
+ this.setPresent(true);
+ }catch (ClassNotFoundException e){
+ this.setPresent(false);
+ }
+ }
+
+ public Collection getDataModelParamArgs() {
+ if(isPresent()) {
+ Collection paramArgs = new ArrayList<>();
+ for (Field field : dataModelClass.getDeclaredFields()) {
+ paramArgs.add(field.getName());
+ }
+ return paramArgs;
+ }
+ return null;
+ }
+
+ public T getDataModelInstance(Class dataModelClass) {
+ if(isPresent()){
+ try {
+ return dataModelClass.newInstance();
+ } catch (IllegalAccessException e) {
+ this.setPresent(false);
+ return null;
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static String doCheckName(String string) {
+ char[] charArray = string.toCharArray();
+ if(Character.isLowerCase(charArray[0])) charArray[0] -= 32;
+ else return string;
+ return String.valueOf(charArray);
+ }
+
+ private String dataModelFullNameGenerator(String subSystem, String dataModel){
+ return new String(modelPath + subSystem + "." + dataModel);
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/component/error/ErrorResponse.java b/src/main/java/com/codesdream/ase/component/error/ErrorResponse.java
new file mode 100644
index 0000000..42d5bbf
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/error/ErrorResponse.java
@@ -0,0 +1,22 @@
+package com.codesdream.ase.component.error;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "error")
+public class ErrorResponse
+{
+ public ErrorResponse(String message, List details) {
+ super();
+ this.message = message;
+ this.details = details;
+ }
+
+ //General error message about nature of error
+ private String message;
+
+ //Specific errors in API request processing
+ private List details;
+
+ //Getter and setters
+}
diff --git a/src/main/java/com/codesdream/ase/component/ASEPasswordEncoder.java b/src/main/java/com/codesdream/ase/component/permission/ASEPasswordEncoder.java
similarity index 91%
rename from src/main/java/com/codesdream/ase/component/ASEPasswordEncoder.java
rename to src/main/java/com/codesdream/ase/component/permission/ASEPasswordEncoder.java
index 62e284f..2682436 100644
--- a/src/main/java/com/codesdream/ase/component/ASEPasswordEncoder.java
+++ b/src/main/java/com/codesdream/ase/component/permission/ASEPasswordEncoder.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
diff --git a/src/main/java/com/codesdream/ase/component/ASESecurityAuthenticationProvider.java b/src/main/java/com/codesdream/ase/component/permission/ASESecurityAuthenticationProvider.java
similarity index 94%
rename from src/main/java/com/codesdream/ase/component/ASESecurityAuthenticationProvider.java
rename to src/main/java/com/codesdream/ase/component/permission/ASESecurityAuthenticationProvider.java
index e2cf120..7092134 100644
--- a/src/main/java/com/codesdream/ase/component/ASESecurityAuthenticationProvider.java
+++ b/src/main/java/com/codesdream/ase/component/permission/ASESecurityAuthenticationProvider.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
@@ -11,8 +11,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import java.io.UnsupportedEncodingException;
-import java.security.NoSuchAlgorithmException;
import java.util.Collection;
@Component
diff --git a/src/main/java/com/codesdream/ase/component/ASEUsernameEncoder.java b/src/main/java/com/codesdream/ase/component/permission/ASEUsernameEncoder.java
similarity index 89%
rename from src/main/java/com/codesdream/ase/component/ASEUsernameEncoder.java
rename to src/main/java/com/codesdream/ase/component/permission/ASEUsernameEncoder.java
index 834dcf5..eee9acf 100644
--- a/src/main/java/com/codesdream/ase/component/ASEUsernameEncoder.java
+++ b/src/main/java/com/codesdream/ase/component/permission/ASEUsernameEncoder.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;
diff --git a/src/main/java/com/codesdream/ase/component/UserAuthoritiesGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java
similarity index 90%
rename from src/main/java/com/codesdream/ase/component/UserAuthoritiesGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java
index 52abd66..3963c38 100644
--- a/src/main/java/com/codesdream/ase/component/UserAuthoritiesGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.GrantedAuthority;
diff --git a/src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserFunctionalPermissionContainersListGenerator.java
similarity index 78%
rename from src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UserFunctionalPermissionContainersListGenerator.java
index 535af65..97de9f3 100644
--- a/src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UserFunctionalPermissionContainersListGenerator.java
@@ -1,8 +1,9 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.*;
import org.springframework.stereotype.Component;
+import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
@@ -11,16 +12,9 @@ import java.util.Collection;
*/
@Component
public class UserFunctionalPermissionContainersListGenerator {
-
+ @Resource
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator;
- public UserFunctionalPermissionContainersListGenerator(
- UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator)
- {
- if(userFunctionalScopeRelationsListGenerator == null) throw new NullPointerException();
- this.functionalScopeRelationsListGenerator = userFunctionalScopeRelationsListGenerator;
- }
-
public Collection generateFunctionalContainers(
Collection functionalScopeRelations){
Collection functionalPermissionContainers
diff --git a/src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserFunctionalScopeRelationsListGenerator.java
similarity index 78%
rename from src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UserFunctionalScopeRelationsListGenerator.java
index 2b213a0..5bed3b3 100644
--- a/src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UserFunctionalScopeRelationsListGenerator.java
@@ -1,10 +1,11 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.FunctionalScopeRelation;
import com.codesdream.ase.model.permission.PermissionContainersCollection;
import com.codesdream.ase.model.permission.User;
import org.springframework.stereotype.Component;
+import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
@@ -14,15 +15,9 @@ import java.util.Collection;
@Component
public class UserFunctionalScopeRelationsListGenerator {
+ @Resource
private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator;
- public UserFunctionalScopeRelationsListGenerator(
- UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator)
- {
- if(userPermissionContainersCollectionsListGenerator == null) throw new NullPointerException();
- this.userPermissionContainersCollectionsListGenerator =
- userPermissionContainersCollectionsListGenerator;
- }
public Collection generateFunctionalScopeRelations(
Collection permissionContainersCollections){
diff --git a/src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserPermissionContainersCollectionsListGenerator.java
similarity index 82%
rename from src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UserPermissionContainersCollectionsListGenerator.java
index 88f161e..0a1fc50 100644
--- a/src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UserPermissionContainersCollectionsListGenerator.java
@@ -1,10 +1,11 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.PermissionContainersCollection;
import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User;
import org.springframework.stereotype.Component;
+import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
@@ -13,15 +14,9 @@ import java.util.Collection;
*/
@Component
public class UserPermissionContainersCollectionsListGenerator {
-
+ @Resource
private UserTagsListGenerator userTagsListGenerator;
- public UserPermissionContainersCollectionsListGenerator(UserTagsListGenerator userTagsListGenerator)
- {
- if(userTagsListGenerator == null) throw new NullPointerException();
- this.userTagsListGenerator = userTagsListGenerator;
- }
-
public Collection generatePermissionContainerCollections(
Collection tags){
Collection permissionContainersCollections =
diff --git a/src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java
similarity index 82%
rename from src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java
index c4317c7..1e39c9e 100644
--- a/src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java
@@ -1,11 +1,13 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
+import com.codesdream.ase.component.permission.UserFunctionalPermissionContainersListGenerator;
import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component;
+import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
@@ -14,16 +16,9 @@ import java.util.Collection;
*/
@Component
public class UserRolesListGenerator {
-
+ @Resource
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator;
- public UserRolesListGenerator(
- UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator)
- {
- this.functionalPermissionContainersListGenerator =
- userFunctionalPermissionContainersListGenerator;
- }
-
public Collection generateRoles(
Collection functionalPermissionContainers){
Collection authorities = new ArrayList<>();
diff --git a/src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java
similarity index 93%
rename from src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java
index b3fca13..9b82847 100644
--- a/src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UserTagsListGenerator.java
@@ -1,9 +1,9 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.ScopePermissionContainer;
import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User;
-import com.codesdream.ase.repository.UserRepository;
+import com.codesdream.ase.repository.permission.UserRepository;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
diff --git a/src/main/java/com/codesdream/ase/component/UsersListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UsersListGenerator.java
similarity index 91%
rename from src/main/java/com/codesdream/ase/component/UsersListGenerator.java
rename to src/main/java/com/codesdream/ase/component/permission/UsersListGenerator.java
index 6bbff53..db0abf1 100644
--- a/src/main/java/com/codesdream/ase/component/UsersListGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/permission/UsersListGenerator.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component;
+package com.codesdream.ase.component.permission;
import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User;
diff --git a/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java b/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java
index a94c16b..32dd966 100644
--- a/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java
+++ b/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java
@@ -1,9 +1,8 @@
package com.codesdream.ase.configure;
-import com.codesdream.ase.component.ASEPasswordEncoder;
-import com.codesdream.ase.component.ASESecurityAuthenticationProvider;
+import com.codesdream.ase.component.permission.ASEPasswordEncoder;
+import com.codesdream.ase.component.permission.ASESecurityAuthenticationProvider;
import com.codesdream.ase.service.ASEUserDetailsService;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
diff --git a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java
new file mode 100644
index 0000000..d5166ff
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java
@@ -0,0 +1,23 @@
+package com.codesdream.ase.controller;
+
+import com.codesdream.ase.component.error.ErrorResponse;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.context.request.WebRequest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@ControllerAdvice
+public class ASEControllerAdvice {
+ @ExceptionHandler(value = {RuntimeException.class})
+ public final ResponseEntity