Skip to content

Commit

Permalink
issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadR committed May 1, 2014
1 parent 56b596a commit e80dca7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import com.nice.coffee.types.TimedUserOrder;
import com.nice.coffee.types.UserOrder;

//@Component
@Component
public class OrdersRepositoryImpl implements OrdersRepository
{

private static Logger log = Logger.getLogger(OrdersRepositoryImpl.class);
private static final String USERNAME_NAME = "username";
private static final String ORDER__DATE_NAME = "Order";
private static final String ORDER_DATE_NAME = "Order";

private static final String USER_DB_KIND = "User";

Expand All @@ -32,7 +32,7 @@ public OrdersRepositoryImpl()

public UserOrder updateUserOrder(UserOrder userOrder)
{
log.info("storing the user's order: " + userOrder);
log.debug("storing the user's order: " + userOrder);

Entity dbUser = getUserEntity( userOrder.getEmail() );

Expand All @@ -50,7 +50,7 @@ public UserOrder updateUserOrder(UserOrder userOrder)
{
dbUser.setProperty(entry.getKey(), entry.getValue());
}
dbUser.setProperty(ORDER__DATE_NAME, new Date( System.currentTimeMillis()) );
dbUser.setProperty(ORDER_DATE_NAME, new Date( System.currentTimeMillis()) );

datastore.put(dbUser);

Expand All @@ -59,24 +59,36 @@ public UserOrder updateUserOrder(UserOrder userOrder)

public List<TimedUserOrder> getAllUsersOrder()
{
return new ArrayList<TimedUserOrder>();
log.debug("getAllUserOrder");
Query q = new Query(USER_DB_KIND);
PreparedQuery pq = datastore.prepare(q);

List<TimedUserOrder> retVal = new ArrayList<TimedUserOrder>();

/* Key userKey = KeyFactory.createKey(USER_DB_KIND, username);
Entity entity;
try
{
entity = datastore.get(userKey);
log.debug("got entity of " + username + ": " + entity);
}
catch (EntityNotFoundException e)
{
log.error("entity of " + username + " not found");
throw new UsernameNotFoundException(username, e);
StringBuffer sb = new StringBuffer();
for (Entity result : pq.asIterable()) {
String username = (String) result.getProperty(USERNAME_NAME);
Date date = (Date) result.getProperty(ORDER_DATE_NAME);
Map<String, Integer> order = new HashMap<String, Integer>();
//TODO: insert items from DS to order obj.
TimedUserOrder tuo = new TimedUserOrder(username, order, date);
retVal.add(tuo);
sb.append(username + " : " + date );
}
*/ }

log.info( sb.toString() );

public void removeUsersOrders(List<UserOrder> usersToRemove) {
// TODO Auto-generated method stub
return retVal;
}

public void removeUsersOrders(List<UserOrder> usersToRemove)
{
for(UserOrder userOrder : usersToRemove)
{
Key userKey = KeyFactory.createKey(USER_DB_KIND, userOrder.getEmail());
log.info( "deleting user " + userOrder.getEmail());
datastore.delete(userKey);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.*;
import java.util.Map.Entry;

@Component
public class OrdersRepositoryInMemoryImpl implements OrdersRepository {
private static Logger log = Logger.getLogger(OrdersRepositoryInMemoryImpl.class);
final private static Map<String, TimedUserOrder> inMemoryCache = new HashMap<String, TimedUserOrder>();
Expand Down

0 comments on commit e80dca7

Please sign in to comment.