package csts.bookstationery.service.entitlement;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.Set;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import csts.bookstationery.service.appconfig.AppConfiguration.AppCfgKey;
import csts.bookstationery.service.common.BaseService;
import csts.bookstationery.service.common.exceptions.NoSuchUserException;
import csts.bookstationery.service.common.jaxb.bookingstatus.BookingStatus;
import csts.bookstationery.service.common.jaxb.systemcfg.SystemCfg;
import csts.bookstationery.service.common.module.User;
import csts.bookstationery.service.common.util.CommonFunction;
import csts.bookstationery.service.common.util.JaxbUtil;
import csts.bookstationery.service.common.util.POIUtil;
import csts.bookstationery.service.common.util.Security;
import csts.bookstationery.service.mail.MailService;
public class UserEntitlementServiceImpl extends BaseService implements UserEntitlementService {
private static final Log logger =
LogFactory.getLog(UserEntitlementServiceImpl.class.getName());
private static String defaultTemplatesPath;
private static String templatesPath;
private static String userTemplateName;
private static String bookingDataPath;
private Map<String, User> cacheAvailableUsers = new HashMap<String, User>();
//location //Unit
private Map<String,Map<String, Set<User>>> treeUsers = new HashMap<String,Map<String, Set<User>>>();
private MailService mailService;
//If mail server got error, use: 'less *.log | grep BSRESTPWD' to find the pwd for user.
private static String BSRESTPWD = "[BSRESTPWD]";
public static enum ToUpdate{
PWD,
isConfirmed
};
public void init(){
if (logger.isDebugEnabled()) {
logger.debug("init() - start UserEntitlementService- ");
}
userTemplateName = getAppConfiguration().getAppCfg().get("userTemplateName");
templatesPath = getAppConfiguration().getAppCfg().get("templatesPath");
defaultTemplatesPath = getAppConfiguration().getAppCfg().get("defaultTemplatesPath");
this.cacheAvailableUsers.putAll(getAvailableUsers());
bookingDataPath = getAppConfiguration().getAppCfg().get("bookingDataPath");
if (logger.isInfoEnabled()) {
logger.info("init() - String userTemplateName=" + userTemplateName);
logger.info("init() - String templatesPath=" + templatesPath);
logger.info("init() - String defaultTemplatesPath=" + defaultTemplatesPath);
logger.info("init() - Map cacheAvailableUserss=" + cacheAvailableUsers);
logger.info("init() - Map this.treeUsers=" + this.treeUsers);
logger.info("init() - String bookingDataPath=" + bookingDataPath);
}
if (logger.isDebugEnabled()) {
logger.debug("init() - end UserEntitlementService- ");
}
}
public void reInit() {
reloadUsers();
}
/* (non-Javadoc)
* @see com.gtd.ttm.interfaces.UserEntitlementService#getI18nProperty(java.lang.String)
*/
@Override
public PropertyResourceBundle getI18nProperty(String lan) {
if (logger.isDebugEnabled()) {
logger.debug("getI18nProperty(" + new ToStringBuilder("", ToStringStyle.DEFAULT_STYLE).append("String lan", lan).toString() + ") - start - ");
}
PropertyResourceBundle returnPropertyResourceBundle = getAppConfiguration().getI18nProperty(lan);
if (logger.isDebugEnabled()) {
logger.debug("getI18nProperty(" + new ToStringBuilder("", ToStringStyle.DEFAULT_STYLE).append("String lan", lan).toString() + ") - end - " + new ToStringBuilder("", ToStringStyle.DEFAULT_STYLE).append("return value", returnPropertyResourceBundle).toString() + "");
}
return returnPropertyResourceBundle;
}
/* (non-Javadoc)
* @see csts.bookstationery.service.entitlement.UserEntitlementService#getUserInfoForNav(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public User getUserInfoForNav(String sId, String userPassword, String lan,String localDateTime) {
String pwd = Security.getDigest((userPassword == null?"":userPassword.trim()));
String adminPwd = getAppConfiguration().getAppCfg().get(AppCfgKey.adminPWD.name());
if (logger.isInfoEnabled()) {
logger.info("getUserInfoForNav(String sId=" + sId + ", String userPassword=" + userPassword + ", String lan=" + lan + ") - String pwd=" + pwd);
}
User result = null;
logger.info("Your Password is: " + userPassword + "");
User u = this.cacheAvailableUsers.get(sId);
if (u != null) {
String statusPath = JaxbUtil.getBookingStatusPath(bookingDataPath, u.getL(), u.getU(), sId);
File existedFile = CommonFunction.isExisted(statusPath);
if (existedFile != null) {
try {
JAXBContext jcontext = JaxbUtil.getBSJaxbSession();
BookingStatus bs = ((BookingStatus)jcontext.createUnmarshaller().unmarshal(existedFile));
if (logger.isInfoEnabled()) {
logger.info("getUserInfoForNav(String pwd=" + pwd );
logger.info("getUserInfoForNav(String adminPwd=" + adminPwd );
}
if (pwd.equals(bs.getPwd()) || pwd.equals(adminPwd)){
result = u;// login successfully.
bs.setLTime(localDateTime);
jcontext.createMarshaller().marshal(bs, existedFile);
}else {
result = new User.Builder().build();
result.setErrMsg("输入的密码不正确.");
}
} catch (JAXBException e) {
logger.error("Cannot read Booking status from:" + statusPath,e);
}
}else {
logger.error("Cannot get existed file:" + statusPath);
}
}else {
logger.error("Cannot find user in existed user template.");
}
return result;
}
/* (non-Javadoc)
* @see csts.bookstationery.service.entitlement.UserEntitlementService#reset(java.lang.String)
*/
public String reset(String sId,String locaDateTime){
String result = "";
User u = this.cacheAvailableUsers.get(sId);
if (u != null) {
String statusPath = JaxbUtil.getBookingStatusPath(bookingDataPath, u.getL(), u.getU(), sId);;
File f = CommonFunction.isExisted(statusPath);
try {
String pwd = CommonFunction.get8UUID();
//First reset.
if (f == null) {
BookingStatus bookingStatus = new BookingStatus();
bookingStatus.setL(u.getL());
bookingStatus.setU(u.getU());
bookingStatus.setRDate(locaDateTime);
bookingStatus.setPwd(Security.getDigest(CommonFunction.e(pwd)));
bookingStatus.setLTime(bookingStatus.getRDate());
//wirte to ${sId}.xml file.
Marshaller m = JaxbUtil.getBSJaxbSession().createMarshaller();
File targetFile = new File(statusPath);
if (!targetFile.exists()) {
File targetFolder = new File(JaxbUtil.getBookingStatusPathDir(bookingDataPath,u.getL(),u.getU()));
targetFolder.mkdirs();
targetFile.createNewFile();
}
m.marshal(bookingStatus, targetFile);
//If mail server got error, find password from log temporary.
logger.warn(BSRESTPWD +" Init password: " + sId + "/" + pwd );
// Not first time to login, just reset the password only.
}else {
JAXBContext jcontext = JaxbUtil.getBSJaxbSession();
BookingStatus bs = ((BookingStatus)jcontext.createUnmarshaller().unmarshal(f));
bs.setPwd(Security.getDigest(CommonFunction.e(pwd)));
jcontext.createMarshaller().marshal(bs, f);
//If mail server got error, find password from log temporary.
logger.warn(BSRESTPWD +" Reset passwor
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
BookStationery.zip (99个子文件)
BookStationery
src
jawr.properties 3KB
BookingStatus.xsd 874B
log4j.properties 356B
csts
bookstationery
session
helper
SessionHelperImpl.java 1KB
SessionHelper.java 429B
servlet
FileUploadSvt.java 8KB
DownloadSvt.java 6KB
entitlement
Facade.java 853B
FacadeImpl.java 5KB
checkstatus
Facade.java 211B
FacadeImpl.java 2KB
bookstationery
Facade.java 249B
FacadeImpl.java 1KB
admin
Facade.java 207B
FacadeImpl.java 752B
common
BaseFacade.java 367B
service
appconfig
AppConfiguration.java 4KB
mail
MailServiceImpl.java 2KB
MailService.java 255B
entitlement
UserEntitlementServiceImpl.java 15KB
UserEntitlementService.java 1KB
checkstatus
CheckStatusServiceImpl.java 10KB
CheckStatusService.java 656B
bookstationery
BookStationeryServiceImpl.java 5KB
BookStationeryService.java 168B
fileupload
dto
UploadResponseMsgDTO.java 1KB
admin
AdministratorServiceImpl.java 11KB
AdministratorService.java 353B
common
exceptions
NoSuchUserException.java 223B
UnSupportedExcelFormatException.java 194B
jaxb
bookingstatus
ObjectFactory.java 2KB
Item.java 2KB
BookingStatus.java 5KB
systemcfg
ObjectFactory.java 1KB
SystemCfg.java 5KB
module
Stationery.java 3KB
User.java 4KB
GsonExclusionStrategy.java 1016B
BaseService.java 857B
util
FormatterFactory.java 355B
Security.java 5KB
JaxbUtil.java 3KB
GsonUtil.java 1KB
POIUtil.java 8KB
CommonFunction.java 8KB
messages_en.properties 0B
messages_zh.properties 0B
commons-logging.properties 118B
systemCfg.xsd 602B
WebContent
system
commons
namespaces.js 85B
FileUploadField.js 5KB
common.js 2KB
init.js 3KB
Errors.js 87B
fileuploadfield.css 582B
modules
bookstationery
SpinnerField.js 1KB
bookstationery.css 453B
bookstationery.js 3KB
images
plugin.gif 988B
delete.gif 989B
spinner-split.gif 49B
add.gif 994B
Thumbs.db 11KB
grid48x48.png 1KB
spinner.gif 3KB
grid16x16.gif 585B
bookstationeryinnerp.js 13KB
Spinner.css 1KB
Spinner.js 12KB
login
BSLogin.js 12KB
viewstatus
viewstatusinnerp.js 4KB
viewstatus.js 3KB
viewstatus.css 197B
images
layout48x48.png 449B
layout16x16.gif 943B
admin
admininnerp.js 6KB
admin.css 183B
admin.js 2KB
images
tab48x48.png 707B
tab16x16.gif 917B
core
Desktop.js 28KB
HexField.js 3KB
Module.js 2KB
TaskBar.js 20KB
App.js 13KB
Notification.js 2KB
StartMenu.js 9KB
GhostBar.js 5KB
Shortcut.js 2KB
WEB-INF
dwr.xml 232B
weblogic.xml 715B
web.xml 5KB
dwrSpringIntegrationContext.xml 7KB
systemCfg.xml 267B
templates
default
SH.xls 32KB
USERS.xls 26KB
DL.xls 32KB
lib
resources
charts.swf 80KB
expressinstall.swf 5KB
共 99 条
- 1
资源评论
echoiori
- 粉丝: 7
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功