List of usage examples for org.springframework.web.multipart MultipartFile getSize
long getSize();
From source file:kitt.site.controller.mobile.UserController.java
/**************************************************** ??? start *********************************************/ //??,??MultipartFile??,??? @LoginRequired//from ww w .j a v a 2 s . co m @ResponseBody @RequestMapping(value = "/account/saveCompanyInfo", method = RequestMethod.POST) public Object saveCompanyInfo(Company company, @RequestParam("license") MultipartFile license, @RequestParam("tax") MultipartFile tax, @RequestParam("organization") MultipartFile organization, @RequestParam("openAccount") MultipartFile openAccount, @RequestParam("bill") MultipartFile bill, @RequestParam("operate") MultipartFile operate, String isdeleteBill, String isdeleteOperate, @CurrentUser User user) throws Exception { user = userMapper.getUserById(user.getId()); Map<String, Object> map = new HashMap<String, Object>(); boolean success = true; String errorMsg = null; int compnayCount = companyMapper.countCompanyIsExist(company.getName().trim(), user.getId()); if (compnayCount != 0) { success = false; errorMsg = "???"; } else { if (!(checkPictureInfo.doCheckPictureTypeIncludeNullFile(license) && checkPictureInfo.doCheckPictureTypeIncludeNullFile(tax) && checkPictureInfo.doCheckPictureTypeIncludeNullFile(organization) && checkPictureInfo.doCheckPictureTypeIncludeNullFile(openAccount) && checkPictureInfo.doCheckPictureTypeIncludeNullFile(bill) && checkPictureInfo.doCheckPictureTypeIncludeNullFile(operate))) { success = false; errorMsg = "? .jpg, .bmp, .png, .jpeg ?"; } else if (!(checkPictureInfo.doCheckPictureSize(license) && checkPictureInfo.doCheckPictureSize(tax) && checkPictureInfo.doCheckPictureSize(organization) && checkPictureInfo.doCheckPictureSize(openAccount) && checkPictureInfo.doCheckPictureSize(bill) && checkPictureInfo.doCheckPictureSize(operate))) { success = false; errorMsg = "??10M"; } else if (!"".equals(user.getVerifystatus())) { company.setUserid(user.getId()); if (company.getId() == 0) { String licensePath = fileService.uploadPictureToUploadDir(license); String taxPath = fileService.uploadPictureToUploadDir(tax); String organizationPath = fileService.uploadPictureToUploadDir(organization); String openAccountPath = fileService.uploadPictureToUploadDir(openAccount); String billPath = null; String operatePath = null; company.setBusinesslicense(licensePath); company.setIdentificationnumber(taxPath); company.setOrganizationcode(organizationPath); company.setOpeninglicense(openAccountPath); if (bill != null && bill.getSize() > 0) { billPath = fileService.uploadPictureToUploadDir(bill); company.setInvoicinginformation(billPath); } if (operate != null && operate.getSize() > 0) { operatePath = fileService.uploadPictureToUploadDir(operate); company.setOperatinglicense(operatePath); } companyMapper.addCompany(company); } else { Company com = companyMapper.getCompanyById(company.getId()); String licensePath = null; String taxPath = null; String organizationPath = null; String openAccountPath = null; String billPath = null; String operatePath = null; if (license != null && license.getSize() > 0) { licensePath = fileService.uploadPictureToUploadDir(license); } else { licensePath = com.getBusinesslicense(); } if (tax != null && tax.getSize() > 0) { taxPath = fileService.uploadPictureToUploadDir(tax); } else { taxPath = com.getIdentificationnumber(); } if (organization != null && organization.getSize() > 0) { organizationPath = fileService.uploadPictureToUploadDir(organization); } else { organizationPath = com.getOrganizationcode(); } if (openAccount != null && openAccount.getSize() > 0) { openAccountPath = fileService.uploadPictureToUploadDir(openAccount); } else { openAccountPath = com.getOpeninglicense(); } if (bill != null && bill.getSize() > 0) { billPath = fileService.uploadPictureToUploadDir(bill); } else { if (StringUtils.isBlank(isdeleteBill)) { billPath = com.getInvoicinginformation(); } else { billPath = null; } } if (operate != null && operate.getSize() > 0) { operatePath = fileService.uploadPictureToUploadDir(operate); } else { if (StringUtils.isBlank(isdeleteOperate)) { operatePath = com.getOperatinglicense(); } else { operatePath = null; } } company.setBusinesslicense(licensePath); company.setIdentificationnumber(taxPath); company.setOrganizationcode(organizationPath); company.setOpeninglicense(openAccountPath); company.setInvoicinginformation(billPath); company.setOperatinglicense(operatePath); companyMapper.modifyCompany(company); } companyMapper.addCompVerify(new CompanyVerify("", LocalDateTime.now(), companyMapper.getIdByUserid(user.getId()), user.getId())); companyMapper.setCompanyStatus("", null, companyMapper.getIdByUserid(user.getId())); userMapper.setUserVerifyStatus("", null, user.getId()); MessageNotice.SubmitCompany.noticeUser(user.getSecurephone()); } } map.put("success", success); map.put("errorMsg", errorMsg); return map; }
From source file:Controller.ProviderController.java
@RequestMapping(value = "/Package/editCoverImage", method = RequestMethod.POST) public @ResponseBody String editCoverImage(@RequestParam("coverImage") MultipartFile coverImage, @RequestParam("packageID") int packageID, HttpSession session) { try {/*w w w .j a v a 2 s . c om*/ String path = System.getProperty("catalina.base"); File folderPackage = new File(path + "/webapps/Images/PrimaryPackages/" + packageID); if (!folderPackage.exists()) { folderPackage.mkdirs(); } String name = "cover." + FilenameUtils.getExtension(coverImage.getOriginalFilename()); FileCopyUtils.copy(coverImage.getBytes(), new FileOutputStream(new File(folderPackage, name))); // get data from image String fileName = coverImage.getOriginalFilename(); String fileType = coverImage.getContentType(); String fileSize = coverImage.getSize() / 1024 + " Kb"; byte[] imageInByte = coverImage.getBytes(); FileMeta metaFile = new FileMeta(fileName, fileSize, fileType, imageInByte); // save temporary Image to session session.setAttribute("coverEditPackageImage", metaFile); return "/Images/PrimaryPackages/" + packageID + "/" + name; } catch (Exception e) { String content = "Function: ProviderController - uploadCoverImage\n" + "***Input***\n" + "PackageID: " + packageID + "\n" + "**********\n" + "****Error****\n" + e.getMessage() + "\n" + "**********"; errorService.logBugWithAccount(content, session, e); return "{\"result\": \"error\"}"; } }
From source file:com.siblinks.ws.service.impl.UploadEssayServiceImpl.java
/** * {@inheritDoc}/*from w w w . j a v a2 s . c o m*/ */ @Override @RequestMapping(value = "/updateEssayStudent", method = RequestMethod.POST) public ResponseEntity<Response> updateEssayStudent(@RequestParam("essayId") final String essayId, @RequestParam("desc") final String desc, @RequestParam("userId") final String userId, @RequestParam(required = false) final String fileName, @RequestParam("title") final String title, @RequestParam("schoolId") final String schoolId, @RequestParam("majorId") final String majorId, @RequestParam(required = false) final MultipartFile file) { SimpleResponse simpleResponse = null; String statusMessage = ""; try { if (!AuthenticationFilter.isAuthed(context)) { simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required."); return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN); } if (StringUtil.isNull(desc)) { statusMessage = "Essay description can't blank!"; } else { if (desc.length() > 1000) { statusMessage = "Essay description can't over 1000 characters!"; } } if (StringUtil.isNull(title)) { statusMessage = "Essay title can't blank!"; } else { if (title.length() > 250) { statusMessage = "Essay title can't over 250 characters!"; } } if (StringUtil.isNull(essayId)) { statusMessage = "EssayId null!"; } boolean msgs = false; if (StringUtil.isNull(statusMessage)) { List<Map<String, String>> allWordFilter = cachedDao.getAllWordFilter(); String strContent = CommonUtil.filterWord(desc, allWordFilter); String strTitle = CommonUtil.filterWord(title, allWordFilter); String strFileName = CommonUtil.filterWord(fileName, allWordFilter); if (validateEssay(file).equals("File is empty")) { Object[] queryParams = { strContent, strTitle, schoolId, majorId, essayId }; msgs = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_STUDENT_UPDATE_ESSAY_NOFILE, queryParams); } else { Object[] queryParams = { file.getInputStream(), strContent, file.getContentType(), strFileName, strTitle, file.getSize(), schoolId, majorId, essayId }; msgs = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_STUDENT_UPDATE_ESSAY, queryParams); } if (msgs) { statusMessage = "You updated successfull essay."; } else { statusMessage = "This essay is already not exist."; } } simpleResponse = new SimpleResponse("" + msgs, "essay", "upload", statusMessage); } catch (Exception e) { e.printStackTrace(); simpleResponse = new SimpleResponse(SibConstants.FAILURE, "essay", "upload", e.getMessage()); } return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK); }
From source file:org.gallery.web.controller.ImageController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody Map upload(MultipartHttpServletRequest request, HttpServletResponse response) throws IOException { log.info("UploadPost called..."); Iterator<String> itr = request.getFileNames(); MultipartFile mpf; List<ImageVO> list = new LinkedList<>(); while (itr.hasNext()) { mpf = request.getFile(itr.next()); String originalFilename = mpf.getOriginalFilename(); if (originalFilename == null || StringUtils.isEmpty(originalFilename)) { originalFilename = UUID.randomUUID().toString() + ".jpg"; }/* ww w. j av a 2 s .c o m*/ log.info("Uploading {}", originalFilename); String newFilenameBase = "-" + UUID.randomUUID().toString(); String storageDirectory = fileUploadDirectory; String contentType = mpf.getContentType(); if (contentType == null || StringUtils.isEmpty(contentType)) { contentType = "image/jpeg"; } String newFilename = newFilenameBase; InputStream in = null; try { // Save Images // mpf.transferTo(newFile); in = new ByteArrayInputStream(mpf.getBytes()); BufferedImage originalImage = ImageIO.read(in); // Save Original Image String filenameExtension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length()); ImageIO.write(originalImage, filenameExtension, new File(storageDirectory + File.separatorChar + originalFilename)); // Small Thumbnails BufferedImage thumbnail_small = Scalr.resize(originalImage, ThumbnailSize.SMALL_SIZE.getSize()); compressImg(thumbnail_small, new File(storageDirectory + File.separatorChar + ThumbnailSize.SMALL_SIZE.getId() + newFilenameBase + "." + ThumbnailSize.SMALL_SIZE.getFormatName()), ThumbnailSize.SMALL_SIZE.getCompressionQuality()); // Medium Thumbnail BufferedImage thumbnail_medium = Scalr.resize(originalImage, ThumbnailSize.MEDIUM_SIZE.getSize()); compressImg(thumbnail_medium, new File(storageDirectory + File.separatorChar + ThumbnailSize.MEDIUM_SIZE.getId() + newFilenameBase + "." + ThumbnailSize.MEDIUM_SIZE.getFormatName()), ThumbnailSize.MEDIUM_SIZE.getCompressionQuality()); // Big Thumbnails BufferedImage thumbnail_big = Scalr.resize(originalImage, ThumbnailSize.BIG_SIZE.getSize()); compressImg(thumbnail_big, new File(storageDirectory + File.separatorChar + ThumbnailSize.BIG_SIZE.getId() + newFilenameBase + "." + ThumbnailSize.BIG_SIZE.getFormatName()), ThumbnailSize.BIG_SIZE.getCompressionQuality()); log.info("EmotionParser..."); // ImageEntity entity = // EmotionParser.parse(ImageIO.read(newFile)); ImageEntity entity = new ImageEntity(); entity.setName(originalFilename); entity.setNewFilename(newFilename); entity.setContentType(contentType); entity.setSize(mpf.getSize()); imageDao.save(entity); ImageVO imageVO = new ImageVO(entity); imageVO.setId(entity.getId()); imageVO.setUrl("/picture/" + entity.getId()); imageVO.setThumbnailUrl("/thumbnail/" + entity.getId()); imageVO.setDeleteUrl("/delete/" + entity.getId()); imageVO.setEmotionUrl("/emotion/" + entity.getId()); imageVO.setDeleteType("DELETE"); list.add(imageVO); } catch (IOException e) { log.error("Could not upload file " + originalFilename, e); } finally { in.close(); } } Map<String, Object> files = new HashMap<>(); files.put("files", list); return files; }
From source file:Controller.ProviderController.java
@RequestMapping(value = "/Package/uploadCoverImage", method = RequestMethod.POST) public @ResponseBody String uploadCoverImage(@RequestParam("coverImage") MultipartFile coverImage, @RequestParam("temporaryPackageID") int temporaryPackageID, HttpSession session) { try {/*from ww w .j a va2s . c o m*/ String path = System.getProperty("catalina.base"); File folderPackage = new File(path + "/webapps/Images/TemporaryPackages/" + temporaryPackageID); if (!folderPackage.exists()) { folderPackage.mkdirs(); } // String name = "cover." + FilenameUtils.getExtension(coverImage.getOriginalFilename()); // FileOutputStream fos = new FileOutputStream(new File(folderPackage, name)); // fos.write(coverImage.getBytes()); // fos.close(); String name = "cover." + FilenameUtils.getExtension(coverImage.getOriginalFilename()); FileCopyUtils.copy(coverImage.getBytes(), new FileOutputStream(new File(folderPackage, name))); // get data from image String fileName = coverImage.getOriginalFilename(); String fileType = coverImage.getContentType(); String fileSize = coverImage.getSize() / 1024 + " Kb"; byte[] imageInByte = coverImage.getBytes(); FileMeta metaFile = new FileMeta(fileName, fileSize, fileType, imageInByte); // save temporary Image to session session.setAttribute("coverPackageImage", metaFile); return "/Images/TemporaryPackages/" + temporaryPackageID + "/" + name; } catch (Exception e) { String content = "Function: ProviderController - uploadCoverImage\n" + "***Input***\n" + "temporaryPackageID: " + temporaryPackageID + "\n" + "**********\n" + "****Error****\n" + e.getMessage() + "\n" + "**********"; errorService.logBugWithAccount(content, session, e); return "{\"result\": \"error\"}"; } }
From source file:com.rr.wabshs.ui.profile.profileController.java
/** * The 'saveProfileForm.do' POST will save the user profile form. * * @param session/* w w w . j ava2 s . co m*/ * @param email * @param firstName * @param lastName * @param newPassword * @param profilePhoto * @return * @throws Exception */ @RequestMapping(value = "saveProfileForm.do", method = RequestMethod.POST) public ModelAndView submitProfileForm(HttpSession session, @RequestParam(value = "updateAllEmails", required = false, defaultValue = "0") String updateAllEmails, @RequestParam String email, @RequestParam String username, @RequestParam String firstName, @RequestParam String lastName, @RequestParam String newPassword, @RequestParam(value = "profilePhoto", required = false) MultipartFile profilePhoto, @RequestParam String phoneNumber, @RequestParam Boolean privateProfile, @RequestParam(value = "selectedResources", required = false) List<Integer> selectedResources, @RequestParam(value = "calendarNotificationId", required = false) String calendarNotificationId, @RequestParam(value = "calendarnotificationEmail", required = false) String calendarnotificationEmail, @RequestParam(value = "newEventNotifications", required = false) Boolean newEventNotifications, @RequestParam(value = "modifyEventNotifications", required = false) Boolean modifyEventNotifications, @RequestParam(value = "forumNotificationId", required = false) String forumNotificationId, @RequestParam(value = "forumnotificationEmail", required = false) String forumnotificationEmail, @RequestParam(value = "newTopicsNotifications", required = false) Boolean newTopicsNotifications, @RequestParam(value = "repliesTopicsNotifications", required = false) Boolean repliesTopicsNotifications, @RequestParam(value = "myPostsNotifications", required = false) Boolean myPostsNotifications, @RequestParam(value = "documentNotificationId", required = false) String documentNotificationId, @RequestParam(value = "documentnotificationEmail", required = false) String documentnotificationEmail, @RequestParam(value = "myHierarchiesOnly", required = false) Boolean myHierarchiesOnly, @RequestParam(value = "allDocs", required = false) Boolean allDocs, @RequestParam(value = "announcementNotificationId", required = false) String announcementNotificationId, @RequestParam(value = "announcementnotificationEmail", required = false) String announcementnotificationEmail, @RequestParam(value = "announcementmyHierarchiesOnly", required = false) Boolean announcementmyHierarchiesOnly, @RequestParam(value = "allAnnouncements", required = false) Boolean allAnnouncements) throws Exception { ModelAndView mav = new ModelAndView(); mav.setViewName("/profile"); /* Get a list of completed surveys the logged in user has access to */ User userDetails = (User) session.getAttribute("userDetails"); /* Check for duplicate email address */ User existingUser = usermanager.checkDuplicateUsername(username, programId, userDetails.getId()); if (existingUser != null) { mav.addObject("existingUser", "The username is already being used by another user."); return mav; } userDetails.setFirstName(firstName); userDetails.setLastName(lastName); userDetails.setEmail(email); userDetails.setUsername(username); userDetails.setPhoneNumber(phoneNumber); userDetails.setPrivateProfile(privateProfile); if (!"".equals(newPassword)) { userDetails.setPassword(newPassword); userDetails = usermanager.encryptPW(userDetails); } if (profilePhoto != null && !"".equals(profilePhoto) && profilePhoto.getSize() > 0) { String profilePhotoFileName = usermanager.saveProfilePhoto(programId, profilePhoto, userDetails); userDetails.setProfilePhoto(profilePhotoFileName); } usermanager.updateUser(userDetails); /* Delete user resources */ usermanager.removeUserResources(userDetails.getId()); /* Save user resources */ if (selectedResources != null) { usermanager.saveUserResources(userDetails.getId(), selectedResources); } /* Check if Calendar Event Notifications need to be updated */ if (calendarNotificationId != null && !"".equals(calendarNotificationId) && Integer.parseInt(calendarNotificationId) > 0) { calendarNotificationPreferences calendarNotificationPreferences = calendarManager .getNotificationPreferences(userDetails.getId(), programId); if (calendarnotificationEmail == null || "".equals(calendarnotificationEmail) || "1".equals(updateAllEmails)) { calendarnotificationEmail = email; } calendarNotificationPreferences.setNotificationEmail(calendarnotificationEmail); if (newEventNotifications == null) { newEventNotifications = false; } calendarNotificationPreferences.setNewEventNotifications(newEventNotifications); if (modifyEventNotifications == null) { modifyEventNotifications = false; } calendarNotificationPreferences.setModifyEventNotifications(modifyEventNotifications); calendarManager.saveNotificationPreferences(calendarNotificationPreferences); } else if (calendarNotificationId != null && "".equals(calendarNotificationId)) { calendarNotificationPreferences calendarNotificationPreferences = new calendarNotificationPreferences(); calendarNotificationPreferences.setSystemUserId(userDetails.getId()); if (calendarnotificationEmail == null || "".equals(calendarnotificationEmail) || "1".equals(updateAllEmails)) { calendarnotificationEmail = email; } calendarNotificationPreferences.setNotificationEmail(calendarnotificationEmail); if (newEventNotifications == null) { newEventNotifications = false; } calendarNotificationPreferences.setNewEventNotifications(newEventNotifications); if (modifyEventNotifications == null) { modifyEventNotifications = false; } calendarNotificationPreferences.setModifyEventNotifications(modifyEventNotifications); calendarNotificationPreferences.setProgramId(programId); calendarManager.saveNotificationPreferences(calendarNotificationPreferences); } /* Check if Forum Notifications need to be updated */ if (forumNotificationId != null && !"".equals(forumNotificationId) && Integer.parseInt(forumNotificationId) > 0) { forumNotificationPreferences forumNotificationPreferences = forumManager .getNotificationPreferences(userDetails.getId(), programId); if (forumnotificationEmail == null || "".equals(forumnotificationEmail) || "1".equals(updateAllEmails)) { forumnotificationEmail = email; } forumNotificationPreferences.setNotificationEmail(forumnotificationEmail); if (newTopicsNotifications == null) { newTopicsNotifications = false; } forumNotificationPreferences.setNewTopicsNotifications(newTopicsNotifications); if (repliesTopicsNotifications == null) { repliesTopicsNotifications = false; } forumNotificationPreferences.setRepliesTopicsNotifications(repliesTopicsNotifications); if (myPostsNotifications == null) { myPostsNotifications = false; } forumNotificationPreferences.setMyPostsNotifications(myPostsNotifications); forumManager.saveNotificationPreferences(forumNotificationPreferences); } else if (forumNotificationId != null && "".equals(forumNotificationId)) { forumNotificationPreferences forumNotificationPreferences = new forumNotificationPreferences(); forumNotificationPreferences.setSystemUserId(userDetails.getId()); forumNotificationPreferences.setProgramId(programId); if (forumnotificationEmail == null || "".equals(forumnotificationEmail) || "1".equals(updateAllEmails)) { forumnotificationEmail = email; } forumNotificationPreferences.setNotificationEmail(forumnotificationEmail); if (newTopicsNotifications == null) { newTopicsNotifications = false; } forumNotificationPreferences.setNewTopicsNotifications(newTopicsNotifications); if (repliesTopicsNotifications == null) { repliesTopicsNotifications = false; } forumNotificationPreferences.setRepliesTopicsNotifications(repliesTopicsNotifications); if (myPostsNotifications == null) { myPostsNotifications = false; } forumNotificationPreferences.setMyPostsNotifications(myPostsNotifications); forumManager.saveNotificationPreferences(forumNotificationPreferences); } /* Check if Document Notifications need to be updated */ if (documentNotificationId != null && !"".equals(documentNotificationId) && Integer.parseInt(documentNotificationId) > 0) { documentNotificationPreferences documentNotificationPreferences = documentmanager .getNotificationPreferences(userDetails.getId(), programId); if (documentnotificationEmail == null || "".equals(documentnotificationEmail) || "1".equals(updateAllEmails)) { documentnotificationEmail = email; } documentNotificationPreferences.setNotificationEmail(documentnotificationEmail); if (myHierarchiesOnly == null) { myHierarchiesOnly = false; } documentNotificationPreferences.setMyHierarchiesOnly(myHierarchiesOnly); if (allDocs == null) { allDocs = false; } documentNotificationPreferences.setAllDocs(allDocs); documentmanager.saveNotificationPreferences(documentNotificationPreferences); } else if (documentNotificationId != null && "".equals(documentNotificationId)) { documentNotificationPreferences documentNotificationPreferences = new documentNotificationPreferences(); documentNotificationPreferences.setProgramId(programId); documentNotificationPreferences.setSystemUserId(userDetails.getId()); if (documentnotificationEmail == null || "".equals(documentnotificationEmail) || "1".equals(updateAllEmails)) { documentnotificationEmail = email; } documentNotificationPreferences.setNotificationEmail(documentnotificationEmail); if (myHierarchiesOnly == null) { myHierarchiesOnly = false; } documentNotificationPreferences.setMyHierarchiesOnly(myHierarchiesOnly); if (allDocs == null) { allDocs = false; } documentNotificationPreferences.setAllDocs(allDocs); documentmanager.saveNotificationPreferences(documentNotificationPreferences); } /* Check if Announcement Notifications need to be updated */ if (announcementNotificationId != null && !"".equals(announcementNotificationId) && Integer.parseInt(announcementNotificationId) > 0) { announcementNotificationPreferences announcementNotificationPreferences = announcementmanager .getNotificationPreferences(userDetails.getId(), programId); if (announcementnotificationEmail == null || "".equals(announcementnotificationEmail) || "1".equals(updateAllEmails)) { announcementnotificationEmail = email; } announcementNotificationPreferences.setNotificationEmail(announcementnotificationEmail); if (announcementmyHierarchiesOnly == null) { announcementmyHierarchiesOnly = false; } announcementNotificationPreferences.setMyHierarchiesOnly(announcementmyHierarchiesOnly); if (allAnnouncements == null) { allAnnouncements = false; } announcementNotificationPreferences.setAllAnnouncements(allAnnouncements); announcementmanager.saveNotificationPreferences(announcementNotificationPreferences); } else if (announcementNotificationId != null && "".equals(announcementNotificationId)) { announcementNotificationPreferences announcementNotificationPreferences = new announcementNotificationPreferences(); announcementNotificationPreferences.setProgramId(programId); announcementNotificationPreferences.setSystemUserId(userDetails.getId()); if (announcementnotificationEmail == null || "".equals(announcementnotificationEmail) || "1".equals(updateAllEmails)) { announcementnotificationEmail = email; } announcementNotificationPreferences.setNotificationEmail(announcementnotificationEmail); if (announcementmyHierarchiesOnly == null) { announcementmyHierarchiesOnly = false; } announcementNotificationPreferences.setMyHierarchiesOnly(announcementmyHierarchiesOnly); if (allAnnouncements == null) { allAnnouncements = false; } announcementNotificationPreferences.setAllAnnouncements(allAnnouncements); announcementmanager.saveNotificationPreferences(announcementNotificationPreferences); } mav.addObject("savedStatus", "updated"); /* Get a list of user resources */ List<Integer> userResources = usermanager.getUserResources(userDetails.getId()); boolean showSkillSets = false; boolean showCalendarNotifications = false; boolean showForumNotifications = false; boolean showDocumentNotifications = false; boolean showAnnouncementNotifications = false; if (session.getAttribute("availModules") != null) { String[][] modules = (String[][]) session.getAttribute("availModules"); for (String[] module : modules) { Integer moduleId = Integer.valueOf(module[3]); if (null != moduleId) switch (moduleId) { case 13: List<programResources> programResources = resourceManager.getResources(programId); if ((programResources != null && programResources.size() > 0) && (userResources != null && userResources.size() > 0)) { for (programResources resource : programResources) { for (Integer userResource : userResources) { if (userResource == resource.getId()) { resource.setSelected(true); } } } } mav.addObject("programResources", programResources); showSkillSets = true; break; case 7: calendarNotificationPreferences calendarNotificationPreferences = calendarManager .getNotificationPreferences(userDetails.getId(), programId); mav.addObject("calendarNotificationPreferences", calendarNotificationPreferences); showCalendarNotifications = true; break; case 9: forumNotificationPreferences forumNotificationPreferences = forumManager .getNotificationPreferences(userDetails.getId(), programId); mav.addObject("forumNotificationPreferences", forumNotificationPreferences); showForumNotifications = true; break; case 10: documentNotificationPreferences documentNotificationPreferences = documentmanager .getNotificationPreferences(userDetails.getId(), programId); mav.addObject("documentNotificationPreferences", documentNotificationPreferences); showDocumentNotifications = true; break; case 14: announcementNotificationPreferences announcementNotificationPreferences = announcementmanager .getNotificationPreferences(userDetails.getId(), programId); mav.addObject("announcementNotificationPreferences", announcementNotificationPreferences); showAnnouncementNotifications = true; break; default: break; } } } mav.addObject("showSkillSets", showSkillSets); mav.addObject("showCalendarNotifications", showCalendarNotifications); mav.addObject("showForumNotifications", showForumNotifications); mav.addObject("showDocumentNotifications", showDocumentNotifications); mav.addObject("showAnnouncementNotifications", showAnnouncementNotifications); return mav; }
From source file:com.siblinks.ws.service.impl.UploadEssayServiceImpl.java
/** * {@inheritDoc}/*www . ja va 2 s .c o m*/ */ @Override @RequestMapping(value = "/insertUpdateCommentEssay", method = RequestMethod.POST) public ResponseEntity<Response> insertUpdateCommentEssay( @RequestParam(required = false) final MultipartFile file, @RequestParam final long essayId, @RequestParam final long mentorId, @RequestParam(required = false) final Long studentId, @RequestParam final String comment, @RequestParam(required = false) final Long commentId, @RequestParam(required = false) final String fileOld, @RequestParam final boolean isUpdate) { SimpleResponse reponse = null; TransactionStatus status = null; try { if (comment != null && comment.length() > 1000) { reponse = new SimpleResponse(SibConstants.FAILURE, "essay", "insertCommentEssay", "Content can not longer than 1000 characters"); } else { boolean flag = false; Object[] params = null; TransactionDefinition def = new DefaultTransactionDefinition(); status = transactionManager.getTransaction(def); String statusMsg = validateEssay(file); if (statusMsg.equals("Error Format")) { reponse = new SimpleResponse(SibConstants.FAILURE, "essay", "insertCommentEssay", "Your file is not valid."); } else if (statusMsg.equals("File over 10M")) { reponse = new SimpleResponse(SibConstants.FAILURE, "essay", "insertCommentEssay", "Your file is lager than 10MB."); } else if (statusMsg.equals("File name is not valid")) { reponse = new SimpleResponse(SibConstants.FAILURE, "essay", "insertCommentEssay", "File name is not valid."); } else { // Word filter content List<Map<String, String>> allWordFilter = cachedDao.getAllWordFilter(); String strContent = CommonUtil.filterWord(comment, allWordFilter); String strFileName = CommonUtil.filterWord((file != null) ? file.getOriginalFilename() : null, allWordFilter); if (!isUpdate) { params = new Object[] { "", mentorId, strContent }; long cid = dao.insertObject(SibConstants.SqlMapper.SQL_SIB_ADD_COMMENT, params); params = new Object[] { essayId, cid }; flag = dao.insertUpdateObject(SibConstants.SqlMapperBROT163.SQL_INSERT_COMMENT_ESSAY_FK, params); if (StringUtil.isNull(statusMsg)) { params = new Object[] { mentorId, file.getInputStream(), file.getSize(), strFileName, essayId }; flag = dao.insertUpdateObject( SibConstants.SqlMapperBROT163.SQL_INSERT_COMMENT_ESSAY_WITH_FILE, params); } else { params = new Object[] { mentorId, essayId }; flag = dao.insertUpdateObject( SibConstants.SqlMapperBROT163.SQL_INSERT_COMMENT_ESSAY_WITHOUT_FILE, params); } if (flag) { String contentNofi = strContent; if (!StringUtil.isNull(strContent) && strContent.length() > Parameters.MAX_LENGTH_TO_NOFICATION) { contentNofi = strContent.substring(0, Parameters.MAX_LENGTH_TO_NOFICATION); } Object[] queryParamsIns3 = { mentorId, studentId, SibConstants.NOTIFICATION_TYPE_REPLY_ESSAY, SibConstants.NOTIFICATION_TITLE_REPLY_ESSAY, contentNofi, null, essayId }; dao.insertUpdateObject(SibConstants.SqlMapper.SQL_CREATE_NOTIFICATION, queryParamsIns3); // send message fire base String toTokenId = userservice.getTokenUser(String.valueOf(studentId)); if (!StringUtil.isNull(toTokenId)) { fireBaseNotification.sendMessage(toTokenId, SibConstants.NOTIFICATION_TITLE_REPLY_ESSAY, SibConstants.TYPE_VIDEO, String.valueOf(essayId), contentNofi, SibConstants.NOTIFICATION_ICON, SibConstants.NOTIFICATION_PRIPORITY_HIGH); } activiLogService.insertActivityLog(new ActivityLogData(SibConstants.TYPE_ESSAY, "C", "You replied an essay", String.valueOf(mentorId), String.valueOf(essayId))); } else { transactionManager.rollback(status); reponse = new SimpleResponse(SibConstants.FAILURE, "essay", "insertComstrContentay", "Failed"); } } else { params = new Object[] { strContent, commentId }; dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_EDIT_COMMENT, params); if (StringUtil.isNull(statusMsg)) { params = new Object[] { mentorId, file.getInputStream(), file.getSize(), strFileName, essayId }; dao.insertUpdateObject(SibConstants.SqlMapperBROT163.SQL_INSERT_COMMENT_ESSAY_WITH_FILE, params); } else { if (fileOld == null || fileOld.equals("null")) { params = new Object[] { mentorId, essayId }; flag = dao.insertUpdateObject( SibConstants.SqlMapperBROT163.SQL_INSERT_COMMENT_ESSAY_WITHOUT_FILE, params); } } } transactionManager.commit(status); reponse = new SimpleResponse(SibConstants.SUCCESS, "essay", "insertCommentEssay", "Success"); } } } catch (Exception e) { e.printStackTrace(); if (status != null) { transactionManager.rollback(status); } reponse = new SimpleResponse(SibConstants.FAILURE, "essay", "insertCommentEssay", e.getMessage()); } return new ResponseEntity<Response>(reponse, HttpStatus.OK); }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping("/fileUploadX.do") public void fileUploadX(HttpServletRequest request, HttpServletResponse response, SessionStatus status) throws Exception { //System.out.println(" ? uuid--"+request.getParameter("uuid")); String chkType = request.getHeader("Content-Type"); if (chkType == null) { return;// w w w. ja v a 2 s. c o m } request.setCharacterEncoding("utf-8"); String contextRealPath = request.getSession().getServletContext().getRealPath("/"); String PATH = request.getParameter("PATH"); String savePath = contextRealPath + PATH; // System.out.println("savePath------@@-----"+savePath); // int maxSize = 500 * 1024 * 1024; // ? ? 500MB() PlatformData resData = new PlatformData(); VariableList resVarList = resData.getVariableList(); String sMsg = " A "; try { MultipartHttpServletRequest msReq = (MultipartHttpServletRequest) request; Iterator<String> filesd = msReq.getFileNames(); String dir = request.getRealPath("images/egovframework/board_img"); while (filesd.hasNext()) { sMsg += "D "; //String name = (String)files.nextElement(); String name = filesd.next(); // System.out.println("? ^^-----"+name); MultipartFile mfile = msReq.getFile(name); //? String genId = UUID.randomUUID().toString(); //? String originalFileName = mfile.getOriginalFilename(); //? String saveFileName = genId; // System.out.println("???="+ originalFileName); System.out.println("??=" + saveFileName); String savePathh = dir + "/" + saveFileName; mfile.transferTo(new File(savePathh)); System.out.println(name + "??"); System.out.println("? ?-" + genId); //?? SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) mfile.getSize()); vo.setiUrl(savePathh); vo.setiUuid(request.getParameter("uuid")); sampleService.uploadImg(vo); status.setComplete(); } resVarList.add("ErrorCode", 200); resVarList.add("ErrorMsg", "SUCC"); } catch (Exception e) { resVarList.add("ErrorCode", 500); resVarList.add("ErrorMsg", sMsg + " " + e); } HttpPlatformResponse res = new HttpPlatformResponse(response); res.setData(resData); res.sendData(); }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping("/fileUploadX2.do") public void fileUploadX2(HttpServletRequest request, HttpServletResponse response, SessionStatus status) throws Exception { //System.out.println(" ? uuid--"+request.getParameter("uuid")); String chkType = request.getHeader("Content-Type"); if (chkType == null) { return;/*from ww w . java 2 s. c o m*/ } request.setCharacterEncoding("utf-8"); String contextRealPath = request.getSession().getServletContext().getRealPath("/"); String PATH = request.getParameter("PATH"); String savePath = contextRealPath + PATH; // System.out.println("savePath------@@-----"+savePath); // int maxSize = 500 * 1024 * 1024; // ? ? 500MB() PlatformData resData = new PlatformData(); VariableList resVarList = resData.getVariableList(); String sMsg = " A "; try { MultipartHttpServletRequest msReq = (MultipartHttpServletRequest) request; Iterator<String> filesd = msReq.getFileNames(); String dir = request.getRealPath("images/egovframework/board_img"); while (filesd.hasNext()) { sMsg += "D "; //String name = (String)files.nextElement(); String name = filesd.next(); // System.out.println("? ^^-----"+name); MultipartFile mfile = msReq.getFile(name); //? String genId = UUID.randomUUID().toString(); //? String originalFileName = mfile.getOriginalFilename(); //? String saveFileName = genId; // System.out.println("???="+ originalFileName); System.out.println("??=" + saveFileName); String savePathh = dir + "/" + saveFileName; mfile.transferTo(new File(savePathh)); System.out.println(name + "??"); System.out.println("? ?-" + genId); //?? SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) mfile.getSize()); vo.setiUrl(savePathh); vo.setiUuid("thumbnail"); sampleService.uploadImg(vo); //? ? //updateThumbnail Product pVO = new Product(); pVO.setP_uuid(request.getParameter("uuid")); System.out.println(" uuid-" + request.getParameter("uuid")); String thumbnail = "http://localhost:8778/sample/images/egovframework/board_img/" + saveFileName; pVO.setP_thumbnail(thumbnail); sampleService.updateThumbnail(pVO); status.setComplete(); } resVarList.add("ErrorCode", 200); resVarList.add("ErrorMsg", "SUCC"); } catch (Exception e) { resVarList.add("ErrorCode", 500); resVarList.add("ErrorMsg", sMsg + " " + e); } HttpPlatformResponse res = new HttpPlatformResponse(response); res.setData(resData); res.sendData(); }