Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utubers - 13513063 - Muhammad Aodyra Khaidir #24

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4413433
Laman Page Home, Question, Askhere, dan Header.
fauzanriff Nov 14, 2015
9964b54
Initial Web Service and model package
fauzanriff Nov 14, 2015
146acfa
Add utility package
fauzanriff Nov 14, 2015
cf6286f
Initial Identity Service and Client
fauzanriff Nov 14, 2015
eb09540
Design CSS,
aodyra Nov 14, 2015
80de6dd
creating jsp files
khalilambiya Nov 15, 2015
8296b2b
revisi jsp
khalilambiya Nov 16, 2015
462fc36
draft IdentityServices selesai
khalilambiya Nov 17, 2015
f948035
Add Web services for Question and Answer
fauzanriff Nov 17, 2015
047f264
memperbaiki tampilan
aodyra Nov 17, 2015
1e7cffd
Merge branch 'master' of https://github.com/Utubers/IF3110-2015-T2
aodyra Nov 17, 2015
eb82530
Membuat servlet Answer
aodyra Nov 17, 2015
9acdbbc
Menambahkan Servlet question
aodyra Nov 17, 2015
ea080cd
Menambahkan servlet register
aodyra Nov 17, 2015
88d75dc
Web Service : Question and Answer
fauzanriff Nov 17, 2015
dcd313d
Web Service Update
fauzanriff Nov 18, 2015
546824f
Web Service Add User WS functionality
fauzanriff Nov 18, 2015
ba4b79c
tes
aodyra Nov 18, 2015
8157739
Utah structure data dan penanganan bug answerWS
fauzanriff Nov 25, 2015
9a6979a
servlet pertanyaan dan jawaban
aodyra Nov 27, 2015
b5e3ebc
servlet edit question
aodyra Nov 27, 2015
1d4da47
memperbaiki fungsi register
aodyra Nov 27, 2015
fcf13d4
memperbaiki proses signin dan signout
aodyra Nov 27, 2015
a0f3a8b
menampilkan askhere.jsp untuk editquestion
aodyra Nov 27, 2015
688d938
menambahkan servlet untuk menampilkan satu pertanyaan dan jawaban
aodyra Nov 27, 2015
cf3b2a8
servler funngsi delete dan voting
aodyra Nov 27, 2015
4bda812
menambah servlet voting answer
aodyra Nov 27, 2015
02a81b3
finish work
aodyra Nov 27, 2015
315287b
Update model answer menggunakan timestamp
fauzanriff Nov 27, 2015
a8c6937
Penyesuaian package model dengan database
fauzanriff Nov 27, 2015
d277e68
Update QuestionWS dan UserWS sesuai kebutuhan client
fauzanriff Nov 27, 2015
1810497
Pembangunan keels Auth yang berhubungan dengan identity service
fauzanriff Nov 27, 2015
9d138e5
Autentikasi Pengecekan User pada QuestionWS
fauzanriff Nov 27, 2015
022f21a
Autentikasi pengecekan user pada AnswerWS
fauzanriff Nov 27, 2015
c9539cf
Autentikasi Pada UserWS
fauzanriff Nov 27, 2015
a721b94
Autenticas dan pánanganan vote
fauzanriff Nov 27, 2015
a1a93ef
Identity service selesai
khalilambiya Nov 27, 2015
1782b3f
Re-deploy, Re-commit some mistaken. Bug fixes on checking identity se…
fauzanriff Nov 27, 2015
7948b20
Update README.md
fauzanriff Nov 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update model answer menggunakan timestamp
fauzanriff committed Nov 27, 2015
commit 315287ba70e9860715c89efa60a8eda2173235b4
226 changes: 133 additions & 93 deletions StackExchange-WebService/src/java/stackexchange/webservice/AnswerWS.java
Original file line number Diff line number Diff line change
@@ -5,9 +5,12 @@
*/
package stackexchange.webservice;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.jws.Oneway;
import javax.jws.WebService;
@@ -16,7 +19,10 @@
import javax.jws.WebResult;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import stackexchange.webservice.auth.Auth;
import stackexchange.webservice.model.Answer;
import stackexchange.webservice.model.Question;
import stackexchange.webservice.model.User;
import stackexchange.webservice.util.Database;

/**
@@ -26,7 +32,7 @@
@WebService(serviceName = "AnswerWS")
public class AnswerWS {

/**
/**
* Web service operation
*/
@WebMethod(operationName = "getAnswers")
@@ -39,7 +45,7 @@ public List<Answer> getAnswers() {
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Answer answer = new Answer(rs.getInt("id"), rs.getInt("userid"), rs.getInt("questionId"), rs.getString("name"), rs.getString("email"), rs.getString("content"), rs.getDate("dateMade"), "", rs.getInt("vote"));
Answer answer = new Answer(rs.getInt("id"), rs.getInt("userid"), rs.getInt("questionId"), rs.getString("name"), rs.getString("email"), rs.getString("content"), rs.getTimestamp("dateMade"), rs.getInt("vote"));
answers.add(answer);
}
return answers;
@@ -68,7 +74,7 @@ public List<Answer> getAnswers(@WebParam(name="questionId") int questionId) {
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Answer answer = new Answer(rs.getInt("id"), rs.getInt("userid"), rs.getInt("questionId"), rs.getString("name"), rs.getString("email"), rs.getString("content"), rs.getDate("dateMade"), "", rs.getInt("vote"));
Answer answer = new Answer(rs.getInt("id"), rs.getInt("userid"), rs.getInt("questionId"), rs.getString("name"), rs.getString("email"), rs.getString("content"), rs.getTimestamp("dateMade"), rs.getInt("vote"));
answers.add(answer);
}
return answers;
@@ -87,44 +93,65 @@ public List<Answer> getAnswers(@WebParam(name="questionId") int questionId) {
*/
@WebMethod(operationName = "addAnswer")
@Oneway
public void addAnswer(@WebParam(name = "answer") Answer answer) {
Database db = new Database();
try{
String values="(";
values+= answer.getQuestionId() +",";
values+= "'"+ answer.getName() +"',";
values+= "'"+ answer.getEmail() +"',";
values+= "'"+ answer.getContent() +"',";
values+= "'"+ answer.getDateMade() +"',";
values+= answer.getVote() +")";
String sql="insert into answers values " + values;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
db = null;
}
public void addAnswer(@WebParam(name = "answer") Answer answer, @WebParam(name = "token")String token) {
Auth auth = new Auth();
int ret = auth.check(answer.getEmail(),token);
UserWS usrws = new UserWS();
User user = usrws.getUserByEmail(answer.getEmail());
Timestamp currentTime = new Timestamp(Calendar.getInstance().getTime().getTime());
Answer newAnswer = new Answer(user.getId(), answer.getQuestionId(), user.getName(), user.getEmail(), answer.getContent(),currentTime, 0 );

if(ret == 1 || ret == 0){
Database db = new Database();
try{
String values="(";
values+= newAnswer.getUserid() + ",";
values+= newAnswer.getQuestionId() +",";
values+= "'"+ newAnswer.getName() +"',";
values+= "'"+ newAnswer.getEmail() +"',";
values+= "'"+ newAnswer.getContent() +"',";
values+= "'"+ newAnswer.getDateMade() +"',";
values+= newAnswer.getVote() +")";
String sql="insert into answers (userid, questionId, name, email, content,dateMade,vote) values " + values;
Connection conn = db.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
ps.executeUpdate();

sql = "update questions set answer= answer+1 where id=" + newAnswer.getQuestionId();
ps = conn.prepareStatement(sql);
ps.executeUpdate();

}catch(Exception e){

}finally{
db.closeConnection();
db = null;
}
}

}

/**
* Web service operation
*/
@WebMethod(operationName = "deleteAnswer")
@Oneway
public void deleteAnswer(@WebParam(name = "id") int id, @WebParam(name = "questionId") int questionId) {
Database db = new Database();
try{
String sql="delete from questions where questionId=" + questionId + "and id=" + id;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
//db = null;
}
public void deleteAnswer(@WebParam(name = "id") int id, @WebParam(name = "questionId") int questionId, @WebParam(name = "email") String email, @WebParam(name = "token") String token) {
Auth auth = new Auth();
int ret = auth.check(email,token);
if(ret == 1 || ret == 0){
Database db = new Database();
try{
String sql="delete from questions where questionId=" + questionId + "and id=" + id;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
//db = null;
}
}
}


@@ -133,28 +160,32 @@ public void deleteAnswer(@WebParam(name = "id") int id, @WebParam(name = "questi
*/
@WebMethod(operationName = "voteAnswer")
@Oneway
public void voteAnswer(@WebParam(name = "answer") Answer answer, @WebParam(name = "inc") boolean inc) {
Database db = new Database();
try{
int val=0;
if (inc) {
val++;
}else{
val--;
}
int id = answer.getId();
int questionId = answer.getQuestionId();
String values="";
values+= "vote=val+("+ val + ")";
String sql="update answers set " + values + " where id=" + id + "and questionId=" + questionId;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
//db = null;
}
public void voteAnswer(@WebParam(name = "answer") Answer answer, @WebParam(name = "inc") boolean inc, @WebParam(name = "token") String token) {
Auth auth = new Auth();
int ret = auth.check(answer.getEmail(),token);
if(ret == 1 || ret == 0){
Database db = new Database();
try{
int val=0;
if (inc) {
val++;
}else{
val--;
}
int id = answer.getId();
int questionId = answer.getQuestionId();
String values="";
values+= "vote=val+("+ val + ")";
String sql="update answers set " + values + " where id=" + id + "and questionId=" + questionId;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
//db = null;
}
}
}

/**
@@ -163,49 +194,58 @@ public void voteAnswer(@WebParam(name = "answer") Answer answer, @WebParam(name
@WebMethod(operationName = "voteAnswer_1")
@Oneway
@RequestWrapper(className = "stackexchange.voteAnswer_1")
public void voteAnswer(@WebParam(name = "id") int id, @WebParam(name = "questionId") int questionId, @WebParam(name = "inc") boolean inc) {
Database db = new Database();
try{
int val=0;
if (inc) {
val++;
}else{
val--;
}
String values="";
values+= "vote=val+("+ val + ")";
String sql="update answers set " + values + " where id=" + id + "and questionId=" + questionId;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
db = null;
}
public void voteAnswer(@WebParam(name = "id") int id, @WebParam(name = "questionId") int questionId, @WebParam(name = "inc") boolean inc, @WebParam(name = "email") String email, @WebParam(name = "token") String token) {
Auth auth = new Auth();
int ret = auth.check(email,token);
if(ret == 1 || ret == 0){
Database db = new Database();
try{
int val=0;
if (inc) {
val++;
}else{
val--;
}
String values="";
values+= "vote=val+("+ val + ")";
String sql="update answers set " + values + " where id=" + id + "and questionId=" + questionId;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
db = null;
}
}
}

/**
* Web service operation
*/
@WebMethod(operationName = "updateAnswer")
@Oneway
public void updateAnswer(@WebParam(name = "answer") Answer answer) {
Database db = new Database();
try{
int id = answer.getId();
int questionId = answer.getQuestionId();
String values="";
values+= "content='"+ answer.getContent() +"',";
values+= "dateMade='"+ answer.getDateMade() +"',";
String sql="update answers set " + values + " where id=" + id + "and questionId=" + questionId;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
//db = null;
}
public void updateAnswer(@WebParam(name = "answer") Answer answer, @WebParam(name = "token") String token) {
Auth auth = new Auth();
int ret = auth.check(answer.getEmail(),token);
if(ret == 1 || ret == 0){
Database db = new Database();
try{
int id = answer.getId();
int questionId = answer.getQuestionId();
String values="";
values+= "content='"+ answer.getContent() +"',";
values+= "dateMade='"+ answer.getDateMade() +"',";
String sql="update answers set " + values + " where id=" + id + "and questionId=" + questionId;
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.executeUpdate();
}catch(Exception e){

}finally{
db.closeConnection();
//db = null;
}
}
}

}