Add files via upload

This commit is contained in:
gopi17701 2018-09-29 21:25:24 -04:00 committed by GitHub
parent ae3001c66c
commit b2567f25f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 173 additions and 40 deletions

View File

@ -132,6 +132,8 @@ public abstract class DAO {
public abstract String dupliateInvoice(String InvoiceNumber) throws AstuteException; public abstract String dupliateInvoice(String InvoiceNumber) throws AstuteException;
public abstract List<Invoice> getSubmittedInvoiceNumbers() throws AstuteException;
public abstract List<Customer> getCustomers(String customerId) throws AstuteException; public abstract List<Customer> getCustomers(String customerId) throws AstuteException;
public abstract Customer getCustomer(String poNumber) throws AstuteException; public abstract Customer getCustomer(String poNumber) throws AstuteException;
@ -154,7 +156,7 @@ public abstract class DAO {
public abstract String getSessionUsername(String sessionId) throws AstuteException; public abstract String getSessionUsername(String sessionId) throws AstuteException;
public abstract String login(String username, String password) throws AstuteException; public abstract User login(String username, String password) throws AstuteException;
public abstract List<ChangeOrder> getChangeOrders(String poNum) throws AstuteException; public abstract List<ChangeOrder> getChangeOrders(String poNum) throws AstuteException;
@ -168,4 +170,5 @@ public abstract class DAO {
public abstract void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate) throws AstuteException; public abstract void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate) throws AstuteException;
public abstract List<PaymentType> getPaymentTypes() throws AstuteException;
} }

View File

@ -618,6 +618,28 @@ public class SqlDAO extends DAO {
throw new AstuteException(DB_ERROR,e.getMessage()); throw new AstuteException(DB_ERROR,e.getMessage());
} }
} }
public List<Invoice> getSubmittedInvoiceNumbers() throws AstuteException {
String sql = "select inv_no from invoice where inv_status = 2";
String invoiceNumber = null;
Invoice invoice = null;
List<Invoice> invoices = new ArrayList<Invoice>();
try {
Statement stmt = conn.createStatement();
ResultSet resultSet = stmt.executeQuery(sql);
while (resultSet.next()) {
invoiceNumber = resultSet.getString(1);
invoice = new Invoice(invoiceNumber,null,null,0,null,null,null,0);
invoices.add(invoice);
}
} catch (SQLException e) {
e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage());
}
System.out.println("Returning invoices " + invoices.size());
return invoices;
}
/* /*
=============================== Customer Methods =============================================== =============================== Customer Methods ===============================================
*/ */
@ -760,7 +782,7 @@ public class SqlDAO extends DAO {
} }
public User getUser(String username) throws AstuteException { public User getUser(String username) throws AstuteException {
String sql = "select user_id, username, password from user where username='" + username + "'"; String sql = "select user_id, username, password, CONCAT(first_name, ' ', last_name) as name from user where username='" + username + "'";
try { try {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
@ -768,7 +790,11 @@ public class SqlDAO extends DAO {
User user = null; User user = null;
if(resultSet.next()) { if(resultSet.next()) {
user = new User(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3)); user = new User(resultSet.getInt(1),
resultSet.getString(2),
resultSet.getString(3),
resultSet.getString(4),null
);
} }
// conn.close(); // conn.close();
@ -894,7 +920,7 @@ public class SqlDAO extends DAO {
try { try {
List<InvoicePayment> invoicePayments = new ArrayList<InvoicePayment>(); List<InvoicePayment> invoicePayments = new ArrayList<InvoicePayment>();
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
String sql = "SELECT invoice_payment_id, invoice_payment_type, get_payment_type(invoice_payment_type), invoice_amount, payment_date FROM invoice_payment "; String sql = "SELECT invoice_payment_id, invoice_payment_type, get_payment_type(invoice_payment_type), invoice_amount, payment_date, inv_no FROM invoice_payment ";
if (invoiceNum != null) { if (invoiceNum != null) {
sql += " WHERE inv_no = '" + invoiceNum + "'"; sql += " WHERE inv_no = '" + invoiceNum + "'";
} }
@ -905,7 +931,8 @@ public class SqlDAO extends DAO {
String invoicePaymentType = rs.getString(3); String invoicePaymentType = rs.getString(3);
Double paymentAmount = rs.getDouble(4); Double paymentAmount = rs.getDouble(4);
Date paymentDate = rs.getDate(5); Date paymentDate = rs.getDate(5);
InvoicePayment invoicePayment = new InvoicePayment(invoiceNum, invoicePaymentId, invoicePaymentTypeId, invoicePaymentType, paymentDate, paymentAmount); String invNo = rs.getString(6);
InvoicePayment invoicePayment = new InvoicePayment(invNo, invoicePaymentId, invoicePaymentTypeId, invoicePaymentType, paymentDate, paymentAmount);
invoicePayments.add(invoicePayment); invoicePayments.add(invoicePayment);
} }
return invoicePayments; return invoicePayments;
@ -922,14 +949,14 @@ public class SqlDAO extends DAO {
String whereClause = ""; String whereClause = "";
if (invoiceNum == null || invoiceNum.isEmpty() || invoicePaymentId <=0 ) { if (invoiceNum == null || invoiceNum.isEmpty() || invoicePaymentId <=0 ) {
throw new AstuteException(DB_ERROR,"Invoice Number can't be null and Invoice Payment Id should be a positive number! "); throw new AstuteException(DB_ERROR,"Invoice Number can't be null and Invoice Payment Id should be a positive number! ");
} else {
whereClause = " WHERE UPPER(inv_no) ='" + invoiceNum.toUpperCase() + "' and invoice_amount = " + paymentAmount;
} }
updateClause = updateClause + " payment_amount = " + paymentAmount ;
if (paymentDate != null) { updateClause = updateClause + " invoice_amount = " + paymentAmount ;
updateClause = "payment_date " + ", paymentDate = STR_TO_DATE(" + paymentDate + ", '%Y-%m-%d')"; // if (paymentDate != null) {
} updateClause = updateClause + ", payment_date = STR_TO_DATE('" + paymentDate + "', '%Y-%m-%d')";
// }
whereClause = " WHERE UPPER(inv_no) ='" + invoiceNum.toUpperCase() + "' and invoice_payment_id = " + invoicePaymentId;
sql = sql + updateClause + whereClause; sql = sql + updateClause + whereClause;
System.out.println(sql); System.out.println(sql);
@ -944,9 +971,10 @@ public class SqlDAO extends DAO {
public void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate) throws AstuteException{ public void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate) throws AstuteException{
try { try {
String dateString = "STR_TO_DATE(" + paymentDate + ", '%Y-%m-%d')"; String dateString = "STR_TO_DATE('" + paymentDate + "', '%Y-%m-%d')";
String sql = "insert into invoice_payment (inv_no, invoice_payment_type, invoice_amount, payment_date) values ('" + invoiceNum + "', " + paymentAmount + ", " + dateString + "')"; String sql = "insert into invoice_payment (inv_no, invoice_payment_type, invoice_amount, payment_date) values ('" + invoiceNum + "', " + invoicePaymentTypeId + ", " + paymentAmount + ", " + dateString + ")";
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
System.out.println(sql);
stmt.execute(sql); stmt.execute(sql);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -954,12 +982,30 @@ public class SqlDAO extends DAO {
} }
} }
public List<PaymentType> getPaymentTypes() throws AstuteException {
try {
List<PaymentType> paymentTypes = new ArrayList<PaymentType>();
Statement stmt = conn.createStatement();
String sql = "SELECT payment_type_id, payment_type_name FROM payment_type ORDER BY 1 ";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
int paymentTypeId = rs.getInt(1);
String paymentTypeName = rs.getString(2);
PaymentType paymentType = new PaymentType(paymentTypeId, paymentTypeName);
paymentTypes.add(paymentType);
}
return paymentTypes;
} catch (SQLException e) {
e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage());
}
};
/* /*
=============================== Utility Methods =============================================== =============================== Utility Methods ===============================================
*/ */
public String login(String username, String password) throws AstuteException{ public User login(String username, String password) throws AstuteException{
User user = dao.getUser(username); User user = getUser(username);
boolean check = false; boolean check = false;
if (password.equals(user.getPassword())) { if (password.equals(user.getPassword())) {
check = true; check = true;
@ -975,9 +1021,9 @@ public class SqlDAO extends DAO {
//create session //create session
String sessionId = UUID.randomUUID().toString().replaceAll("-", ""); String sessionId = UUID.randomUUID().toString().replaceAll("-", "");
dao.createSession(user.getUserId(), sessionId); createSession(user.getUserId(), sessionId);
user.setSessionId(sessionId);
return sessionId; return user;
}else{ }else{
return null; //"Username or password was not correct"; return null; //"Username or password was not correct";
} }

View File

@ -9,7 +9,7 @@ public class AstuteException extends Exception {
public static final int CLIENT_ERROR = 400; public static final int CLIENT_ERROR = 400;
public static final int SERVER_ERROR = 500; public static final int SERVER_ERROR = 500;
public static final int DB_ERROR = 600; public static final int DB_ERROR = 600;
public static final int AUTH_ERROR = 700;
private int code; private int code;

View File

@ -0,0 +1,29 @@
package com.astute.model;
import java.sql.Date;
public class PaymentType {
int paymentTypeId;
String paymentTypeName;
public PaymentType(int paymentTypeId, String paymentTypeName) {
this.paymentTypeId = paymentTypeId;
this.paymentTypeName = paymentTypeName;
}
public int getPaymentTypeId() {
return paymentTypeId;
}
public void setPaymentTypeId(int paymentTypeId) {
this.paymentTypeId = paymentTypeId;
}
public String getPaymentTypeName() {
return paymentTypeName;
}
public void setPaymentTypeName(String paymentTypeName) {
this.paymentTypeName = paymentTypeName;
}
}

View File

@ -4,11 +4,31 @@ public class User {
int userId; int userId;
String username; String username;
String password; String password;
String name;
String sessionId;
public User(int userId, String username, String password) { public User(int userId, String username, String password, String name, String sessionId) {
this.userId = userId; this.userId = userId;
this.username = username; this.username = username;
this.password = password; this.password = password;
this.name = name;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} }
public int getUserId() { public int getUserId() {
@ -27,11 +47,11 @@ public class User {
this.username = username; this.username = username;
} }
public String getPassword() { public String getName() {
return password; return name;
} }
public void setPassword(String password) { public void setName(String name) {
this.password = password; this.name = name;
} }
} }

View File

@ -1,6 +1,5 @@
package com.astute.requests; package com.astute.requests;
import java.sql.Date;
public class InvoicePaymentRequest { public class InvoicePaymentRequest {
String invoiceNum; String invoiceNum;
@ -19,6 +18,10 @@ public class InvoicePaymentRequest {
this.invoiceAmount = invoiceAmount; this.invoiceAmount = invoiceAmount;
} }
public InvoicePaymentRequest() {
}
public String getInvoiceNum() { public String getInvoiceNum() {
return invoiceNum; return invoiceNum;
} }

View File

@ -1,6 +1,7 @@
package com.astute.resources; package com.astute.resources;
import com.astute.exceptions.AstuteException; import com.astute.exceptions.AstuteException;
import com.astute.model.User;
import com.astute.requests.LoginRequest; import com.astute.requests.LoginRequest;
import com.astute.response.ApiResponse; import com.astute.response.ApiResponse;
import com.astute.service.AuthService; import com.astute.service.AuthService;
@ -25,9 +26,9 @@ public class AuthResource {
@POST @POST
public Response login(LoginRequest request) throws AstuteException { public Response login(LoginRequest request) throws AstuteException {
String sessionId = service.login(request.getUsername(), request.getPassword()); User user = service.login(request.getUsername(), request.getPassword());
if (sessionId != null) { if (user != null) {
return new ApiResponse(sessionId).toResponse(); return new ApiResponse(user).toResponse();
} else { } else {
return new ApiResponse(ApiResponse.ACCESS_DENIED).toResponse(); return new ApiResponse(ApiResponse.ACCESS_DENIED).toResponse();
} }

View File

@ -3,6 +3,7 @@ package com.astute.resources;
import com.astute.exceptions.AstuteException; import com.astute.exceptions.AstuteException;
import com.astute.requests.ChangeOrderRequest; import com.astute.requests.ChangeOrderRequest;
import com.astute.response.ApiResponse; import com.astute.response.ApiResponse;
import com.astute.service.AuthService;
import com.astute.service.ChangeOrderService; import com.astute.service.ChangeOrderService;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -16,13 +17,16 @@ import java.sql.SQLException;
public class ChangeOrderResource { public class ChangeOrderResource {
private com.astute.service.ChangeOrderService service = new ChangeOrderService(); private com.astute.service.ChangeOrderService service = new ChangeOrderService();
private com.astute.service.AuthService authService = new AuthService();
public ChangeOrderResource() { public ChangeOrderResource() {
} }
@GET @GET
public Response getChangeOrders(@QueryParam("poNum") String poNum) public Response getChangeOrders(@QueryParam("poNum") String poNum, @QueryParam("sessionId") String sessionId)
throws AstuteException { throws AstuteException {
authService.getUser(sessionId);
return new ApiResponse(service.getChangeOrders(poNum)).toResponse(); return new ApiResponse(service.getChangeOrders(poNum)).toResponse();
} }

View File

@ -3,6 +3,7 @@ package com.astute.resources;
import com.astute.exceptions.AstuteException; import com.astute.exceptions.AstuteException;
import com.astute.requests.CustomerRequest; import com.astute.requests.CustomerRequest;
import com.astute.response.ApiResponse; import com.astute.response.ApiResponse;
import com.astute.service.AuthService;
import com.astute.service.CustomerService; import com.astute.service.CustomerService;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -16,6 +17,7 @@ import java.sql.SQLException;
public class CustomerResource { public class CustomerResource {
private com.astute.service.CustomerService service = new CustomerService(); private com.astute.service.CustomerService service = new CustomerService();
private com.astute.service.AuthService authService = new AuthService();
public CustomerResource() { public CustomerResource() {
} }
@ -23,6 +25,8 @@ public class CustomerResource {
@GET @GET
public Response getCustomers(@QueryParam("customerId") String customerId) public Response getCustomers(@QueryParam("customerId") String customerId)
throws AstuteException { throws AstuteException {
// TODO , @QueryParam("sessionId") String sessionId
// authService.getUser(sessionId);
return new ApiResponse(service.getCustomers(customerId)).toResponse(); return new ApiResponse(service.getCustomers(customerId)).toResponse();
} }

View File

@ -46,7 +46,14 @@ public class InvoicePaymentResource {
String dateStr = request.getPaymentDate(); String dateStr = request.getPaymentDate();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = new java.sql.Date(df.parse(dateStr).getTime()); Date date = new java.sql.Date(df.parse(dateStr).getTime());
service.createInvoicePayment(request.getInvoiceNum(), request.getInvoicePaymentId(), request.getInvoiceAmount(),date); service.createInvoicePayment(request.getInvoiceNum(), request.getPaymentTypeId(), request.getInvoiceAmount(),date);
return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse(); return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse();
} }
@GET
@Path("/paymentTypes")
public Response getInvoicePaymentTypes() throws AstuteException {
return new ApiResponse(service.getPaymentTypes()).toResponse();
}
} }

View File

@ -122,4 +122,12 @@ public class InvoiceResource {
public Response duplicateInvoice(@PathParam("InvoiceNumber") String InvoiceNumber) throws AstuteException { public Response duplicateInvoice(@PathParam("InvoiceNumber") String InvoiceNumber) throws AstuteException {
return new ApiResponse(service.dupliateInvoice(InvoiceNumber)).toResponse(); return new ApiResponse(service.dupliateInvoice(InvoiceNumber)).toResponse();
} }
@Path("/submitted")
@GET
public Response getSubmittedInvoiceNumbers() throws AstuteException {
System.out.println("In getSubmittedInvoiceNumbers");
return new ApiResponse(service.getSubmittedInvoiceNumbers()).toResponse();
}
} }

View File

@ -2,30 +2,29 @@ package com.astute.service;
import com.astute.exceptions.AstuteException; import com.astute.exceptions.AstuteException;
import com.astute.model.User;
import java.sql.SQLException; import java.sql.SQLException;
import static com.astute.dao.DAO.getDao; import static com.astute.dao.DAO.getDao;
import static com.astute.exceptions.AstuteException.AUTH_ERROR;
public class AuthService extends Service{ public class AuthService extends Service{
public AuthService(){ public AuthService(){
super(); super();
} }
public String login(String username, String password) public User login(String username, String password)
throws AstuteException { throws AstuteException {
return getDao().login(username,password); return getDao().login(username,password);
} }
public void updateCustomer( String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, String phone, String fax) public String getUser(String sessionId) throws AstuteException {
throws AstuteException { User user = getDao().getUser(sessionId);
getDao().updateCustomer(customerId, customerName,billToDept, add1, add2, city, state, zip, ziplast4, email, phone, fax); if (user == null) {
} throw new AstuteException(AUTH_ERROR, "Authentication Error. Please login first!");
}
return user.getUsername();
public void createCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, String phone, String fax)
throws AstuteException {
getDao().createCustomer(customerId, customerName,billToDept, add1, add2, city, state, zip, ziplast4, email, phone, fax);
} }
} }

View File

@ -2,6 +2,7 @@ package com.astute.service;
import com.astute.exceptions.AstuteException; import com.astute.exceptions.AstuteException;
import com.astute.model.InvoicePayment; import com.astute.model.InvoicePayment;
import com.astute.model.PaymentType;
import java.sql.Date; import java.sql.Date;
import java.util.List; import java.util.List;
@ -29,4 +30,7 @@ public class InvoicePaymentService extends Service{
getDao().createInvoicePayment(invoiceNum, invoicePaymentTypeId, paymentAmount, paymentDate); getDao().createInvoicePayment(invoiceNum, invoicePaymentTypeId, paymentAmount, paymentDate);
} }
public List<PaymentType> getPaymentTypes() throws AstuteException {
return getDao().getPaymentTypes();
}
} }

View File

@ -81,4 +81,9 @@ public class InvoiceService extends Service{
public List<PaymentStatus> getPaymentStatuses() throws AstuteException { public List<PaymentStatus> getPaymentStatuses() throws AstuteException {
return getDao().getPaymentStatuses(); return getDao().getPaymentStatuses();
} }
public List<Invoice> getSubmittedInvoiceNumbers() throws AstuteException {
return getDao().getSubmittedInvoiceNumbers();
}
} }