Skip to content

Commit

Permalink
Customer Module Added
Browse files Browse the repository at this point in the history
  • Loading branch information
cooligc committed Aug 29, 2015
1 parent 9692ca9 commit 3c4782a
Show file tree
Hide file tree
Showing 49 changed files with 2,034 additions and 15 deletions.
33 changes: 33 additions & 0 deletions TicketBookingSystem/booking-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
</parent>
<artifactId>booking-core</artifactId>
<name>Booking Core App</name>
<packaging>jar</packaging>
<description>Booking Core App</description>
<dependencies>

<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
Expand Down Expand Up @@ -54,6 +60,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -151,5 +161,28 @@
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<!-- Hibernate and JPA Dependency -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<classifier>tests</classifier>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.ticketbooking.core.api.config;

import javax.ws.rs.ApplicationPath;

import org.apache.log4j.Logger;
import org.glassfish.jersey.server.ResourceConfig;
import org.ticketbooking.core.api.web.CheckBookingStatus;

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

@ApplicationPath("/api")
public class ApiApplicationConfig extends ResourceConfig{
//@ApplicationPath("/api/*")
public class ApiApplicationConfig extends ResourceConfig {
private final static Logger LOGGER = Logger.getLogger(ApiApplicationConfig.class);

public ApiApplicationConfig() {
LOGGER.info("Api going to start");
register("org.ticketbooking.core.api.web");
packages("org.ticketbooking.core.api.web");
register(JacksonJaxbJsonProvider.class);
registerClasses(CheckBookingStatus.class);
LOGGER.info("Api started");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.ticketbooking.core.api.jaxb.other;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "links")
public class Links {
private String relationType;
private String url;

public Links(String relationType, String url) {
super();
this.relationType = relationType;
this.url = url;
}
public Links() {}

@XmlElement(name="rel")
public String getRelationType() {
return relationType;
}
public void setRelationType(String relationType) {
this.relationType = relationType;
}
@XmlElement(name="_href")
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.ticketbooking.core.api.jaxb.user;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="addresses")
public class Address {
private String street1;
private String street2;
private String state;
private String country;
private Long pin;

@XmlElement(name="street1")
public String getStreet1() {
return street1;
}
public void setStreet1(String street1) {
this.street1 = street1;
}

@XmlElement(name="street2")
public String getStreet2() {
return street2;
}
public void setStreet2(String street2) {
this.street2 = street2;
}
@XmlElement(name="state")
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
@XmlElement(name="country")
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@XmlElement(name="pin")
public Long getPin() {
return pin;
}
public void setPin(Long pin) {
this.pin = pin;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.ticketbooking.core.api.jaxb.user;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import org.ticketbooking.core.api.jaxb.other.Links;


@XmlRootElement(name="user")
public class UserDetails {

private String userName;
private String password;
private String firstName;
private String middleName;
private String lastName;
private String email;
private String phone;
private List<Address> addresses;
private List<Links> links;

@XmlElement(name="username")
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
// @XmlElement(name="password")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@XmlElement(name="firstname")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@XmlElement(name="middlename")
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
@XmlElement(name="lastname")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@XmlElement(name="email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@XmlElement(name="phone")
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@XmlElementWrapper
@XmlElement(name="address")
public List<Address> getAddresses() {
return addresses;
}
public void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}
@XmlElementWrapper
@XmlElement(name="link")
public List<Links> getLinks() {
return links;
}
public void setLinks(List<Links> links) {
this.links = links;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CheckBookingStatus {

@GET
public Response checkBooking(){
System.out.println("Ser");
LOGGER.info("CheckBookingStatus - started");
return Response.status(Status.ACCEPTED)
.entity("App is up")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.ticketbooking.core.api.web.customer;

import javax.annotation.Resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.springframework.stereotype.Service;
import org.ticketbooking.core.api.jaxb.user.UserDetails;
import org.ticketbooking.core.domain.user.Customer;
import org.ticketbooking.core.domain.user.CustomerImpl;
import org.ticketbooking.core.helper.AddressHelper;
import org.ticketbooking.core.service.customer.CustomerService;

@Path("/user")
@Service("apiCustomer")
public class CusomerApiServiceImpl implements CustomerApiService{

@Resource(name="customerService")
CustomerService customerService;

@Resource(name="addressHelper")
AddressHelper addressHelper;

@POST
@Produces(value={MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Consumes(value={MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public Response createCustomer(UserDetails userDetails) {

Customer customer = new CustomerImpl();
customer.setUsername(userDetails.getUserName());
customer.setFirstName(userDetails.getFirstName());
customer.setLastName(userDetails.getLastName());
customer.setMiddleName(userDetails.getMiddleName());
customer.setEmail(userDetails.getEmail());
customer.setPhone(userDetails.getPhone());
customer.setPassword(userDetails.getPassword());
customer.setAddresses(addressHelper.convertAddressEntity(userDetails.getAddresses()));
customer.setUsername(userDetails.getUserName());
customer.setUsername(userDetails.getUserName());
customerService.createCustomer(customer);

return Response.status(Status.CREATED).header("X-header-message", "User created").build();
}

@Path("/{username}")
@PUT
@Produces(value={MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Consumes(value={MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public Response updateCustomer(UserDetails details) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.ticketbooking.core.api.web.customer;

import javax.ws.rs.core.Response;

import org.ticketbooking.core.api.jaxb.user.UserDetails;

public interface CustomerApiService {
Response createCustomer(UserDetails details);
Response updateCustomer(UserDetails details);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ticketbooking.core.dao.address;

import java.util.List;

import org.ticketbooking.core.domain.user.AddressImpl;

public interface AddressDao {
void createAddress(AddressImpl address);
void deleteAddress(Long id);
AddressImpl fetchAddress(Long id);
List<AddressImpl> fetchAddressByCustomer(Long customerId);
void updateAddress(AddressImpl address);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.ticketbooking.core.dao.address;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.ticketbooking.core.domain.user.AddressImpl;

@Repository("addressDao")
public class AddressDaoImpl implements AddressDao{

@PersistenceContext
EntityManager entityManager;

public void createAddress(AddressImpl address) {
entityManager.persist(address);
}

public void deleteAddress(Long id) {
AddressImpl address = fetchAddress(id);
entityManager.remove(address);
}

public AddressImpl fetchAddress(Long id) {
return entityManager.find(AddressImpl.class, id);
}

@SuppressWarnings("unchecked")
public List<AddressImpl> fetchAddressByCustomer(Long customerId) {
Query query = entityManager.createNamedQuery("AddressImpl.fetchByCustomer");
query.setParameter("id", customerId);
return query.getResultList();
}

public void updateAddress(AddressImpl address) {
entityManager.merge(address);
}

}
Loading

0 comments on commit 3c4782a

Please sign in to comment.