Skip to content

Commit

Permalink
Entire Customer Module Integrated and Swagger also Intgrated
Browse files Browse the repository at this point in the history
  • Loading branch information
cooligc committed Sep 3, 2015
1 parent 3c4782a commit ae20ff3
Show file tree
Hide file tree
Showing 29 changed files with 581 additions and 159 deletions.
5 changes: 5 additions & 0 deletions TicketBookingSystem/booking-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,10 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<!-- Swwagger -->
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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/*")
@ApplicationPath("/api/*")
public class ApiApplicationConfig extends ResourceConfig {
private final static Logger LOGGER = Logger.getLogger(ApiApplicationConfig.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.ticketbooking.core.api.jaxb.other.Links;



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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ticketbooking.core.api.web.customer;

import java.util.Set;

import javax.annotation.Resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
Expand All @@ -12,25 +14,33 @@

import org.springframework.stereotype.Service;
import org.ticketbooking.core.api.jaxb.user.UserDetails;
import org.ticketbooking.core.domain.user.AddressImpl;
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;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Api(value="CustomerDetails",description="Service to get the details about Customer")
@Path("/user")
@Service("apiCustomer")
public class CusomerApiServiceImpl implements CustomerApiService{
public class CusomerApiServiceImpl implements CustomerApiService{

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

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


@ApiOperation(httpMethod="POST",value="To create a customer")
@POST
@Produces(value={MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Consumes(value={MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public Response createCustomer(UserDetails userDetails) {
public Response createCustomer(@ApiParam(name="userDetails",value="XML/JSON for creating user")UserDetails userDetails) {

Customer customer = new CustomerImpl();
customer.setUsername(userDetails.getUserName());
Expand All @@ -40,11 +50,11 @@ public Response createCustomer(UserDetails userDetails) {
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);

Set<AddressImpl> address = addressHelper.convertAddressEntity(userDetails.getAddresses());
//TODO Logic to be changed
addressHelper.createCustomerAddress(customer,address.iterator().next());
return Response.status(Status.CREATED).header("X-header-message", "User created").build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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);
//List<AddressImpl> fetchAddressByCustomer(Long customerId);
void updateAddress(AddressImpl address);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
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;
Expand All @@ -28,12 +25,12 @@ public AddressImpl fetchAddress(Long id) {
return entityManager.find(AddressImpl.class, id);
}

@SuppressWarnings("unchecked")
/*@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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.ticketbooking.core.dao.customer.address;

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



public interface CustomerAddressDao{
void createCustomerAddress(CustomerAddressImpl customerAddress);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.ticketbooking.core.dao.customer.address;

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

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

@Repository("customerAddressDao")
public class CustomerAddressDaoImpl implements CustomerAddressDao{

@PersistenceContext
EntityManager entityManager;

public void createCustomerAddress(CustomerAddressImpl customerAddress){
entityManager.persist(customerAddress);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.ticketbooking.core.domain.common.audit;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Embeddable
public class Auditable implements Serializable{

/**
*
*/
private static final long serialVersionUID = -2384592094387880727L;

@Column(name="TBS_CREATED_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;

@Column(name="TBS_UPDATED_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdatedDate;

public Date getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}

public Date getLastUpdatedDate() {
return lastUpdatedDate;
}

public void setLastUpdatedDate(Date lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}

@Override
public String toString() {
return "Auditable [createdDate=" + createdDate + ", lastUpdatedDate="
+ lastUpdatedDate + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((createdDate == null) ? 0 : createdDate.hashCode());
result = prime * result
+ ((lastUpdatedDate == null) ? 0 : lastUpdatedDate.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Auditable other = (Auditable) obj;
if (createdDate == null) {
if (other.createdDate != null)
return false;
} else if (!createdDate.equals(other.createdDate))
return false;
if (lastUpdatedDate == null) {
if (other.lastUpdatedDate != null)
return false;
} else if (!lastUpdatedDate.equals(other.lastUpdatedDate))
return false;
return true;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.ticketbooking.core.domain.common.listener;

import java.lang.reflect.Field;
import java.util.Date;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import org.ticketbooking.core.domain.common.audit.Auditable;

public class AuditableListener {

@PrePersist
public void setAuditableFieldforCreate(Object entity) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
if (entity.getClass().isAnnotationPresent(Entity.class)) {
Field field = getSingleField(entity.getClass(), "auditable");
field.setAccessible(true);
if (field.isAnnotationPresent(Embedded.class)) {
Object auditable = field.get(entity);
if (auditable == null) {
field.set(entity, new Auditable());
auditable = field.get(entity);
}
Field temporalField = auditable.getClass().getDeclaredField("createdDate");
Field agentField = auditable.getClass().getDeclaredField("lastUpdatedDate");
setAuditValueTemporal(temporalField, auditable);
setAuditValueTemporal(agentField, auditable);
}
}
}

@PreUpdate
public void setAuditableFieldForUdate(Object entity) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException{
if (entity.getClass().isAnnotationPresent(Entity.class)) {
Field field = getSingleField(entity.getClass(), "auditable");
field.setAccessible(true);
if (field.isAnnotationPresent(Embedded.class)) {
Object auditable = field.get(entity);
if (auditable == null) {
field.set(entity, new Auditable());
auditable = field.get(entity);
}
Field agentField = auditable.getClass().getDeclaredField("lastUpdatedDate");
setAuditValueTemporal(agentField, auditable);
}
}
}


private void setAuditValueTemporal(Field temporalField, Object auditable) throws IllegalArgumentException, IllegalAccessException {
temporalField.setAccessible(true);
temporalField.set(auditable, new Date());
}

private Field getSingleField(Class<?> clazz, String fieldName)
throws IllegalStateException {
try {
return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException nsf) {
// Try superclass
if (clazz.getSuperclass() != null) {
return getSingleField(clazz.getSuperclass(), fieldName);
}

return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.ticketbooking.core.domain.user;

import java.util.Date;
import java.io.Serializable;

public interface Address {
public interface Address extends Serializable{
public Long getId();
public void setId(Long id);
public String getStreet1();
Expand All @@ -11,13 +11,10 @@ public interface Address {
public void setStree2(String stree2);
public Long getPin();
public void setPin(Long pin);
public Date getCreatedDate();
public void setCreatedDate(Date createdDate);
public Date getUpdatedDate();
public void setUpdatedDate(Date updatedDate);
public State getState();
public void setState(StateImpl state);
public Customer getCustomer();
public void setCustomer(CustomerImpl customer);

public boolean isDefaultAddress();
public void setDefaultAddress(boolean isDefaultAddress);
public boolean isActiveAddress();
public void setActiveAddress(boolean isActiveAddress);
}
Loading

0 comments on commit ae20ff3

Please sign in to comment.