Java tutorial
/* * Copyright (C) 2014-2016 Kagucho <kagucho.net@gmail.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tsuboneSystem.action.admin; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.servlet.ServletContext; import org.apache.commons.lang3.RandomStringUtils; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.seasar.struts.annotation.ActionForm; import org.seasar.struts.annotation.Execute; import org.seasar.struts.util.ServletContextUtil; import org.seasar.struts.util.UploadUtil; import tsuboneSystem.code.FileKindCode; import tsuboneSystem.code.ImageFilePurposeCode; import tsuboneSystem.code.LeadersKindCode; import tsuboneSystem.code.MailBrowsingRightsCode; import tsuboneSystem.dto.LoginMemberDto; import tsuboneSystem.entity.TAdmin; import tsuboneSystem.entity.TImageUpload; import tsuboneSystem.entity.TMember; import tsuboneSystem.entity.TTempLogin; import tsuboneSystem.form.SettingsEditForm; import tsuboneSystem.original.util.DigestUtil; import tsuboneSystem.original.util.MailManagerUtil; import tsuboneSystem.original.util.TsuboneSystemUtil; import tsuboneSystem.service.TAdminService; import tsuboneSystem.service.TImageUploadService; import tsuboneSystem.service.TMailSendMemberService; import tsuboneSystem.service.TMailService; import tsuboneSystem.service.TMemberService; import tsuboneSystem.service.TTempLoginService; public class SettingsEditAction { public String actionName = "Settings"; /** */ @ActionForm @Resource public SettingsEditForm settingsEditForm; /** LoginMemberDto */ @Resource public LoginMemberDto loginMemberDto; /** TMember? */ @Resource protected TMemberService tMemberService; /** TAdminService? */ @Resource protected TAdminService tAdminService; /** TTempLoginService? */ @Resource protected TTempLoginService tTempLoginService; /** TMail? */ @Resource protected TMailService tMailService; /** TMailSendMemberService? */ @Resource protected TMailSendMemberService tMailSendMemberService; /** TImageUploadService? */ @Resource protected TImageUploadService tImageUploadService; /**--------------- ? -----------**/ /** ? **/ @Execute(validator = false) public String tempMemberInput() { return viewinput(); } @Execute(validator = false) public String viewinput() { settingsEditForm.tTempLoginNow = tTempLoginService.findAll(); return "tempMemberInput.jsp"; } /** ?? **/ @Execute(validator = true, validate = "validateBase", input = "viewinput", stopOnValidationError = false) public String tempMemberConfirm() { //????? String rdn = RandomStringUtils.randomAlphabetic(8); settingsEditForm.password = rdn; return "tempMemberConfirm.jsp"; } /** ? **/ @Execute(validator = false) public String tempMemberComplete() { //???? List<TTempLogin> tTempLoginsListOld = tTempLoginService.findAll(); for (TTempLogin one : tTempLoginsListOld) { tTempLoginService.delete(one); } //?? TTempLogin tTempLogin = new TTempLogin(); tTempLogin.userName = settingsEditForm.userName; tTempLogin.password = DigestUtil.md5(settingsEditForm.password); tTempLoginService.insert(tTempLogin); //???????web???? List<TAdmin> tAdminList = tAdminService.findByKind(LeadersKindCode.WEBADMIN.getCode()); List<TMember> tMemberSendList = new ArrayList<TMember>(); for (TAdmin tAdmin : tAdminList) { tMemberSendList.add(tAdmin.tMember); } //???? String title = new String(); String content = new String(); title = "ID???????"; StringBuffer buf = new StringBuffer(); buf.append( "ID????????????????????????"); buf.append("\n"); buf.append(""); buf.append(loginMemberDto.tMemberLogin.hname); buf.append("\n"); buf.append("\n"); buf.append("ID"); buf.append(tTempLogin.userName); buf.append("\n"); buf.append("Password"); buf.append(settingsEditForm.password); buf.append("\n"); buf.append("\n"); content = new String(buf); //?? MailManagerUtil mailUtil = new MailManagerUtil(); mailUtil.setBrowsingRights(MailBrowsingRightsCode.ADMIN.getCodeNumber()); mailUtil.setTitle(title); mailUtil.setContent(content); mailUtil.setLinkUrlFlag(false); mailUtil.setToAddressActorSplit(tMemberSendList); mailUtil.sendMail(); return "tempMemberComplete.jsp"; } /**--------------- ? -----------**/ /** ?? **/ @Execute(validator = false) public String tempMemberDeleteConfirm() { return "tempMemberDeleteConfirm.jsp"; } /** ? **/ @Execute(validator = false) public String tempMemberDeleteComplete() { //???????? List<TTempLogin> tTempLoginList = tTempLoginService.findAll(); if (tTempLoginList.size() > 0) { for (TTempLogin one : tTempLoginList) { tTempLoginService.delete(one); } } return "tempMemberDeleteComplete.jsp"; } /**--------------- ? -----------**/ @Execute(validator = false) public String ruleUpdateInput() { return ruleUpdateView(); } @Execute(validator = false) public String ruleUpdateView() { return "ruleUpdateInput.jsp"; } @Execute(validator = true, validate = "validateUpload", input = "ruleUpdateView", stopOnValidationError = false) public String ruleUpdateComplete() { //ServletContext ?? ServletContext app = ServletContextUtil.getServletContext(); //????(DB?????????) String path = app.getRealPath("/pdf/kaisoku.pdf"); //?????????? UploadUtil.write(path, settingsEditForm.rulePdf); return "ruleUpdateComplete.jsp"; } /**-------------------- ? ----------------------------**/ @Execute(validator = false) public String topBuckImage() { settingsEditForm.tImageUploadList = new ArrayList<TImageUpload>(); settingsEditForm.tImageUploadList = tImageUploadService .findByImageFilePurposeCode(ImageFilePurposeCode.TOP_BACK.getCode()); return "topBuckImageList.jsp"; } @Execute(validator = false) public String topBuckImageRegist() { return "topBuckImageRegist.jsp"; } @Execute(validator = false, urlPattern = "topBuckImageDelete/{imageId}") public String topBuckImageDelete() { TImageUpload tImageUpload = tImageUploadService.findById(settingsEditForm.imageId); tImageUpload.deleteFlag = true; tImageUploadService.update(tImageUpload); return topBuckImage(); } //? public ActionMessages validateBase() { ActionMessages errors = new ActionMessages(); // userName??? TMember tMember = tMemberService.findByUserName(settingsEditForm.userName); TTempLogin tTempLogin = tTempLoginService.findByUserName(settingsEditForm.userName); if (tMember != null || tTempLogin != null) { errors.add("userName", new ActionMessage( "????ID?????????", false)); } return errors; } public ActionMessages validateUpload() { ActionMessages errors = new ActionMessages(); if (settingsEditForm.rulePdf.getFileSize() > 0) { String[] kinds = { FileKindCode.PDF.getName() }; if (TsuboneSystemUtil.isFileKindCheck(settingsEditForm.rulePdf, kinds)) { errors.add("rulePdf", new ActionMessage( "PDF????????????????????????", false)); } } else { errors.add("rulePdf", new ActionMessage("????????", false)); } return errors; } }