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 handleRuntimeException(RuntimeException e, WebRequest webRequest){ + List details = new ArrayList<>(); + details.add(e.getLocalizedMessage()); + ErrorResponse errorResponse = new ErrorResponse("Runtime Error", details); + return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR); + } + +} diff --git a/src/main/java/com/codesdream/ase/controller/ASEErrorController.java b/src/main/java/com/codesdream/ase/controller/ASEErrorController.java index 189d0cd..0fa6b72 100644 --- a/src/main/java/com/codesdream/ase/controller/ASEErrorController.java +++ b/src/main/java/com/codesdream/ase/controller/ASEErrorController.java @@ -1,26 +1,44 @@ package com.codesdream.ase.controller; +import com.codesdream.ase.component.error.ErrorResponse; import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.request.WebRequest; import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; @Controller public class ASEErrorController implements ErrorController { - @RequestMapping("/error") public String handleError(HttpServletRequest request, Model model){ Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception"); // 页面未找到 - if(statusCode == 404){ + if(statusCode == HttpStatus.NOT_FOUND.value()){ return "not_found"; } + model.addAttribute("http_status", statusCode); + model.addAttribute("exception_name", exception.getClass().getName()); + model.addAttribute("exception_message", exception.getMessage()); + List stack_infos = new ArrayList<>(); + for(StackTraceElement element : exception.getStackTrace()){ + String s = element.toString(); + stack_infos.add(s); + } + model.addAttribute("error_stack", stack_infos); + model.addAttribute("exception_date",new Date()); + return "error"; - return"error"; } @Override diff --git a/src/main/java/com/codesdream/ase/controller/DataManagerController.java b/src/main/java/com/codesdream/ase/controller/DataManagerController.java new file mode 100644 index 0000000..05c7693 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/DataManagerController.java @@ -0,0 +1,42 @@ +package com.codesdream.ase.controller; + +import com.codesdream.ase.component.ASESpringUtil; +import com.codesdream.ase.component.datamanager.DataModelRepositorySearcher; +import com.codesdream.ase.component.datamanager.DataModelSearcher; +import org.apache.catalina.core.ApplicationContext; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.w3c.dom.Entity; + +import javax.annotation.Resource; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.util.*; + +@Controller +@RequestMapping(value = "/database") +public class DataManagerController { + + @Resource + ASESpringUtil springUtil; + + @RequestMapping(value = "{subSystem}/{dataModel}/query") + private String queryView(Model model, @PathVariable String dataModel, @PathVariable String subSystem) { + DataModelRepositorySearcher dataModelRepositorySearcher = springUtil.getBean(DataModelRepositorySearcher.class); + DataModelSearcher dataModelSearcher = springUtil.getBean(DataModelSearcher.class); + + dataModelSearcher.getDataModelClass(subSystem, dataModel); + if(!dataModelSearcher.isPresent()){ + throw new RuntimeException("Data Model Not Found"); + } + dataModelRepositorySearcher.getDataModelRepositoryClass(subSystem, dataModel); + if(!dataModelRepositorySearcher.isPresent()){ + throw new RuntimeException("Data Model Repository Not Found"); + } + + Map data; + return "query"; + } +} diff --git a/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java b/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java new file mode 100644 index 0000000..ce1331e --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java @@ -0,0 +1,17 @@ +package com.codesdream.ase.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class UserInformationIllegalException extends RuntimeException { + + String username; + + public UserInformationIllegalException(String username){ + super(); + this.username = username; + } + +} diff --git a/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java b/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java new file mode 100644 index 0000000..f0d38e3 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java @@ -0,0 +1,17 @@ +package com.codesdream.ase.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class UserNotFoundException extends RuntimeException { + Integer id; + String username; + + public UserNotFoundException(Integer id, String username){ + super(); + this.id = id; + this.username = username; + } +} diff --git a/src/main/java/com/codesdream/ase/exception/UsernameAlreadyExistException.java b/src/main/java/com/codesdream/ase/exception/UsernameAlreadyExistException.java new file mode 100644 index 0000000..634d2e8 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/UsernameAlreadyExistException.java @@ -0,0 +1,16 @@ +package com.codesdream.ase.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class UsernameAlreadyExistException extends RuntimeException { + + String username; + + public UsernameAlreadyExistException(String username){ + super(); + this.username = username; + } +} diff --git a/src/main/java/com/codesdream/ase/model/information/BaseCandidateCategory.java b/src/main/java/com/codesdream/ase/model/information/BaseCandidateCategory.java new file mode 100644 index 0000000..25535dd --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/information/BaseCandidateCategory.java @@ -0,0 +1,20 @@ +package com.codesdream.ase.model.information; + +import lombok.Data; + +import javax.persistence.*; + +/** + * 考生类别基本信息 + */ +@Data +@Entity +@Table(name = "base_candidate_category") +public class BaseCandidateCategory { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + private String name; + +} diff --git a/src/main/java/com/codesdream/ase/model/information/BaseCollege.java b/src/main/java/com/codesdream/ase/model/information/BaseCollege.java index 7bd9299..e62c514 100644 --- a/src/main/java/com/codesdream/ase/model/information/BaseCollege.java +++ b/src/main/java/com/codesdream/ase/model/information/BaseCollege.java @@ -16,4 +16,7 @@ public class BaseCollege { private int id; private String name; + + // 学院代码 + private int number; } diff --git a/src/main/java/com/codesdream/ase/model/information/BaseEthnic.java b/src/main/java/com/codesdream/ase/model/information/BaseEthnic.java index 189926a..9b6b7ab 100644 --- a/src/main/java/com/codesdream/ase/model/information/BaseEthnic.java +++ b/src/main/java/com/codesdream/ase/model/information/BaseEthnic.java @@ -4,6 +4,9 @@ import lombok.Data; import javax.persistence.*; +/** + * 民族基本信息 + */ @Data @Entity @Table(name = "base_ethnic") diff --git a/src/main/java/com/codesdream/ase/model/information/BaseMajor.java b/src/main/java/com/codesdream/ase/model/information/BaseMajor.java index f744510..e7076fd 100644 --- a/src/main/java/com/codesdream/ase/model/information/BaseMajor.java +++ b/src/main/java/com/codesdream/ase/model/information/BaseMajor.java @@ -4,6 +4,9 @@ import lombok.Data; import javax.persistence.*; +/** + * 专业基本信息 + */ @Data @Entity @Table(name = "base_major") diff --git a/src/main/java/com/codesdream/ase/model/information/BasePoliticalStatus.java b/src/main/java/com/codesdream/ase/model/information/BasePoliticalStatus.java new file mode 100644 index 0000000..fd89069 --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/information/BasePoliticalStatus.java @@ -0,0 +1,19 @@ +package com.codesdream.ase.model.information; + +import lombok.Data; + +import javax.persistence.*; + +/** + * 政治面貌基本信息 + */ +@Data +@Entity +@Table(name = "base_political_status") +public class BasePoliticalStatus { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + private String name; +} diff --git a/src/main/java/com/codesdream/ase/model/information/BaseStudentInfo.java b/src/main/java/com/codesdream/ase/model/information/BaseStudentInfo.java new file mode 100644 index 0000000..f5e2c8f --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/information/BaseStudentInfo.java @@ -0,0 +1,42 @@ +package com.codesdream.ase.model.information; + +import lombok.Data; + +import javax.persistence.*; + +/** + * 学生基本真实信息 + */ +@Data +@Entity +@Table(name = "base_student_info") +public class BaseStudentInfo { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + // 真实姓名 + private String name; + // 学号 + private String studentId; + // 班号 + private String classId; + // 性别 + private String sex; + // 民族 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private BaseEthnic ethnic; + // 学院 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private BaseCollege college; + // 专业 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private BaseMajor major; + // 政治面貌 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private BasePoliticalStatus politicalStatus; + // 省份地区 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private BaseAdministrativeDivision administrativeDivision; + +} diff --git a/src/main/java/com/codesdream/ase/model/leaves/Leave.java b/src/main/java/com/codesdream/ase/model/leaves/Leave.java new file mode 100644 index 0000000..bc4f361 --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/leaves/Leave.java @@ -0,0 +1,36 @@ +package com.codesdream.ase.model.leaves; + +import com.codesdream.ase.model.permission.User; +import lombok.Data; +import java.util.*; +import javax.persistence.*; +@Data +@Entity +@Table(name = "leaves_archive") +public class Leave { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + //发出人 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private User userFrom; + //审批人容器 + @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + private Set userTo; + //请假类型 病假,事假等 + @Column(name = "type", nullable = false) + private String type; + //批准状态 + @Column(name = "Authentication", nullable = false) + private Boolean Authentication; + //开始时间 + @Column(nullable = false) + private Date startTime; + @Column(nullable = false) + private Date endTime; + //申请时间 + private Date applyTime; + //认证时间 + private Date authTime; + +} diff --git a/src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java b/src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java new file mode 100644 index 0000000..d21d7ad --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java @@ -0,0 +1,7 @@ +package com.codesdream.ase.model.leaves; +/** + 请假信息的管理系统 + */ +public class LeavesSystem { + +} diff --git a/src/main/java/com/codesdream/ase/model/permission/User.java b/src/main/java/com/codesdream/ase/model/permission/User.java index 87b739c..6819bdc 100644 --- a/src/main/java/com/codesdream/ase/model/permission/User.java +++ b/src/main/java/com/codesdream/ase/model/permission/User.java @@ -1,15 +1,10 @@ package com.codesdream.ase.model.permission; -import com.codesdream.ase.component.UserAuthoritiesGenerator; -import com.codesdream.ase.component.UserRolesListGenerator; import com.codesdream.ase.model.activity.UserActivity; -import com.codesdream.ase.service.IUserService; import lombok.Data; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; -import javax.annotation.PostConstruct; -import javax.annotation.Resource; import javax.persistence.*; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java index 148a185..ef8d1ee 100644 --- a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java +++ b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java @@ -1,8 +1,6 @@ package com.codesdream.ase.model.permission; -import com.codesdream.ase.model.information.BaseAdministrativeDivision; -import com.codesdream.ase.model.information.BaseCollege; -import com.codesdream.ase.model.information.BaseMajor; +import com.codesdream.ase.model.information.*; import lombok.Data; import javax.persistence.*; @@ -19,20 +17,28 @@ public class UserDetail { private int id; // 所属地区 - @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private BaseAdministrativeDivision baseAdministrativeDivision; // 所属学院 - @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private BaseCollege baseCollege; // 所属专业 - @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private BaseMajor baseMajor; + // 民族 + @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + private BaseEthnic baseEthnic; + + // 政治面貌 + @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + private BasePoliticalStatus basePoliticalStatus; + // 真实姓名 - private String realName; + private String realName = ""; // 在校状态 - private boolean atSchool; + private boolean atSchool = false; } diff --git a/src/main/java/com/codesdream/ase/repository/information/BaseAdministrativeDivisionRepository.java b/src/main/java/com/codesdream/ase/repository/information/BaseAdministrativeDivisionRepository.java new file mode 100644 index 0000000..c96f610 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BaseAdministrativeDivisionRepository.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BaseAdministrativeDivision; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface BaseAdministrativeDivisionRepository extends CrudRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/codesdream/ase/repository/information/BaseCandidateCategoryRepository.java b/src/main/java/com/codesdream/ase/repository/information/BaseCandidateCategoryRepository.java new file mode 100644 index 0000000..1536e41 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BaseCandidateCategoryRepository.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BaseCandidateCategory; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface BaseCandidateCategoryRepository extends CrudRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/codesdream/ase/repository/information/BaseCollegeRepository.java b/src/main/java/com/codesdream/ase/repository/information/BaseCollegeRepository.java new file mode 100644 index 0000000..d149b4d --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BaseCollegeRepository.java @@ -0,0 +1,13 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BaseCollege; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface BaseCollegeRepository extends CrudRepository { + Optional findByName(String name); + Optional findByNumber(Integer number); +} diff --git a/src/main/java/com/codesdream/ase/repository/information/BaseEthnicRepository.java b/src/main/java/com/codesdream/ase/repository/information/BaseEthnicRepository.java new file mode 100644 index 0000000..b007952 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BaseEthnicRepository.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BaseEthnic; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface BaseEthnicRepository extends CrudRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/codesdream/ase/repository/information/BaseMajorRepository.java b/src/main/java/com/codesdream/ase/repository/information/BaseMajorRepository.java new file mode 100644 index 0000000..a5d1f34 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BaseMajorRepository.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BaseMajor; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface BaseMajorRepository extends CrudRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/codesdream/ase/repository/information/BasePoliticalStatusRepository.java b/src/main/java/com/codesdream/ase/repository/information/BasePoliticalStatusRepository.java new file mode 100644 index 0000000..1a42b33 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BasePoliticalStatusRepository.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BasePoliticalStatus; +import org.springframework.data.repository.CrudRepository; + +import java.util.Optional; + +public interface BasePoliticalStatusRepository extends CrudRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/codesdream/ase/repository/information/BaseStudentInfoRepository.java b/src/main/java/com/codesdream/ase/repository/information/BaseStudentInfoRepository.java new file mode 100644 index 0000000..69f2d85 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/information/BaseStudentInfoRepository.java @@ -0,0 +1,14 @@ +package com.codesdream.ase.repository.information; + +import com.codesdream.ase.model.information.BaseStudentInfo; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface BaseStudentInfoRepository extends CrudRepository { + // 通过学号查找 + Optional findByStudentId(String student_id); + +} diff --git a/src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java b/src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionRepository.java similarity index 89% rename from src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionRepository.java index 5776b09..134b3f8 100644 --- a/src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/FunctionalPermissionRepository.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.repository; +package com.codesdream.ase.repository.permission; import com.codesdream.ase.model.permission.FunctionalPermissionContainer; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/com/codesdream/ase/repository/PermissionContainersCollectionRepository.java b/src/main/java/com/codesdream/ase/repository/permission/PermissionContainersCollectionRepository.java similarity index 89% rename from src/main/java/com/codesdream/ase/repository/PermissionContainersCollectionRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/PermissionContainersCollectionRepository.java index d0131a0..1b7b242 100644 --- a/src/main/java/com/codesdream/ase/repository/PermissionContainersCollectionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/PermissionContainersCollectionRepository.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.repository; +package com.codesdream.ase.repository.permission; import com.codesdream.ase.model.permission.PermissionContainersCollection; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java b/src/main/java/com/codesdream/ase/repository/permission/ScopePermissionRepository.java similarity index 86% rename from src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/ScopePermissionRepository.java index 984580a..95893f8 100644 --- a/src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/ScopePermissionRepository.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.repository; +package com.codesdream.ase.repository.permission; import com.codesdream.ase.model.permission.ScopePermissionContainer; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/com/codesdream/ase/repository/TagRepository.java b/src/main/java/com/codesdream/ase/repository/permission/TagRepository.java similarity index 89% rename from src/main/java/com/codesdream/ase/repository/TagRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/TagRepository.java index 9af0508..f46de40 100644 --- a/src/main/java/com/codesdream/ase/repository/TagRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/TagRepository.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.repository; +package com.codesdream.ase.repository.permission; import com.codesdream.ase.model.permission.FunctionalPermissionContainer; import com.codesdream.ase.model.permission.Tag; diff --git a/src/main/java/com/codesdream/ase/repository/UserRepository.java b/src/main/java/com/codesdream/ase/repository/permission/UserRepository.java similarity index 88% rename from src/main/java/com/codesdream/ase/repository/UserRepository.java rename to src/main/java/com/codesdream/ase/repository/permission/UserRepository.java index 486beec..6ba5c8e 100644 --- a/src/main/java/com/codesdream/ase/repository/UserRepository.java +++ b/src/main/java/com/codesdream/ase/repository/permission/UserRepository.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.repository; +package com.codesdream.ase.repository.permission; import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.User; diff --git a/src/main/java/com/codesdream/ase/service/ASEUserDetailsService.java b/src/main/java/com/codesdream/ase/service/ASEUserDetailsService.java index 00e9ad8..411bcbb 100644 --- a/src/main/java/com/codesdream/ase/service/ASEUserDetailsService.java +++ b/src/main/java/com/codesdream/ase/service/ASEUserDetailsService.java @@ -1,6 +1,6 @@ package com.codesdream.ase.service; -import com.codesdream.ase.component.UserAuthoritiesGenerator; +import com.codesdream.ase.component.permission.UserAuthoritiesGenerator; import com.codesdream.ase.model.permission.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -9,7 +9,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.transaction.Transactional; -import java.util.Optional; @Service public class ASEUserDetailsService implements UserDetailsService { diff --git a/src/main/java/com/codesdream/ase/service/IBaseInformationService.java b/src/main/java/com/codesdream/ase/service/IBaseInformationService.java new file mode 100644 index 0000000..8c55369 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/IBaseInformationService.java @@ -0,0 +1,5 @@ +package com.codesdream.ase.service; + +public interface IBaseInformationService { + boolean checkAdministrativeDivision(String name); +} diff --git a/src/main/java/com/codesdream/ase/service/IUserService.java b/src/main/java/com/codesdream/ase/service/IUserService.java index 5de817d..277d413 100644 --- a/src/main/java/com/codesdream/ase/service/IUserService.java +++ b/src/main/java/com/codesdream/ase/service/IUserService.java @@ -1,6 +1,7 @@ package com.codesdream.ase.service; import com.codesdream.ase.model.permission.User; +import javafx.util.Pair; import org.springframework.security.core.GrantedAuthority; import java.util.Collection; @@ -16,20 +17,28 @@ public interface IUserService { List findAll(); Optional findUserById(int id); + User findUserByUsername(String username); + public Pair checkIfUserExists(String username); + // 获得用户所有的权限角色 Collection getUserAuthorities(User user); // 更新用户的密码 void updatePassword(User user, String password); - // 生成随机用户名 + // 根据学号生成随机用户名 void generateRandomUsernameByStudentID(User user, String id); + // 注册用户 User save(User user); + // 更新用户信息 User update(User user); + // 删除用户 + void delete(User user); + } diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index 056a6c1..ee8f8f2 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -1,11 +1,11 @@ package com.codesdream.ase.service; -import com.codesdream.ase.component.UserFunctionalPermissionContainersListGenerator; -import com.codesdream.ase.component.UserFunctionalScopeRelationsListGenerator; +import com.codesdream.ase.component.permission.UserFunctionalPermissionContainersListGenerator; +import com.codesdream.ase.component.permission.UserFunctionalScopeRelationsListGenerator; import com.codesdream.ase.model.permission.*; -import com.codesdream.ase.repository.FunctionalPermissionRepository; -import com.codesdream.ase.repository.ScopePermissionRepository; -import com.codesdream.ase.repository.TagRepository; +import com.codesdream.ase.repository.permission.FunctionalPermissionRepository; +import com.codesdream.ase.repository.permission.ScopePermissionRepository; +import com.codesdream.ase.repository.permission.TagRepository; import javafx.util.Pair; import org.springframework.stereotype.Service; @@ -30,7 +30,7 @@ public class PermissionService implements IPermissionService { private UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator; @Resource - UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator; + private UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator; @Override public Optional findTag(String name) { diff --git a/src/main/java/com/codesdream/ase/service/UserService.java b/src/main/java/com/codesdream/ase/service/UserService.java index 45fb059..10372be 100644 --- a/src/main/java/com/codesdream/ase/service/UserService.java +++ b/src/main/java/com/codesdream/ase/service/UserService.java @@ -1,10 +1,14 @@ package com.codesdream.ase.service; -import com.codesdream.ase.component.ASEPasswordEncoder; -import com.codesdream.ase.component.ASEUsernameEncoder; -import com.codesdream.ase.component.UserRolesListGenerator; +import com.codesdream.ase.component.permission.ASEPasswordEncoder; +import com.codesdream.ase.component.permission.ASEUsernameEncoder; +import com.codesdream.ase.component.permission.UserRolesListGenerator; +import com.codesdream.ase.exception.UserInformationIllegalException; +import com.codesdream.ase.exception.UserNotFoundException; +import com.codesdream.ase.exception.UsernameAlreadyExistException; import com.codesdream.ase.model.permission.User; -import com.codesdream.ase.repository.UserRepository; +import com.codesdream.ase.repository.permission.UserRepository; +import javafx.util.Pair; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; @@ -41,10 +45,16 @@ public class UserService implements IUserService { @Override public User findUserByUsername(String username) { Optional user = userRepository.findByUsername(username); - if(!user.isPresent()) throw new UsernameNotFoundException("User Not Found"); + if(!user.isPresent()) throw new UsernameNotFoundException(username); return user.get(); } + @Override + public Pair checkIfUserExists(String username){ + Optional user = userRepository.findByUsername(username); + return user.map(value -> new Pair<>(true, value)).orElseGet(() -> new Pair<>(false, null)); + } + @Override public Collection getUserAuthorities(User user) { return userRolesListGenerator.generateRoles(user); @@ -66,23 +76,43 @@ public class UserService implements IUserService { public User save(User user) { // 查找用户名是否已经被注册 if(userRepository.findByUsername(user.getUsername()).isPresent()) - throw new RuntimeException("Username Already Exists"); + throw new UsernameAlreadyExistException(user.getUsername()); + + // 用户信息一般性规范检查 + if(user.getUserAuth().getUserAnswer().length() > 255 + || user.getUserAuth().getUserQuestion().length() > 255 + || user.getUserAuth().getStudentID().length() > 24 + || user.getUserAuth().getMail().length() > 64 + || user.getUserDetail().getRealName().length() > 12) + throw new UserInformationIllegalException(user.getUsername()); + + // 强制以哈希值(sha256)保存密码 user.setPassword(passwordEncoder.encode(user.getPassword())); return userRepository.save(user); } @Override public User update(User user) { - if(!userRepository.findByUsername(user.getUsername()).isPresent()) - throw new RuntimeException("Username Already Exists"); + // 执行前检查 + if(!userRepository.findById(user.getId()).isPresent()) + throw new UserNotFoundException(user.getId(), user.getUsername()); return userRepository.save(user); } + @Override + public void delete(User user) { + // 执行前检查 + if(!userRepository.findById(user.getId()).isPresent()) + throw new UserNotFoundException(user.getId(), user.getUsername()); + userRepository.delete(user); + } + // 获得一个默认初始化的用户对象 @Override public User getDefaultUser() { return new User(); } + } diff --git a/src/main/java/com/codesdream/ase/test/DataManagerTest.java b/src/main/java/com/codesdream/ase/test/DataManagerTest.java new file mode 100644 index 0000000..9404bb5 --- /dev/null +++ b/src/main/java/com/codesdream/ase/test/DataManagerTest.java @@ -0,0 +1,45 @@ +package com.codesdream.ase.test; + +import com.codesdream.ase.component.ASESpringUtil; +import com.codesdream.ase.component.datamanager.DataModelRepositorySearcher; +import com.codesdream.ase.component.datamanager.DataModelSearcher; +import com.codesdream.ase.repository.permission.UserRepository; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +@RunWith(SpringRunner.class) +@SpringBootTest +public class DataManagerTest { + @Resource + ASESpringUtil springUtil; + + @Test + public void dataModelSearcherTest() { + DataModelSearcher dataModelSearcher = springUtil.getBean(DataModelSearcher.class); + dataModelSearcher.getDataModelClass("permission", "Tag"); + Assert.assertTrue(dataModelSearcher.isPresent()); + + for(String param : dataModelSearcher.getDataModelParamArgs()){ + System.out.println(param); + } + + } + + @Test + public void dataModelRepositorySearcherTest(){ + DataModelRepositorySearcher dataModelRepositorySearcher = + springUtil.getBean(DataModelRepositorySearcher.class); + + dataModelRepositorySearcher.getDataModelRepositoryClass("permission", "User"); + Assert.assertTrue(dataModelRepositorySearcher.isPresent()); + UserRepository userRepository = dataModelRepositorySearcher.getDataModelRepositoryInstance(); + + } + +} diff --git a/src/main/java/com/codesdream/ase/test/UserTest.java b/src/main/java/com/codesdream/ase/test/UserTest.java index 374123e..1b0c25e 100644 --- a/src/main/java/com/codesdream/ase/test/UserTest.java +++ b/src/main/java/com/codesdream/ase/test/UserTest.java @@ -1,75 +1,71 @@ package com.codesdream.ase.test; -import com.codesdream.ase.model.permission.FunctionalPermissionContainer; -import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.User; -import com.codesdream.ase.repository.UserRepository; import static org.junit.Assert.*; +import com.codesdream.ase.service.UserService; +import com.sun.org.apache.xpath.internal.operations.Bool; +import javafx.util.Pair; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import java.util.HashMap; -import java.util.HashSet; +import javax.annotation.Resource; /** * 用户基本表单元测试 * 用于测试数据库与DAO层交互是否通畅 */ -@DataJpaTest @RunWith(SpringRunner.class) +@SpringBootTest public class UserTest { - @Autowired - private TestEntityManager entityManager; - - @Autowired - private UserRepository userRepository; + @Resource + private UserService userService; /** * 基本存储与查询测试 */ @Test public void UserBaseTest_1(){ - User user = new User("Tim", "123456"); - userRepository.save(user); - assertTrue(userRepository.findByUsername("Tim").isPresent()); - assertFalse(userRepository.findByUsername("Tom").isPresent()); - user = userRepository.findByUsername("Tim").get(); + // 查找数据库中是否有重复项 + Pair checker = userService.checkIfUserExists("Tim"); + if(checker.getKey()){ + userService.delete(checker.getValue()); + } + + User user = userService.getDefaultUser(); + user.setUsername("Tim"); + user.setPassword("123456"); + user.getUserAuth().setStudentID("2018303026"); + user.getUserAuth().setMail("937447984@qq.com"); + user.getUserAuth().setUserQuestion("Your favourite animal?"); + user.getUserAuth().setUserAnswer("Cat"); + user.getUserDetail().setAtSchool(true); + userService.save(user); + + user = userService.findUserByUsername("Tim"); assertEquals(user.getUsername(), "Tim"); - assertEquals(user.getPassword(), "123456"); + assertEquals(user.getPassword(), + "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92"); + // 检查账号状态 assertTrue(user.isEnabled()); assertFalse(user.isDeleted()); + assertTrue(user.isAccountNonExpired()); + assertTrue(user.isAccountNonLocked()); + assertTrue(user.isCredentialsNonExpired()); + assertEquals(user.getUserAuth().getStudentID(), "2018303026"); + assertEquals(user.getUserAuth().getMail(), "937447984@qq.com"); + assertEquals(user.getUserAuth().getUserQuestion(), "Your favourite animal?"); + assertEquals(user.getUserAuth().getUserAnswer(), "Cat"); } @Test public void UserBaseTest_2(){ - // 用户 - User user = new User("Pat", "123456"); - // 标签 - Tag tag = new Tag("学生","普通学生"); - // 功能性权限容器 - FunctionalPermissionContainer functionalPermissionContainer = - new FunctionalPermissionContainer("基本用户权限", "基本的用户权限"); - - // 添加为标签功能性权限容器 - HashSet functionalPermissionContainers = new HashSet<>(); - functionalPermissionContainers.add(functionalPermissionContainer); - // 等待添加 - - // 为用户添加标签 - HashSet tags = new HashSet<>(); - tags.add(tag); - user.setTags(tags); - - userRepository.save(user); - + User user = userService.findUserByUsername("Tim"); diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index 3c55a1c..55690a0 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -8,11 +8,89 @@ -
-

Error

+ +
+
+ +
+
+
+
+ +
+
+
+
+ +

  概要信息

+
+
+
+ 此次异常的简要信息已被异常管理子系统收集并概括如下表 +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#信息项
0 HTTP状态
1异常类型
2附带消息
2附带消息
+
+ +
+
+
+

  运行栈相关信息

+
+
+
    +
  1. + +
  2. +
+ +
+
+
+
+
+
+
+
- - - \ No newline at end of file diff --git a/src/main/resources/templates/not_found.html b/src/main/resources/templates/not_found.html index 1890621..6a4a8e1 100644 --- a/src/main/resources/templates/not_found.html +++ b/src/main/resources/templates/not_found.html @@ -8,10 +8,23 @@ -
-

404 Not Found

+
+
+
- +
+
+
+
+
+ +
+
+
diff --git a/src/main/resources/templates/query.html b/src/main/resources/templates/query.html new file mode 100644 index 0000000..de567c1 --- /dev/null +++ b/src/main/resources/templates/query.html @@ -0,0 +1,11 @@ + + + + + Title + + + + + \ No newline at end of file