diff --git a/pom.xml b/pom.xml index 900747a..c36beed 100644 --- a/pom.xml +++ b/pom.xml @@ -177,6 +177,12 @@ 2.9.2 + + com.github.java-json-tools + json-patch + 1.12 + + diff --git a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java index 67c90b9..4ae1b7f 100644 --- a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java +++ b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java @@ -1,21 +1,18 @@ package com.codesdream.ase.component.activity; import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.exception.DataInvalidFormatException; +import com.codesdream.ase.exception.innerservererror.DataInvalidFormatException; import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.activity.Attendance; import com.codesdream.ase.model.activity.Period; import com.codesdream.ase.model.permission.User; -import com.codesdream.ase.repository.activity.ActivityRepository; import com.codesdream.ase.service.ActivityService; import com.codesdream.ase.service.AttendanceService; import com.codesdream.ase.service.PeriodService; import com.codesdream.ase.service.UserService; -import javafx.util.converter.LocalDateTimeStringConverter; import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java index 83c1948..c11d01b 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java @@ -1,7 +1,7 @@ package com.codesdream.ase.component.datamanager; import com.codesdream.ase.exception.notfound.DataFileNotFoundException; -import com.codesdream.ase.exception.DataIOException; +import com.codesdream.ase.exception.innerservererror.DataIOException; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java index f5471f2..794f8c3 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java @@ -2,6 +2,9 @@ package com.codesdream.ase.component.datamanager; import com.codesdream.ase.exception.*; +import com.codesdream.ase.exception.innerservererror.DataIOException; +import com.codesdream.ase.exception.innerservererror.DataIllegalTableFormatException; +import com.codesdream.ase.exception.innerservererror.DataInvalidFormatException; import com.codesdream.ase.exception.notfound.DataFileNotFoundException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; @@ -48,7 +51,7 @@ public class DataExcelReader implements DataReader { Row titleRow = sheet.getRow(0); colNumber = titleRow.getLastCellNum(); // 表头项目个数不可为0 - if(colNumber == 0) throw new DataIllegalTableFormatException(); + if(colNumber == 0) throw new DataIllegalTableFormatException(); Collection title = new ArrayList<>(); for(int cellIdx = 0; cellIdx < colNumber; cellIdx++){ title.add(readCell(titleRow.getCell(cellIdx))); diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java b/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java index cf1217c..97d04f5 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java @@ -1,11 +1,9 @@ package com.codesdream.ase.component.datamanager; -import com.codesdream.ase.exception.DataIllegalTableFormatException; +import com.codesdream.ase.exception.innerservererror.DataIllegalTableFormatException; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import javax.persistence.Table; -import javax.swing.text.html.Option; import java.util.*; // 描述一张数据表 diff --git a/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java b/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java new file mode 100644 index 0000000..64b719b --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java @@ -0,0 +1,23 @@ +package com.codesdream.ase.component.datamanager; + +import com.codesdream.ase.exception.innerservererror.HandlingErrorsException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jsonpatch.JsonPatch; +import com.github.fge.jsonpatch.JsonPatchException; +import org.springframework.stereotype.Controller; + +@Controller +public class JsonPathParameter { + public T parsePathToObject(JsonPatch patch, T object){ + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode patched = patch.apply(mapper.convertValue(object, JsonNode.class)); + return (T) mapper.treeToValue(patched, object.getClass()); + } catch (JsonPatchException | JsonProcessingException e) { + throw new HandlingErrorsException(e.getMessage()); + } + + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonablePCCList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonablePCCList.java new file mode 100644 index 0000000..870743e --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonablePCCList.java @@ -0,0 +1,22 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.model.permission.PermissionContainersCollection; +import com.codesdream.ase.model.permission.Tag; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@ApiModel("权限容器集合列表") +public class JsonablePCCList { + List pccIdList; + + public JsonablePCCList(Tag tag){ + for(PermissionContainersCollection pcc : tag.getPermissionContainersCollections()){ + pccIdList.add(pcc.getId()); + } + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java similarity index 87% rename from src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java rename to src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java index 523c61e..e91c3cb 100644 --- a/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java @@ -12,13 +12,13 @@ import java.util.List; @Data @NoArgsConstructor @ApiModel("标签所属用户集合") -public class JsonableTagUserList { +public class JsonableUserList { @ApiModelProperty(name = "用户列表") private List users; - public JsonableTagUserList(Tag tag){ + public JsonableUserList(Tag tag){ for(User user : tag.getUsers()){ users.add(user.getId()); } diff --git a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java index bdddf30..281ced4 100644 --- a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java +++ b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java @@ -3,7 +3,11 @@ package com.codesdream.ase.controller; import com.codesdream.ase.component.api.QuickJSONRespond; import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond; import com.codesdream.ase.exception.badrequest.AlreadyExistException; +import com.codesdream.ase.exception.badrequest.IllegalException; import com.codesdream.ase.exception.conflict.RelatedObjectsExistException; +import com.codesdream.ase.exception.innerservererror.FormatException; +import com.codesdream.ase.exception.innerservererror.HandlingErrorsException; +import com.codesdream.ase.exception.innerservererror.RuntimeIOException; import com.codesdream.ase.exception.notfound.NotFoundException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -21,7 +25,8 @@ public class ASEControllerAdvice { @ExceptionHandler(value = { NullPointerException.class, - AlreadyExistException.class + AlreadyExistException.class, + IllegalException.class }) public ResponseEntity handleBadRequest(Exception ex) { return getResponse(HttpStatus.BAD_REQUEST, ex); @@ -43,6 +48,14 @@ public class ASEControllerAdvice { return getResponse(HttpStatus.CONFLICT, ex); } + @ExceptionHandler(value = { + HandlingErrorsException.class, + FormatException.class, + RuntimeIOException.class}) + public ResponseEntity handleInnerServerError(Exception ex){ + return getResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex); + } + private ResponseEntity getResponse(HttpStatus status, Exception ex){ return ResponseEntity.status(status).body(getJSON(status, ex)); diff --git a/src/main/java/com/codesdream/ase/controller/PermissionController.java b/src/main/java/com/codesdream/ase/controller/PermissionController.java index 766d619..400bbfa 100644 --- a/src/main/java/com/codesdream/ase/controller/PermissionController.java +++ b/src/main/java/com/codesdream/ase/controller/PermissionController.java @@ -1,30 +1,31 @@ package com.codesdream.ase.controller; -import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.component.datamanager.JSONParameter; -import com.codesdream.ase.component.api.QuickJSONRespond; +import com.codesdream.ase.component.datamanager.JsonPathParameter; +import com.codesdream.ase.component.json.model.JsonablePCCList; import com.codesdream.ase.component.json.model.JsonableTag; -import com.codesdream.ase.component.json.model.JsonableTagUserList; +import com.codesdream.ase.component.json.model.JsonableUserList; import com.codesdream.ase.component.json.model.JsonableUser; -import com.codesdream.ase.component.json.respond.PermissionJSONRespond; import com.codesdream.ase.exception.badrequest.AlreadyExistException; import com.codesdream.ase.exception.conflict.RelatedObjectsExistException; import com.codesdream.ase.exception.notfound.NotFoundException; -import com.codesdream.ase.exception.notfound.TagNotFoundException; +import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.service.IUserService; import com.codesdream.ase.service.PermissionService; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jsonpatch.JsonPatch; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.formula.functions.T; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import springfox.documentation.spring.web.json.Json; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -41,6 +42,9 @@ public class PermissionController { @Resource private IUserService userService; + @Resource + private JsonPathParameter pathParameter; + // 根据名字创建新的标签 @PostMapping("tag") @ResponseStatus(HttpStatus.CREATED) @@ -99,31 +103,51 @@ public class PermissionController { permissionService.delete(tag.get()); } + // 根据名字搜索标签的简要信息 + @PatchMapping(path = "tag", consumes = "application/json-patch+json") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation("修改标签属性") + @ApiImplicitParam(name = "name", value = "标签名") + public JsonableTag updateTag(@RequestParam(value = "name") String name, @RequestBody JsonPatch patch){ + Optional tag = permissionService.findTag(name); + if(!tag.isPresent()) throw new NotFoundException(name); + + JsonableTag jsonableTag = new JsonableTag(tag.get()); + jsonableTag = pathParameter.parsePathToObject(patch, jsonableTag); + + tag.get().setName(jsonableTag.getName()); + tag.get().setDescription(jsonableTag.getDescription()); + + return new JsonableTag(permissionService.save(tag.get())); + + } + + @GetMapping("tag/users") @ResponseStatus(HttpStatus.OK) @ApiOperation("搜索单个标签所属用户集合信息") - public JsonableTagUserList getUserTag(@RequestParam(value = "name") String name){ + public JsonableUserList getUserTag(@RequestParam(value = "name") String name){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); - return new JsonableTagUserList(tag.get()); + return new JsonableUserList(tag.get()); } @PutMapping("tag/users") @ApiOperation("更新索单个标签所属用户集合信息") - public JsonableTagUserList setUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){ + public JsonableUserList setUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); Set userSet = new HashSet<>(userList.getUsers()); tag.get().setUsers(userService.findUsersById(userSet)); - return new JsonableTagUserList(permissionService.save(tag.get())); + return new JsonableUserList(permissionService.save(tag.get())); } @PostMapping("tag/users") @ApiOperation("更新单个标签所属用户集合中添加一个或多个用户") - public JsonableTagUserList addUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){ + public JsonableUserList addUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); Set newUserSet = userService.findUsersById(new HashSet<>(userList.getUsers())); @@ -133,13 +157,14 @@ public class PermissionController { userSet.addAll(newUserSet); tag.get().setUsers(userSet); - return new JsonableTagUserList(permissionService.save(tag.get())); + return new JsonableUserList(permissionService.save(tag.get())); } @DeleteMapping("tag/users") + @ResponseStatus(HttpStatus.OK) @ApiOperation("从单个标签所属用户集合中删除一个或多个用户") @ApiImplicitParam(name = "name", value = "标签名") - public JsonableTagUserList deleteUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){ + public JsonableUserList deleteUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); Set userSet = tag.get().getUsers(); @@ -148,7 +173,7 @@ public class PermissionController { userSet.removeAll(deleteUserSet); tag.get().setUsers(userSet); - return new JsonableTagUserList(permissionService.save(tag.get())); + return new JsonableUserList(permissionService.save(tag.get())); } @GetMapping("tags/users") @@ -167,6 +192,31 @@ public class PermissionController { return jsonableUsers; } + @GetMapping("tag/pcc") + @ResponseStatus(HttpStatus.OK) + @ApiOperation("获取标签所含权限容器集合列表") + public JsonablePCCList getPCCTag(@RequestParam(value = "name") String name){ + Optional tagOptional = permissionService.findTag(name); + if(!tagOptional.isPresent()) throw new NotFoundException(name); + + return new JsonablePCCList(tagOptional.get()); + } + + @PostMapping("tag/pcc") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation("在指定标签的权限列表中添加一个或多个权限容器") + public JsonablePCCList addPCCTag(@RequestParam(value = "name") String name, JsonablePCCList jsonablePCCList){ + Optional tagOptional = permissionService.findTag(name); + if(!tagOptional.isPresent()) throw new NotFoundException(name); + + Set pccs = tagOptional.get().getPermissionContainersCollections(); + pccs.addAll(permissionService.findPCCs(new HashSet(jsonablePCCList.getPccIdList()))); + + tagOptional.get().setPermissionContainersCollections(pccs); + + return new JsonablePCCList(permissionService.save(tagOptional.get())); + } + } diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java index ad6e384..64b2d2b 100644 --- a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java @@ -7,7 +7,7 @@ import com.codesdream.ase.component.activity.NullValueAttributes; import com.codesdream.ase.component.datamanager.JSONParameter; import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond; import com.codesdream.ase.configure.ActivityFormConfigure; -import com.codesdream.ase.exception.InvalidFormFormatException; +import com.codesdream.ase.exception.innerservererror.InvalidFormFormatException; import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.activity.UserActivity; import com.codesdream.ase.model.permission.User; @@ -20,7 +20,6 @@ import com.codesdream.ase.validator.JSONFormValidator; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -28,7 +27,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.InvocationTargetException; import java.util.List; -import java.util.Map; import java.util.Optional; @Controller diff --git a/src/main/java/com/codesdream/ase/exception/DataIOException.java b/src/main/java/com/codesdream/ase/exception/DataIOException.java deleted file mode 100644 index f220cac..0000000 --- a/src/main/java/com/codesdream/ase/exception/DataIOException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.codesdream.ase.exception; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class DataIOException extends RuntimeException { -} diff --git a/src/main/java/com/codesdream/ase/exception/DataIllegalTableFormatException.java b/src/main/java/com/codesdream/ase/exception/DataIllegalTableFormatException.java deleted file mode 100644 index 5c01b8c..0000000 --- a/src/main/java/com/codesdream/ase/exception/DataIllegalTableFormatException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.codesdream.ase.exception; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class DataIllegalTableFormatException extends RuntimeException { -} diff --git a/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java b/src/main/java/com/codesdream/ase/exception/badrequest/BaseInformationIllegalException.java similarity index 73% rename from src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java rename to src/main/java/com/codesdream/ase/exception/badrequest/BaseInformationIllegalException.java index 34b485b..1cd9768 100644 --- a/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java +++ b/src/main/java/com/codesdream/ase/exception/badrequest/BaseInformationIllegalException.java @@ -1,11 +1,11 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.badrequest; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data -public class BaseInformationIllegalException extends RuntimeException { +public class BaseInformationIllegalException extends IllegalException { String type; String value; diff --git a/src/main/java/com/codesdream/ase/exception/badrequest/IllegalException.java b/src/main/java/com/codesdream/ase/exception/badrequest/IllegalException.java new file mode 100644 index 0000000..c62f81a --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/badrequest/IllegalException.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.exception.badrequest; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class IllegalException extends RuntimeException { + public IllegalException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java b/src/main/java/com/codesdream/ase/exception/badrequest/UserInformationIllegalException.java similarity index 68% rename from src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java rename to src/main/java/com/codesdream/ase/exception/badrequest/UserInformationIllegalException.java index ce1331e..1107c14 100644 --- a/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java +++ b/src/main/java/com/codesdream/ase/exception/badrequest/UserInformationIllegalException.java @@ -1,11 +1,11 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.badrequest; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data -public class UserInformationIllegalException extends RuntimeException { +public class UserInformationIllegalException extends IllegalException { String username; diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/DataIOException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIOException.java new file mode 100644 index 0000000..7c3615e --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIOException.java @@ -0,0 +1,9 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class DataIOException extends RuntimeIOException { +} diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/DataIllegalTableFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIllegalTableFormatException.java new file mode 100644 index 0000000..d68b2d8 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIllegalTableFormatException.java @@ -0,0 +1,9 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class DataIllegalTableFormatException extends FormatException { +} diff --git a/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java similarity index 71% rename from src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java rename to src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java index b5d4de5..99f6dd9 100644 --- a/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java @@ -1,11 +1,11 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.innerservererror; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data -public class DataInvalidFormatException extends RuntimeException { +public class DataInvalidFormatException extends FormatException { String information; public DataInvalidFormatException(Exception e){ diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/FormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/FormatException.java new file mode 100644 index 0000000..dd6a734 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/FormatException.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class FormatException extends RuntimeException { + public FormatException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/HandlingErrorsException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/HandlingErrorsException.java new file mode 100644 index 0000000..e87c712 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/HandlingErrorsException.java @@ -0,0 +1,13 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.NoArgsConstructor; + +// 处理错误对应的异常类 +@Data +@NoArgsConstructor +public class HandlingErrorsException extends RuntimeException { + public HandlingErrorsException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/InvalidFormFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidFormFormatException.java similarity index 75% rename from src/main/java/com/codesdream/ase/exception/InvalidFormFormatException.java rename to src/main/java/com/codesdream/ase/exception/innerservererror/InvalidFormFormatException.java index be25439..fc49abb 100644 --- a/src/main/java/com/codesdream/ase/exception/InvalidFormFormatException.java +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidFormFormatException.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.innerservererror; import lombok.Data; import lombok.EqualsAndHashCode; @@ -7,7 +7,7 @@ import javax.persistence.criteria.CriteriaBuilder; @EqualsAndHashCode(callSuper = true) @Data -public class InvalidFormFormatException extends Throwable { +public class InvalidFormFormatException extends FormatException { private String message = "Invalid form format"; diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/RuntimeIOException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/RuntimeIOException.java new file mode 100644 index 0000000..df0c511 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/RuntimeIOException.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class RuntimeIOException extends RuntimeException { + public RuntimeIOException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/service/BaseInformationService.java b/src/main/java/com/codesdream/ase/service/BaseInformationService.java index ec287a5..b659029 100644 --- a/src/main/java/com/codesdream/ase/service/BaseInformationService.java +++ b/src/main/java/com/codesdream/ase/service/BaseInformationService.java @@ -2,7 +2,7 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.datamanager.DataTable; import com.codesdream.ase.exception.badrequest.BaseInformationAlreadyExistException; -import com.codesdream.ase.exception.BaseInformationIllegalException; +import com.codesdream.ase.exception.badrequest.BaseInformationIllegalException; import com.codesdream.ase.exception.notfound.BaseInformationNotFoundException; import com.codesdream.ase.model.information.*; import com.codesdream.ase.repository.information.*; diff --git a/src/main/java/com/codesdream/ase/service/IPermissionService.java b/src/main/java/com/codesdream/ase/service/IPermissionService.java index ca8ec6e..fb875ab 100644 --- a/src/main/java/com/codesdream/ase/service/IPermissionService.java +++ b/src/main/java/com/codesdream/ase/service/IPermissionService.java @@ -44,6 +44,10 @@ public interface IPermissionService { // 标签下所有的获得权限容器集合列表 Collection getPCCs(Tag tag); + Set findPCCs(Set pccs); + + Optional findPCC(Integer id); + // 获得范围性权限容器下的所有标签列表 Collection getTagsFromSPC( ScopePermissionContainer spc); diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index 918c7f2..6ddea4f 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -110,6 +110,22 @@ public class PermissionService implements IPermissionService { return new ArrayList<>(tag.getPermissionContainersCollections()); } + @Override + public Set findPCCs(Set pccs) { + Set set = new HashSet<>(); + for(Integer id : pccs){ + Optional pcc = findPCC(id); + if(!pcc.isPresent()) throw new NotFoundException(String.format("PCCId: %d",id)); + set.add(pcc.get()); + } + return set; + } + + @Override + public Optional findPCC(Integer id) { + return pccRepository.findById(id); + } + @Override public Collection getTagsFromSPC(ScopePermissionContainer spc) { return new ArrayList<>(spc.getTags()); diff --git a/src/main/java/com/codesdream/ase/service/UserService.java b/src/main/java/com/codesdream/ase/service/UserService.java index f4710e4..da9333b 100644 --- a/src/main/java/com/codesdream/ase/service/UserService.java +++ b/src/main/java/com/codesdream/ase/service/UserService.java @@ -3,7 +3,7 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.auth.ASEPasswordEncoder; import com.codesdream.ase.component.auth.ASEUsernameEncoder; import com.codesdream.ase.component.permission.UserRolesListGenerator; -import com.codesdream.ase.exception.UserInformationIllegalException; +import com.codesdream.ase.exception.badrequest.UserInformationIllegalException; import com.codesdream.ase.exception.notfound.UserNotFoundException; import com.codesdream.ase.exception.badrequest.UsernameAlreadyExistException; import com.codesdream.ase.model.information.BaseStudentInfo; diff --git a/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java b/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java index 79a3c83..a54272c 100644 --- a/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java +++ b/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java @@ -1,8 +1,6 @@ package com.codesdream.ase.validator; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.exception.DataIllegalTableFormatException; import org.springframework.stereotype.Component; import java.util.*; diff --git a/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java b/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java index 11ef842..779f270 100644 --- a/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java +++ b/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java @@ -2,13 +2,10 @@ package com.codesdream.ase.test; import com.alibaba.fastjson.JSONObject; import com.codesdream.ase.component.ASESpringUtil; -import com.codesdream.ase.component.json.respond.JSONBaseRespondObject; import com.codesdream.ase.configure.ActivityFormConfigure; -import com.codesdream.ase.exception.InvalidFormFormatException; +import com.codesdream.ase.exception.innerservererror.InvalidFormFormatException; import com.codesdream.ase.validator.JSONFormValidator; -import com.fasterxml.jackson.databind.util.JSONPObject; import lombok.extern.slf4j.Slf4j; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest;