Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. public Action modifyEventAction(String bevUid, String bactUid, ActionBase body){
  2. BmobVUserRegionMacroregionCity regionalData = null;
  3. BmobEvent event;
  4. BmobAction action;
  5. try{
  6.  
  7. try {
  8. if (!UserUtils.currentUserHasAuthority("BAEVENTADMIN")) {
  9. regionalData = userService.getUserRegion(UserUtils.getUser().getUserId());
  10. }
  11. } catch (Exception e){
  12. throw new ApiException(500, "-52500", "statMessgInternalError");
  13. }
  14.  
  15. try {
  16. event = bmobEventRepository.findByBevUidAndActAndStRrd(bevUid, ZUtils.BOOLEAN_SHORT_TRUE, ZUtils.BOOLEAN_SHORT_TRUE);
  17. } catch (Exception e){
  18. throw new ApiException(500, "-58500", "statMessgInternalError");
  19. }
  20. if(event == null){
  21. throw new ApiException(400, "batadm-5400", "batadmNotFindEvent");
  22. }
  23. if (event.getStatus() == 3) {
  24. throw new ApiException(400, "batadm-8400", "batadmEventFinished");
  25. }
  26.  
  27. try {
  28. action = bmobActionRepository.findByBactUidAndActAndStRrd(bactUid, ZUtils.BOOLEAN_SHORT_TRUE, ZUtils.BOOLEAN_SHORT_TRUE);
  29. } catch (Exception e){
  30. throw new ApiException(500, "-59500", "statMessgInternalError");
  31. }
  32. if(action == null){
  33. throw new ApiException(400, "batadm-6400", "batadmNotFindAction");
  34. }
  35. if (action.getStatus() != 1 && action.getStatus() != 4) {
  36. throw new ApiException(400, "batadm-9400", "batadmActionCannotModify");
  37. }
  38.  
  39. if(action.getBevBevId().getBevId() != event.getBevId()){
  40. throw new ApiException(404, "batadm-error", "statMessgNotFound");
  41. }
  42.  
  43. validateModifyEventAction(body, bevUid, regionalData);
  44.  
  45. try{
  46. action = updateEventAction(action,body);
  47. } catch (Exception e){
  48. throw new ApiException(500, "-53500", "statMessgInternalError" );
  49. }
  50.  
  51. bmobActionRepository.save(action);
  52.  
  53. return ActionConverter.convertToAction(action);
  54.  
  55. }catch (ApiException ae){
  56. throw ae;
  57. } catch(Exception e){
  58. log.error("Internal error", e);
  59. throw new ApiException(500, "-50500", "statInternalMessgError");
  60. }
  61. }
  62.  
  63. private void validateModifyEventAction(ActionBase object, String bevUid, BmobVUserRegionMacroregionCity regionalData){
  64. List<ErrorMsg> errors = new ArrayList<>();
  65.  
  66. Date startDate = null;
  67. LocalTime startHour = null;
  68. LocalTime finishedHour = null;
  69. if (object.getStartDate() != null) {
  70. try {
  71. startDate = ISO8601Utils.parse(object.getStartDate(), new ParsePosition((0)));
  72. } catch (Exception ex) {
  73. errors.add(new ErrorMsg("batadm-val-2400", "err.batadm.cea.val.2400",
  74. new String[]{"startDate"}, ErrorMsg.ErrorType.ERROR));
  75. }
  76. } else {
  77. errors.add(new ErrorMsg("batadm-val-2400", "err.batadm.cea.val.2400",
  78. new String[]{"startDate"}, ErrorMsg.ErrorType.ERROR));
  79. }
  80.  
  81. if (object.getStartHour() != null) {
  82. try {
  83. startHour = LocalTime.parse(object.getStartHour());
  84. } catch (Exception ex) {
  85. errors.add(new ErrorMsg("batadm-val-3400", "err.batadm.cea.val.3400",
  86. new String[]{"startHour"}, ErrorMsg.ErrorType.ERROR));
  87. }
  88. } else {
  89. errors.add(new ErrorMsg("batadm-val-3400", "err.batadm.cea.val.3400",
  90. new String[]{"startHour"}, ErrorMsg.ErrorType.ERROR));
  91. }
  92.  
  93. if (object.getFinishHour() != null) {
  94. try {
  95. finishedHour = LocalTime.parse(object.getFinishHour());
  96. } catch (Exception ex) {
  97. errors.add(new ErrorMsg("batadm-val-4400", "err.batadm.cea.val.4400",
  98. new String[]{"finishedHour"}, ErrorMsg.ErrorType.ERROR));
  99. }
  100. } else {
  101. errors.add(new ErrorMsg("batadm-val-4400", "err.batadm.cea.val.4400",
  102. new String[]{"finishedHour"}, ErrorMsg.ErrorType.ERROR));
  103. }
  104.  
  105. if(!UserUtils.currentUserHasAuthority("BAEVENTADMIN")){
  106. if(regionalData.getBmrBmrId() != object.getBmrBmrId()){
  107. errors.add(new ErrorMsg("batadm-val-10400", "err.batadm.mea.val.10400",
  108. new String[]{"bmrBmrId"}, ErrorMsg.ErrorType.ERROR));
  109. }
  110. }
  111.  
  112. if (!errors.isEmpty()) {
  113. throw new ApiException(400, "batadm-40400", "batAdmValError", errors);
  114. }
  115.  
  116. }
  117.  
  118. private BmobAction updateEventAction(BmobAction action, ActionBase body) {
  119. try {
  120. action.setStartDate(ISO8601Utils.parse(body.getStartDate(), new ParsePosition((0))));
  121. action.setStartHour(body.getStartHour());
  122. action.setFinishedHour(body.getFinishHour());
  123. action.setModifyBy(UserUtils.getUser().getUserId());
  124. action.setModifyDate(Calendar.getInstance().getTime());
  125. }catch (ParseException ex) {
  126. log.error("Error parse ", ex);
  127. }
  128. return action;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement