// user func @RequestMapping( value = {"/workspace/general/to-participate-in-the-event"}, method = RequestMethod.GET) public String toParticipateInTheEvent( ModelMap modelMap, @RequestParam String eventId, Principal principal) { EventEntity eventEntity = eventService.findById(eventId); UserEntity userEntity = userService.findByUsername(principal.getName()); Set<EventEntity> userEvents = userEntity.getUserEvents(); if (eventEntity.getTheCurrentNumberOfParticipants() + 1 > eventEntity.getCountParticipants()) { modelMap.addAttribute("textPage", ActionMessage.THE_EXCESS_NUMBER_OF_PARTICIPANTS); return "pages/general/success-template-page"; } else { if (null != userEvents) { userEvents.add(eventEntity); } else { userEvents = new HashSet<EventEntity>(); userEvents.add(eventEntity); } userEntity.setUserEvents(userEvents); userService.update(userEntity); try { mailService.sendEmail( MailMessageText.helloLetterRegisterOfEventHeader(eventEntity), MailMessageText.helloLetterRegisterOfEventBody(eventEntity), new String[] {userEntity.getEmail()}); } catch (MessagingException e) { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); } modelMap.addAttribute("textPage", ActionMessage.SUCCESS_EVENT_USER_REGISTRATION); return "pages/general/success-template-page"; } }
@RequestMapping( value = {"/workspace/general/list-another-application"}, method = RequestMethod.GET) public String listAnotherApplicationGeneralPage(ModelMap modelMap, Principal principal) { modelMap.addAttribute("listApplication", applicationService.applicationEntityList()); if (null != principal) { modelMap.addAttribute("userId", userService.findByUsername(principal.getName()).getIdUser()); } return "pages/general/another-application/index"; }
@RequestMapping( value = {"/workspace/user/another-application-user-list"}, method = RequestMethod.GET) public String listOfUserApplication(ModelMap modelMap, Principal principal) { modelMap.addAttribute( "listApplication", applicationService.listOfUserEvents( userService.findByUsername(principal.getName()).getIdUser())); return "pages/user/another-application/another-application-user-list"; }
@RequestMapping( value = {"/workspace/general/event-index"}, method = RequestMethod.GET) public String indexEventPage(ModelMap modelMap, Principal principal) { modelMap.addAttribute("eventList", eventService.getActualityEvents()); if (null != principal) { modelMap.addAttribute("userId", userService.findByUsername(principal.getName()).getIdUser()); } return "pages/general/event/index"; }
@RequestMapping( value = {"/workspace/general/refuse-to-participate-in-the-event"}, method = RequestMethod.GET) public String refuseToParticipateInTheEvent( ModelMap modelMap, @RequestParam String eventId, Principal principal) { EventEntity eventEntity = eventService.findById(eventId); UserEntity userEntity = userService.findByUsername(principal.getName()); Set<EventEntity> userEvents = userEntity.getUserEvents(); userEvents.remove(eventEntity); userEntity.setUserEvents(userEvents); userService.update(userEntity); try { mailService.sendEmail( MailMessageText.cancelLetterRegisterOfEventHeader(eventEntity), MailMessageText.cancelLetterRegisterOfEventBody(eventEntity), new String[] {userEntity.getEmail()}); } catch (MessagingException e) { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); } modelMap.addAttribute("textPage", ActionMessage.CANCEL_EVENT_USER_REGISTRATION); return "pages/general/success-template-page"; }
@RequestMapping( value = {"/workspace/general/find-by-type-event"}, method = RequestMethod.GET) public String findByTypeEvent( ModelMap modelMap, @RequestParam String typeOfEvent, Principal principal) { List<EventEntity> eventEntities = eventService.findByTypeEvent(typeOfEvent); if (null != typeOfEvent && null != eventEntities) { modelMap.addAttribute("eventList", eventEntities); if (null != principal) { modelMap.addAttribute( "userId", userService.findByUsername(principal.getName()).getIdUser()); } return "pages/general/event/index"; } else { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); return "pages/general/success-template-page"; } }
@RequestMapping( value = {"/workspace/user/another-application-cancel-participant"}, method = RequestMethod.GET) public String cancelAnotherApplicationToParticipate( ModelMap modelMap, Principal principal, @RequestParam String idApplication) { ApplicationEntity applicationEntity = applicationService.findById(idApplication); if (null != idApplication && null != applicationEntity) { ApplicationUserForParticipationEntity app = applicationService.cancelAnotherApplicationToParticipate( userService.findByUsername(principal.getName()).getIdUser(), idApplication); app.setStatusApplication(ProjectConstantsEnum.CANCEL_USER_REQUEST.name()); applicationUserForParticipationService.update(app); modelMap.addAttribute("textPage", ActionMessage.SUCCESS_CANCEL_REGISTER_ON_APPLICATION); return "pages/general/success-template-page"; } else { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); return "pages/general/success-template-page"; } }
@RequestMapping( value = {"/workspace/user/another-application-send-to-participate"}, method = RequestMethod.GET) public String sendAnotherApplicationToParticipate( ModelMap modelMap, @RequestParam String idApplication, Principal principal) { ApplicationEntity applicationEntity = applicationService.findById(idApplication); if (null != idApplication && null != applicationEntity) { if ("true".equals(applicationEntity.getUserAttachFile())) { modelMap.addAttribute("idApplication", idApplication); UserEntity userEntity = userService.findByUsername(principal.getName()); ApplicationUserForParticipationEntity activityApplication = applicationService.checkIsExistsActiveApplicationUserForParticipation( idApplication, userEntity, ProjectConstantsEnum.SEND_REQUEST.name()); if (null != activityApplication) { modelMap.addAttribute("activityApplication", activityApplication); } return "pages/user/another-application/another-application-send"; } else { ApplicationUserForParticipationEntity appUserForParticipationEntity = new ApplicationUserForParticipationEntity(); appUserForParticipationEntity.setIdApplication(applicationEntity.getIdApplication()); appUserForParticipationEntity.setDateAndTimeSendApplication(Utils.getTimestamp()); appUserForParticipationEntity.setIdApplicationUserForParticipation( Utils.generateIdentifier()); appUserForParticipationEntity.setIdUser( userService.findByUsername(principal.getName()).getIdUser()); appUserForParticipationEntity.setStatusApplication( ProjectConstantsEnum.APPROVED_REQUEST.name()); appUserForParticipationEntity.setApplicationEntity(applicationEntity); // applicationUserForParticipationService.save(appUserForParticipationEntity); Set<ApplicationUserForParticipationEntity> applicationUserForParticipationEntities; if (null == applicationEntity.getApplicationUserForParticipationEntities()) { applicationUserForParticipationEntities = new HashSet<ApplicationUserForParticipationEntity>(); applicationUserForParticipationEntities.add(appUserForParticipationEntity); } else { applicationUserForParticipationEntities = applicationEntity.getApplicationUserForParticipationEntities(); applicationUserForParticipationEntities.add(appUserForParticipationEntity); } applicationEntity.setApplicationUserForParticipationEntities( applicationUserForParticipationEntities); applicationService.update(applicationEntity); UserEntity userEntity = userService.findByUsername(principal.getName()); Set<ApplicationEntity> applicationEntities; if (null == userEntity.getApplicationEntities()) { applicationEntities = new HashSet<ApplicationEntity>(); applicationEntities.add(applicationEntity); } else { applicationEntities = userEntity.getApplicationEntities(); applicationEntities.add(applicationEntity); } userEntity.setApplicationEntities(applicationEntities); userService.update(userEntity); modelMap.addAttribute("textPage", ActionMessage.SUCCESS_REGISTER_ON_APPLICATION); return "pages/general/success-template-page"; } } else { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); return "pages/general/success-template-page"; } }
@RequestMapping( value = {"/workspace/user/another-application-send-to-participate-attach"}, method = RequestMethod.POST) public String singleFileUpload( @Valid final File fileBucket, BindingResult result, ModelMap modelMap, Principal principal, @RequestParam String idApp) throws IOException { ApplicationEntity applicationEntity = applicationService.findById(idApp); if (null != idApp && null != applicationEntity) { ApplicationUserForParticipationEntity appUserForParticipationEntity = new ApplicationUserForParticipationEntity(); appUserForParticipationEntity.setIdApplication(applicationEntity.getIdApplication()); appUserForParticipationEntity.setDateAndTimeSendApplication(Utils.getTimestamp()); appUserForParticipationEntity.setIdApplicationUserForParticipation( Utils.generateIdentifier()); appUserForParticipationEntity.setIdUser( userService.findByUsername(principal.getName()).getIdUser()); appUserForParticipationEntity.setStatusApplication(ProjectConstantsEnum.SEND_REQUEST.name()); appUserForParticipationEntity.setApplicationEntity(applicationEntity); // applicationUserForParticipationService.save(appUserForParticipationEntity); Set<ApplicationUserForParticipationEntity> applicationUserForParticipationEntities; if (null == applicationEntity.getApplicationUserForParticipationEntities()) { applicationUserForParticipationEntities = new HashSet<ApplicationUserForParticipationEntity>(); applicationUserForParticipationEntities.add(appUserForParticipationEntity); } else { applicationUserForParticipationEntities = applicationEntity.getApplicationUserForParticipationEntities(); applicationUserForParticipationEntities.add(appUserForParticipationEntity); } applicationEntity.setApplicationUserForParticipationEntities( applicationUserForParticipationEntities); applicationService.update(applicationEntity); UserEntity userEntity = userService.findByUsername(principal.getName()); Set<ApplicationEntity> applicationEntities; if (null == userEntity.getApplicationEntities()) { applicationEntities = new HashSet<ApplicationEntity>(); applicationEntities.add(applicationEntity); } else { applicationEntities = userEntity.getApplicationEntities(); applicationEntities.add(applicationEntity); } userEntity.setApplicationEntities(applicationEntities); DocumentEntity documentEntity = new DocumentEntity(); documentEntity.setIdDocument( appUserForParticipationEntity.getIdApplicationUserForParticipation()); documentEntity.setPathToTheFileSystem( environment.getProperty("upload.file.location") + fileBucket.getFile().getOriginalFilename()); appUserForParticipationEntity.setAttachDocumentFile(documentEntity); applicationUserForParticipationService.update(appUserForParticipationEntity); // Now do something with file... FileCopyUtils.copy( fileBucket.getFile().getBytes(), new java.io.File( environment.getProperty("upload.file.location") + fileBucket.getFile().getOriginalFilename())); userService.update(userEntity); modelMap.addAttribute("textPage", ActionMessage.SUCCESS_SEND_APPLICATION_FOR_MEMBERSHIP); return "pages/general/success-template-page"; } else { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); return "pages/general/success-template-page"; } }
@RequestMapping( value = {"/workspace/trade-union-activists/add-event"}, method = RequestMethod.POST) public String addEvents( @ModelAttribute("uploadForm") FileUploadForm uploadForm, @RequestParam String eventName, @RequestParam String typeOfEvent, @RequestParam String countParticipants, @RequestParam String dateBegin, @RequestParam String dateEnd, @RequestParam String descriptionEvent, @RequestParam String roleUser, @RequestParam String intervalsOfAMailingGroup, Principal principal, ModelMap modelMap) { TypeOfEventEntity typeOfEventEntity = eventTypeService.findById(typeOfEvent); EventEntity eventEntity = new EventEntity(); eventEntity.setRoleParticipants("[" + roleUser + "]"); eventEntity.setIdEvent(Utils.generateIdentifier()); eventEntity.setEventDescription(descriptionEvent); eventEntity.setIntervalsOfAMailingGroup(intervalsOfAMailingGroup); eventEntity.setEventName(eventName); eventEntity.setCountParticipants(new Integer(countParticipants)); eventEntity.setDateAndTimeBegin(Utils.convertStringToSqlFormatDate(dateBegin)); eventEntity.setDateAndTimeEnd(Utils.convertStringToSqlFormatDate(dateEnd)); eventEntity.setIdTypeOfEvent(typeOfEventEntity.getIdTypeOfEvent()); eventEntity.setEventStatus(eventService.checkStatusEvent(dateBegin, dateEnd)); eventEntity.setTheCurrentNumberOfParticipants(0); eventEntity.setIdOrganizer(userService.findByUsername(principal.getName()).getIdUser()); eventEntity.setEventOrganizer(userService.findByUsername(principal.getName())); Set<ImageEntity> imageEntityList = new HashSet<>(); byte fileBytes[]; FileOutputStream fos = null; List<MultipartFile> list = uploadForm.getFiles(); Set<String> filenames = new HashSet<>(); if (list != null && list.size() > 0) { for (MultipartFile multipartFile : list) { String fileName = multipartFile.getOriginalFilename(); String webappRoot = servletContext.getRealPath("/"); String relativeFolder = "/resources" + File.separator + "img" + File.separator + "files" + File.separator; String path = webappRoot + relativeFolder + fileName; if (checkFormatFileUtils.checkingForImage(fileName)) { ImageEntity imageEntity = new ImageEntity(); imageEntity.setIdImage(Utils.generateIdentifier()); imageEntity.setPathToTheFileSystem(relativeFolder + fileName); imageEntityList.add(imageEntity); } File file = new File(path); try { fos = new FileOutputStream(file); fileBytes = multipartFile.getBytes(); fos.write(fileBytes); filenames.add(fileName); } catch (IOException e) { e.printStackTrace(); } } } /*newsEntity.setNewsDocuments(documentEntities);*/ eventEntity.setEventImages(imageEntityList); eventService.save(eventEntity); modelMap.addAttribute("textPage", ActionMessage.SUCCESS_EVENT_REGISTER); return "pages/general/success-template-page"; }