Adding delivery service.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.gempukku.lotro.collection;
|
||||
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class DeliveryService {
|
||||
private Map<String, Map<String, List<CardCollection.Item>>> _undeliveredDeliverables = new HashMap<String, Map<String, List<CardCollection.Item>>>();
|
||||
|
||||
private ReadWriteLock _deliveryLock = new ReentrantReadWriteLock(false);
|
||||
|
||||
public void addPackage(Player player, String collectionType, List<CardCollection.Item> items) {
|
||||
_deliveryLock.writeLock().lock();
|
||||
try {
|
||||
Map<String, List<CardCollection.Item>> playerDeliverables = _undeliveredDeliverables.get(player.getName());
|
||||
if (playerDeliverables == null) {
|
||||
playerDeliverables = new HashMap<String, List<CardCollection.Item>>();
|
||||
_undeliveredDeliverables.put(player.getName(), playerDeliverables);
|
||||
}
|
||||
List<CardCollection.Item> deliverablesInCollection = playerDeliverables.get(collectionType);
|
||||
if (deliverablesInCollection == null) {
|
||||
deliverablesInCollection = new LinkedList<CardCollection.Item>();
|
||||
playerDeliverables.put(collectionType, deliverablesInCollection);
|
||||
}
|
||||
deliverablesInCollection.addAll(items);
|
||||
} finally {
|
||||
_deliveryLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUndeliveredPackages(Player player) {
|
||||
_deliveryLock.readLock().lock();
|
||||
try {
|
||||
return _undeliveredDeliverables.containsKey(player.getName());
|
||||
} finally {
|
||||
_deliveryLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, List<CardCollection.Item>> consumePackages(Player player) {
|
||||
_deliveryLock.writeLock().lock();
|
||||
try {
|
||||
return _undeliveredDeliverables.remove(player.getName());
|
||||
} finally {
|
||||
_deliveryLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.collection.DeliveryService;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.DeckDAO;
|
||||
import com.gempukku.lotro.db.LeagueDAO;
|
||||
import com.gempukku.lotro.db.LeagueSerieDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.game.DefaultCardCollection;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.game.MutableCardCollection;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.game.*;
|
||||
import com.gempukku.lotro.hall.HallServer;
|
||||
import com.sun.jersey.spi.resource.Singleton;
|
||||
|
||||
@@ -26,6 +24,8 @@ public class AdminResource extends AbstractResource {
|
||||
@Context
|
||||
private CollectionDAO _collectionDao;
|
||||
@Context
|
||||
private DeliveryService _deliveryService;
|
||||
@Context
|
||||
private DeckDAO _deckDao;
|
||||
@Context
|
||||
private LeagueDAO _leagueDao;
|
||||
@@ -113,9 +113,14 @@ public class AdminResource extends AbstractResource {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
|
||||
MutableCardCollection baseCollection = league.getBaseCollection();
|
||||
|
||||
List<CardCollection.Item> items = new LinkedList<CardCollection.Item>();
|
||||
|
||||
List<String> packs = getPacks(packProduct);
|
||||
for (String pack : packs)
|
||||
for (String pack : packs) {
|
||||
baseCollection.addPacks(pack, 1);
|
||||
items.add(new CardCollection.Item(CardCollection.Item.Type.PACK, 1, pack));
|
||||
}
|
||||
_leagueDao.setBaseCollectionForLeague(league, baseCollection);
|
||||
|
||||
Map<Integer, MutableCardCollection> playerCollections = _collectionDao.getPlayerCollectionsByType(leagueType);
|
||||
@@ -126,6 +131,7 @@ public class AdminResource extends AbstractResource {
|
||||
collection.addPacks(pack, 1);
|
||||
Player player = _playerDao.getPlayer(playerId);
|
||||
_collectionDao.setCollectionForPlayer(player, leagueType, collection);
|
||||
_deliveryService.addPackage(player, leagueType, items);
|
||||
}
|
||||
|
||||
return "OK";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.collection.DeliveryService;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
@@ -31,6 +32,8 @@ public class CollectionResource extends AbstractResource {
|
||||
@Context
|
||||
private CollectionDAO _collectionDao;
|
||||
@Context
|
||||
private DeliveryService _deliveryService;
|
||||
@Context
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
@Context
|
||||
private LeagueService _leagueService;
|
||||
@@ -145,6 +148,8 @@ public class CollectionResource extends AbstractResource {
|
||||
MutableCardCollection modifiableColleciton = (MutableCardCollection) collection;
|
||||
|
||||
List<CardCollection.Item> packContents = modifiableColleciton.openPack(packId, _packStorage);
|
||||
_deliveryService.addPackage(resourceOwner, collectionType, packContents);
|
||||
|
||||
if (packContents == null)
|
||||
sendError(Response.Status.NOT_FOUND);
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.collection.DeliveryService;
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.core.spi.component.ComponentScope;
|
||||
import com.sun.jersey.spi.inject.Injectable;
|
||||
import com.sun.jersey.spi.inject.InjectableProvider;
|
||||
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@Provider
|
||||
public class DeliveryServiceProvider implements Injectable<DeliveryService>, InjectableProvider<Context, Type> {
|
||||
private DeliveryService _deliveryService;
|
||||
|
||||
@Override
|
||||
public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
|
||||
if (type.equals(DeliveryService.class))
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentScope getScope() {
|
||||
return ComponentScope.Singleton;
|
||||
}
|
||||
|
||||
private DeliveryService createDeliveryService() {
|
||||
return new DeliveryService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized DeliveryService getValue() {
|
||||
if (_deliveryService == null)
|
||||
_deliveryService = createDeliveryService();
|
||||
return _deliveryService;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user