Skip to content

Commit

Permalink
Updated shipping app and changed order's REST service model
Browse files Browse the repository at this point in the history
  • Loading branch information
azzazzel committed Mar 15, 2015
1 parent 4c96f94 commit 4324c4c
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 58 deletions.
10 changes: 10 additions & 0 deletions dukes-shipment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<name>dukes-shipment</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>usecases-identity</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jpa-persistence</artifactId>
Expand All @@ -25,5 +30,10 @@
<artifactId>dukes-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>events</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,43 @@
*/
package com.forest.shipment.session;

import com.forest.entity.CustomerEntity;
import com.forest.entity.PersonEntity;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.forest.entity.CustomerEntity;
import com.forest.model.Customer;
import com.forest.persitence.jpa.PersonPersistenceJPA;
import com.forest.usecase.identity.AbstractBasePersonManager;
import com.forest.usecase.identity.persistence.PersonPersistence;

/**
*
* @author markito
*/
@Stateless
public class UserBean extends AbstractFacade<CustomerEntity> {

@PersistenceContext(unitName="forestPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
public class UserBean extends AbstractBasePersonManager {

@PersistenceContext(unitName="forestPU")
private EntityManager entityManager;

public PersonEntity getUserByEmail(String email) {
Query createNamedQuery = getEntityManager().createNamedQuery("Person.findByEmail");

createNamedQuery.setParameter("email", email);

return (PersonEntity) createNamedQuery.getSingleResult();
}
private PersonPersistenceJPA personPersistance = new PersonPersistenceJPA();

public UserBean() {
super(CustomerEntity.class);

@PostConstruct
public void init() {
personPersistance.setEntityManager(entityManager);
}

public Customer newCustomerInstance() {
return new CustomerEntity();
}

@Override
protected PersonPersistence getPersonPersistence() {
return personPersistance;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.forest.events.OrderEvent;
import com.forest.model.CustomerOrder;
import com.forest.shipment.ejb.OrderBrowser;

Expand Down Expand Up @@ -69,47 +70,30 @@ public void setOrders(Map<String, CustomerOrder> orders) {
this.orders = orders;
}

public enum Status {

PENDING_PAYMENT(2),
READY_TO_SHIP(3),
SHIPPED(4),
CANCELLED_PAYMENT(5),
CANCELLED_MANUAL(6);
private int status;

private Status(final int pStatus) {
status = pStatus;
}

public int getStatus() {
return status;
}
}

public String getEndpoint() {
public String getEndpoint() {
return SERVICE_ENDPOINT;
}

public List<CustomerOrder> listByStatus(final Status status) {
List<CustomerOrder> entity = (List<CustomerOrder>) client.target(SERVICE_ENDPOINT)
.queryParam("status", String.valueOf(status.getStatus()))
public List<OrderEvent> listByStatus(final int status) {
List<OrderEvent> entity = (List<OrderEvent>) client.target(SERVICE_ENDPOINT)
.queryParam("status", String.valueOf(status))
.request(MEDIA_TYPE)
.get(new GenericType<List<CustomerOrder>>() {
.get(new GenericType<List<OrderEvent>>() {
});


return entity;
}

public void updateOrderStatus(final String messageID, final Status status) {
public void updateOrderStatus(final String messageID, final String status) {
// consume message
CustomerOrder order = orderBrowser.processOrder(messageID);

// call order service to update db in Store
Response response = client.target(SERVICE_ENDPOINT)
.path("/" + order.getId())
.path("/shipping/" + order.getId())
.request(MEDIA_TYPE)
.put(Entity.text(String.valueOf(status.getStatus())));
.put(Entity.text(String.valueOf(status)));

logger.log(Level.FINEST, "PUT Status response: {0}", response.getStatus());
}
Expand All @@ -129,7 +113,7 @@ public List<String> getPendingOrders() {
}
}

public List<CustomerOrder> getCompletedOrders() {
return listByStatus(Status.SHIPPED);
public List<OrderEvent> getCompletedOrders() {
return listByStatus(4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -38,8 +37,6 @@ public class UserController implements Serializable {

private static final long serialVersionUID = -7440104826420270291L;

@Inject
ShippingBean adapter;

Person user;
@EJB
Expand All @@ -59,7 +56,7 @@ public String login() {
request.login(this.getUsername(), this.getPassword());


this.user = ejbFacade.getUserByEmail(getUsername());
this.user = ejbFacade.getPersonByEmail(getUsername());
this.getAuthenticatedUser();

if (isAdmin(user)) {
Expand Down
6 changes: 3 additions & 3 deletions dukes-shipment/src/main/webapp/admin/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<div id="option">
<h:commandButton value="Approve" action="#{shippingBean.updateOrderStatus(key, 'SHIPPED')}" />
<h:commandButton value="Deny" action="#{shippingBean.updateOrderStatus(key, 'CANCELLED_MANUAL')}" />
<h:commandButton value="Deny" action="#{shippingBean.updateOrderStatus(key, 'CANCELLED')}" />
</div>
</li>
</h:column>
Expand All @@ -74,10 +74,10 @@
<h:column>
<li>
<h:outputLabel for="id" value="#{bundle.ViewCustomerOrderLabel_id} "/>
<h:outputText id="id" value="#{item.id}"/><br />
<h:outputText id="id" value="#{item.orderID}"/><br />

<h:outputLabel for="customer" value="#{bundle.ViewCustomerLabel_name}"/>
<h:outputText id="customer" value="#{item.customer.firstname} #{item.customer.lastname}"/><br />
<h:outputText id="customer" value="#{item.customerName}"/><br />

<h:outputLabel for="total" value="#{bundle.ViewCustomerOrderLabel_amount}"/>
<h:outputText id="total" value="#{item.amount}">
Expand Down
18 changes: 16 additions & 2 deletions dukes-store/src/main/java/com/forest/ejb/OrderBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.forest.ejb;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.annotation.PostConstruct;
Expand All @@ -25,6 +26,7 @@
import com.forest.entity.CustomerOrderEntity;
import com.forest.entity.OrderDetailEntity;
import com.forest.entity.OrderDetailPKEntity;
import com.forest.events.OrderEvent;
import com.forest.model.CustomerOrder;
import com.forest.model.OrderDetail;
import com.forest.persitence.jpa.OrderPersistenceJPA;
Expand Down Expand Up @@ -117,8 +119,20 @@ protected ShippingProvider getShippingProvider() {

@GET
@Produces({ "application/xml", "application/json" })
public List<CustomerOrder> getOrderByStatus(@QueryParam("status") int status) {
return super.getOrderByStatus(status);
public List<OrderEvent> getOrderEventsByStatus(@QueryParam("status") int status) {

List<OrderEvent> result = new LinkedList<OrderEvent>();
for (CustomerOrder customerOrder: super.getOrderByStatus(status)) {
OrderEvent orderEvent = new OrderEvent();
orderEvent.setAmount(customerOrder.getAmount());
orderEvent.setCustomerID(customerOrder.getCustomer().getId());
orderEvent.setDateCreated(customerOrder.getDateCreated());
orderEvent.setOrderID(customerOrder.getId());
orderEvent.setStatusID(customerOrder.getOrderStatus().getId());
result.add(orderEvent);
}

return result;
}

@PUT
Expand Down
11 changes: 10 additions & 1 deletion events/src/main/java/com/forest/events/OrderEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class OrderEvent implements Serializable {
private double amount;
private Date dateCreated;
private int customerID;
private int orderID;
private String customerName;
private int orderID;
private int statusID;

public int getCustomerID() {
Expand Down Expand Up @@ -69,6 +70,14 @@ public void setAmount(double amount) {
this.amount = amount;
}

public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {
this.customerName = customerName;
}

public String toString() {
return "[OrderEvent] " + getCustomerID();
}
Expand Down

0 comments on commit 4324c4c

Please sign in to comment.