Skip to content

Commit

Permalink
Merge pull request #43 from FeverTeam/dev-iron
Browse files Browse the repository at this point in the history
Dev iron
  • Loading branch information
lizijing committed Sep 29, 2013
2 parents f456f0a + 649fe22 commit 85f86aa
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.fever.liveppt.exception.ppt;

import com.fever.liveppt.utils.StatusCode;

/**
* Created with IntelliJ IDEA.
* User: Administrator
* Date: 13-9-28
* Time: 下午9:37
* To change this template use File | Settings | File Templates.
*/
public class PptNotPermissionDenyException extends PptException {
public PptNotPermissionDenyException()
{
super(StatusCode.PPT_NOT_PERMISSION_DENY,StatusCode.PPT_NOT_PERMISSION_DENY_MESSAGE);
}
}
5 changes: 3 additions & 2 deletions LivePPT/app/com/fever/liveppt/service/MeetingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@


/**
* 会议服务
* @author
* @version : v1.00
* @Description : 会议操作接口 ,提供给controller层调用
*
* @author 梁博文
*/
public interface MeetingService {

Expand Down
12 changes: 5 additions & 7 deletions LivePPT/app/com/fever/liveppt/service/PptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.fever.liveppt.exception.common.InternalErrorException;
import com.fever.liveppt.exception.common.InvalidParamsException;
import com.fever.liveppt.exception.ppt.PptNotConvertedException;
import com.fever.liveppt.exception.ppt.PptNotExistedException;
import com.fever.liveppt.exception.ppt.PptNotSelfOwnException;
import com.fever.liveppt.exception.ppt.PptPageOutOfRangeException;
import com.fever.liveppt.exception.ppt.*;
import com.fever.liveppt.models.Ppt;
import com.fever.liveppt.models.User;
import org.codehaus.jackson.JsonNode;
Expand All @@ -14,9 +11,10 @@
import java.util.List;

/**
* PPT服务
* @author
* @version : v1.00
* @Description : PPT操作接口 ,提供给controller层调用
*
* @author 梁博文
*/
public interface PptService {

Expand All @@ -31,7 +29,7 @@ public interface PptService {
* @throws PptPageOutOfRangeException
* @throws InternalErrorException
*/
public byte[] getPptPage(Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException;
public byte[] getPptPage(String userEmail,Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException, PptNotPermissionDenyException;

/**
* 更新PPT转换状态
Expand Down
16 changes: 16 additions & 0 deletions LivePPT/app/com/fever/liveppt/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@

import com.fever.liveppt.exception.common.CommonException;
import com.fever.liveppt.exception.common.InvalidParamsException;
import com.fever.liveppt.exception.user.PasswordNotMatchException;
import com.fever.liveppt.exception.user.UserException;
import com.fever.liveppt.exception.user.UserNotExistedException;
import com.fever.liveppt.models.User;
import com.fever.liveppt.utils.ResultJson;

/**
* @author
* @version : v1.00
* @Description : 用户操作接口 ,提供给controller层调用
*
*/
public interface UserService {

/**
*
* @param userEmail
* @param oldPassword
* @param newPassword
* @return
* @throws PasswordNotMatchException
*/
public ResultJson updatePassword(String userEmail,String oldPassword,String newPassword,String seed) throws PasswordNotMatchException;
/**
* 验证帐号密码
*
Expand Down
15 changes: 11 additions & 4 deletions LivePPT/app/com/fever/liveppt/service/impl/MeetingServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.fever.liveppt.service.impl;

import com.fever.liveppt.exception.meeting.AttendingExistedException;
Expand All @@ -20,6 +21,12 @@
import java.util.ArrayList;
import java.util.List;

/**
* @author
* @version : v1.00
* @Description : 会议操作接口实现 ,提供给service层调用
*
*/
public class MeetingServiceImpl implements MeetingService {

@Override
Expand Down Expand Up @@ -56,7 +63,7 @@ public ResultJson quitMeeting(String userEmail, Long meetingId) throws MeetingNo
throw new MeetingNotAttendedException();
}
for (Attender attender : user.attendents) {
if (attender.meeting.id == meetingId) {
if (attender.meeting.id.equals( meetingId)) {
attender.delete();
isAttended = true;
break;
Expand All @@ -79,7 +86,7 @@ public ResultJson createMeeting(String userEmail, Long pptId, String topic) thro
if (ppt == null) {
throw new PptNotExistedException();
}
if (ppt.owner.id != founder.id) {
if (!ppt.owner.id.equals(founder.id)) {
throw new MeetingPermissionDenyException();
}
//新建发起的会议,并存入数据库
Expand Down Expand Up @@ -163,7 +170,7 @@ public ResultJson joinMeeting(String userEmail, Long meetingId) throws MeetingNo
if (attendents != null) {
for (Attender attending : attendents) {
//已经加入
if (attending.meeting.id == meeting.id) {
if (attending.meeting.id.equals(meeting.id)) {
resultJson = ResultJson.simpleSuccess();
isAttended = true;
break;
Expand All @@ -189,7 +196,7 @@ public ResultJson setPage(String userEmail, Long meetingId, Long pageIndex) thro

User user = User.find.where().eq("email", userEmail).findUnique();

if (meeting.founder.id != user.id) {
if (!meeting.founder.id.equals(user.id)) {
throw new MeetingPermissionDenyException();
}

Expand Down
41 changes: 36 additions & 5 deletions LivePPT/app/com/fever/liveppt/service/impl/PptServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.fever.liveppt.exception.common.InternalErrorException;
import com.fever.liveppt.exception.common.InvalidParamsException;
import com.fever.liveppt.exception.ppt.PptNotConvertedException;
import com.fever.liveppt.exception.ppt.PptNotExistedException;
import com.fever.liveppt.exception.ppt.PptNotSelfOwnException;
import com.fever.liveppt.exception.ppt.PptPageOutOfRangeException;
import com.fever.liveppt.exception.ppt.*;
import com.fever.liveppt.models.Attender;
import com.fever.liveppt.models.Meeting;
import com.fever.liveppt.models.Ppt;
Expand All @@ -29,16 +26,50 @@
import java.util.LinkedList;
import java.util.List;

/**
* @author
* @version : v1.00
* @Description : PPT操作接口实现 ,提供给service层调用
*
*/
public class PptServiceImpl implements PptService {


@Override
public byte[] getPptPage(Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException {
public byte[] getPptPage(String userEmail,Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException, PptNotPermissionDenyException {
boolean ifPermission = false;
Ppt ppt = Ppt.find.byId(pptId);
if (ppt == null) {
throw new PptNotExistedException();
}

User user = User.find.where().eq("email", userEmail).findUnique();

for(Ppt userPpt: user.ppts)
{
if(pptId.equals(userPpt.id) )
{
ifPermission = true;
break;
}
}
if(!ifPermission)
{
for (Attender attender : user.attendents) {
if(pptId == attender.meeting.ppt.id)
{
ifPermission = true;
break;
}

}
}

if(!ifPermission)
{
throw new PptNotPermissionDenyException();
}

//检查是否已转换
if (!ppt.isConverted) {
throw new PptNotConvertedException();
Expand Down
20 changes: 18 additions & 2 deletions LivePPT/app/com/fever/liveppt/service/impl/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,25 @@
import java.util.HashMap;
import java.util.Map;


/**
* @author
* @version : v1.00
* @Description : 用户操作接口实现 ,提供给service层调用
*
*/
public class UserServiceImpl implements UserService {

@Override
public ResultJson updatePassword(String userEmail,String oldPassword,String newPassword,String seed) throws PasswordNotMatchException {
User user = User.find.where().eq("email", userEmail).findUnique();
String userHashedPassword = Crypto.sign(user.password, seed.getBytes());
if(!oldPassword.equals(userHashedPassword))
{
throw new PasswordNotMatchException();
}
user.password = Crypto.decryptAES(newPassword, seed);
user.save();
return new ResultJson(StatusCode.SUCCESS, StatusCode.SUCCESS_MESSAGE, null);
}
@Override
public boolean isEmailExisted(String userEmail) throws CommonException, UserException {
if (!TokenAgent.isEmailFormatValid(userEmail)) {
Expand Down
2 changes: 1 addition & 1 deletion LivePPT/app/com/fever/liveppt/utils/ControllerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* User: simonlbw
* Date: 13-8-28
* Time: 下午11:20
* To change this template use File | Settings | File Templates.
* Description: controller层所用到的参数检查等方法
*/
public class ControllerUtils {

Expand Down
2 changes: 1 addition & 1 deletion LivePPT/app/com/fever/liveppt/utils/DataJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* User: Zijing Lee
* Date: 13-8-27
* Time: 上午10:42
* To change this template use File | Settings | File Templates.
* Description: 封装Json格式的数据
*/

import org.codehaus.jackson.JsonNode;
Expand Down
6 changes: 5 additions & 1 deletion LivePPT/app/com/fever/liveppt/utils/ResultJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import org.codehaus.jackson.node.ObjectNode;

/**
* 封装数据方向接口的自定义JSON格式
* Created with IntelliJ IDEA.
* User: Zijing Lee
* Date: 13-9-27
* Time: 上午10:42
* Description: 封装数据方向接口的自定义JSON格式,即接口返回数据的JSON格式
*/
public class ResultJson extends ObjectNode {
public final static String KEY_DATA = "data";
Expand Down
11 changes: 10 additions & 1 deletion LivePPT/app/com/fever/liveppt/utils/StatusCode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.fever.liveppt.utils;

/**
* Created with IntelliJ IDEA.
* User: Zijing Lee
* Date: 13-9-27
* Time: 上午12:43
* Description: 异常状态码以及异常返回信息静态变量定义
*/
public class StatusCode {
//一切正常
public final static int SUCCESS = 0;
Expand Down Expand Up @@ -44,6 +50,9 @@ public class StatusCode {
//指定PPT并非用户自己所拥有
public final static int PPT_NOT_SELF_OWN = -305;
public final static String PPT_NOT_SELF_OWN_MESSAGE = "ppt not of user own";
//用户没有权限操作该PPT
public final static int PPT_NOT_PERMISSION_DENY = -306;
public final static String PPT_NOT_PERMISSION_DENY_MESSAGE = "not have permission to operate the ppt" ;
//*******************MEETING类型错误*****************
//Meeting不存在
public final static int MEETING_NOT_EXISTED = -401;
Expand Down
8 changes: 7 additions & 1 deletion LivePPT/app/com/fever/liveppt/utils/TokenAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
* Created with IntelliJ IDEA.
* User: Zijing Lee
* Date: 13-9-27
* Time: 上午12:43
* Description: 关于用户登陆后token的操作,包括token的检验,根据token获取用户,生成token等。
*/
public class TokenAgent {

public static Pattern emailPattern = Pattern.compile("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\\.([a-zA-Z0-9_-])+)+$");
Expand Down
Loading

0 comments on commit 85f86aa

Please sign in to comment.