Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Action modifyEventAction(String bevUid, String bactUid, ActionBase body){
- BmobVUserRegionMacroregionCity regionalData = null;
- BmobEvent event;
- BmobAction action;
- try{
- try {
- if (!UserUtils.currentUserHasAuthority("BAEVENTADMIN")) {
- regionalData = userService.getUserRegion(UserUtils.getUser().getUserId());
- }
- } catch (Exception e){
- throw new ApiException(500, "-52500", "statMessgInternalError");
- }
- try {
- event = bmobEventRepository.findByBevUidAndActAndStRrd(bevUid, ZUtils.BOOLEAN_SHORT_TRUE, ZUtils.BOOLEAN_SHORT_TRUE);
- } catch (Exception e){
- throw new ApiException(500, "-58500", "statMessgInternalError");
- }
- if(event == null){
- throw new ApiException(400, "batadm-5400", "batadmNotFindEvent");
- }
- if (event.getStatus() == 3) {
- throw new ApiException(400, "batadm-8400", "batadmEventFinished");
- }
- try {
- action = bmobActionRepository.findByBactUidAndActAndStRrd(bactUid, ZUtils.BOOLEAN_SHORT_TRUE, ZUtils.BOOLEAN_SHORT_TRUE);
- } catch (Exception e){
- throw new ApiException(500, "-59500", "statMessgInternalError");
- }
- if(action == null){
- throw new ApiException(400, "batadm-6400", "batadmNotFindAction");
- }
- if (action.getStatus() != 1 && action.getStatus() != 4) {
- throw new ApiException(400, "batadm-9400", "batadmActionCannotModify");
- }
- if(action.getBevBevId().getBevId() != event.getBevId()){
- throw new ApiException(404, "batadm-error", "statMessgNotFound");
- }
- validateModifyEventAction(body, bevUid, regionalData);
- try{
- action = updateEventAction(action,body);
- } catch (Exception e){
- throw new ApiException(500, "-53500", "statMessgInternalError" );
- }
- bmobActionRepository.save(action);
- return ActionConverter.convertToAction(action);
- }catch (ApiException ae){
- throw ae;
- } catch(Exception e){
- log.error("Internal error", e);
- throw new ApiException(500, "-50500", "statInternalMessgError");
- }
- }
- private void validateModifyEventAction(ActionBase object, String bevUid, BmobVUserRegionMacroregionCity regionalData){
- List<ErrorMsg> errors = new ArrayList<>();
- Date startDate = null;
- LocalTime startHour = null;
- LocalTime finishedHour = null;
- if (object.getStartDate() != null) {
- try {
- startDate = ISO8601Utils.parse(object.getStartDate(), new ParsePosition((0)));
- } catch (Exception ex) {
- errors.add(new ErrorMsg("batadm-val-2400", "err.batadm.cea.val.2400",
- new String[]{"startDate"}, ErrorMsg.ErrorType.ERROR));
- }
- } else {
- errors.add(new ErrorMsg("batadm-val-2400", "err.batadm.cea.val.2400",
- new String[]{"startDate"}, ErrorMsg.ErrorType.ERROR));
- }
- if (object.getStartHour() != null) {
- try {
- startHour = LocalTime.parse(object.getStartHour());
- } catch (Exception ex) {
- errors.add(new ErrorMsg("batadm-val-3400", "err.batadm.cea.val.3400",
- new String[]{"startHour"}, ErrorMsg.ErrorType.ERROR));
- }
- } else {
- errors.add(new ErrorMsg("batadm-val-3400", "err.batadm.cea.val.3400",
- new String[]{"startHour"}, ErrorMsg.ErrorType.ERROR));
- }
- if (object.getFinishHour() != null) {
- try {
- finishedHour = LocalTime.parse(object.getFinishHour());
- } catch (Exception ex) {
- errors.add(new ErrorMsg("batadm-val-4400", "err.batadm.cea.val.4400",
- new String[]{"finishedHour"}, ErrorMsg.ErrorType.ERROR));
- }
- } else {
- errors.add(new ErrorMsg("batadm-val-4400", "err.batadm.cea.val.4400",
- new String[]{"finishedHour"}, ErrorMsg.ErrorType.ERROR));
- }
- if(!UserUtils.currentUserHasAuthority("BAEVENTADMIN")){
- if(regionalData.getBmrBmrId() != object.getBmrBmrId()){
- errors.add(new ErrorMsg("batadm-val-10400", "err.batadm.mea.val.10400",
- new String[]{"bmrBmrId"}, ErrorMsg.ErrorType.ERROR));
- }
- }
- if (!errors.isEmpty()) {
- throw new ApiException(400, "batadm-40400", "batAdmValError", errors);
- }
- }
- private BmobAction updateEventAction(BmobAction action, ActionBase body) {
- try {
- action.setStartDate(ISO8601Utils.parse(body.getStartDate(), new ParsePosition((0))));
- action.setStartHour(body.getStartHour());
- action.setFinishedHour(body.getFinishHour());
- action.setModifyBy(UserUtils.getUser().getUserId());
- action.setModifyDate(Calendar.getInstance().getTime());
- }catch (ParseException ex) {
- log.error("Error parse ", ex);
- }
- return action;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement