From 3181288755ebf533f5a20f97751bc8e7832980ab Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 25 Mar 2020 02:07:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B4=BB=E5=8A=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=AD=90=E7=B3=BB=E7=BB=9F=E7=9A=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/activity/ActivityConverter.java | 28 +++++++++---------- .../exception/DataInvalidFormatException.java | 4 +++ .../codesdream/ase/model/activity/Period.java | 4 +++ 3 files changed, 22 insertions(+), 14 deletions(-) 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 e3f0d18..67c90b9 100644 --- a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java +++ b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java @@ -44,14 +44,14 @@ public class ActivityConverter { JSONObject jsonObject = json.get(); String username = (String) jsonObject.get("creator"); - User creator = userService.findUserByUsername(username); - activity.setCreator(creator); + Optional creator = userService.findUserByUsername(username); + activity.setCreator(creator.get()); List participateGroupFromJson = (List) jsonObject.get("participate-group"); Set participateGroup = new HashSet<>(); for (String name : participateGroupFromJson) { - User user = userService.findUserByUsername(name); - participateGroup.add(user); + Optional user = userService.findUserByUsername(name); + participateGroup.add(user.get()); } activity.setParticipateGroup(participateGroup); @@ -59,14 +59,14 @@ public class ActivityConverter { activity.setTitle(title); String chiefManagerName = (String) jsonObject.get("chief-manager"); - User chiefManager = userService.findUserByUsername(chiefManagerName); - activity.setChiefManager(chiefManager); + Optional chiefManager = userService.findUserByUsername(chiefManagerName); + activity.setChiefManager(chiefManager.get()); List assistManagerFromJSON = (List) jsonObject.get("assist-manager"); Set assistManager = new HashSet<>(); for (String name : assistManagerFromJSON) { - User user = userService.findUserByUsername(name); - assistManager.add(user); + Optional user = userService.findUserByUsername(name); + assistManager.add(user.get()); } activity.setAssistManagers(assistManager); @@ -91,24 +91,24 @@ public class ActivityConverter { List signGroupFromJSON = (List) jsonObject.get("sign-group"); Set signGroup = new HashSet<>(); for (String name : signGroupFromJSON) { - User user = userService.findUserByUsername(name); - signGroup.add(user); + Optional user = userService.findUserByUsername(name); + signGroup.add(user.get()); } activity.setSignGroup(signGroup); List informGroupFromJSON = (List) jsonObject.get("inform-group"); Set informGroup = new HashSet<>(); for (String name : informGroupFromJSON) { - User user = userService.findUserByUsername(name); - informGroup.add(user); + Optional user = userService.findUserByUsername(name); + informGroup.add(user.get()); } activity.setInformGroup(informGroup); List visibleGroupFromJSON = (List) jsonObject.get("visible-group"); Set visibleGroup = new HashSet<>(); for (String name : visibleGroupFromJSON) { - User user = userService.findUserByUsername(name); - visibleGroup.add(user); + Optional user = userService.findUserByUsername(name); + visibleGroup.add(user.get()); } activity.setVisibleGroup(informGroup); diff --git a/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java b/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java index e06394f..b5d4de5 100644 --- a/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java +++ b/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java @@ -12,4 +12,8 @@ public class DataInvalidFormatException extends RuntimeException { super(); information = e.getMessage(); } + + public DataInvalidFormatException(){ + super(); + } } diff --git a/src/main/java/com/codesdream/ase/model/activity/Period.java b/src/main/java/com/codesdream/ase/model/activity/Period.java index 8064ffc..ae359f7 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Period.java +++ b/src/main/java/com/codesdream/ase/model/activity/Period.java @@ -34,4 +34,8 @@ public class Period { this.endTime = endTime; } + public Period(){ + + } + }