- Adding base collections from leagues to CollectionsManager
This commit is contained in:
@@ -2,10 +2,12 @@ package com.gempukku.lotro.collection;
|
||||
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.PlayerDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
import com.gempukku.lotro.game.DefaultCardCollection;
|
||||
import com.gempukku.lotro.game.MutableCardCollection;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.league.LeagueService;
|
||||
import com.gempukku.lotro.packs.PacksStorage;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -17,10 +19,12 @@ public class CollectionsManager {
|
||||
|
||||
private PlayerDAO _playerDAO;
|
||||
private CollectionDAO _collectionDAO;
|
||||
private LeagueService _leagueService;
|
||||
|
||||
public CollectionsManager(PlayerDAO playerDAO, CollectionDAO collectionDAO) {
|
||||
public CollectionsManager(PlayerDAO playerDAO, CollectionDAO collectionDAO, LeagueService leagueService) {
|
||||
_playerDAO = playerDAO;
|
||||
_collectionDAO = collectionDAO;
|
||||
_leagueService = leagueService;
|
||||
}
|
||||
|
||||
public void clearDBCache() {
|
||||
@@ -33,6 +37,11 @@ public class CollectionsManager {
|
||||
final CardCollection collection = _collectionDAO.getCollectionForPlayer(player.getId(), collectionType);
|
||||
if (collection == null && collectionType.equals("permanent"))
|
||||
return new DefaultCardCollection();
|
||||
if (collection == null) {
|
||||
final League league = _leagueService.getLeagueByType(collectionType);
|
||||
if (league != null)
|
||||
return league.getBaseCollection();
|
||||
}
|
||||
return collection;
|
||||
} finally {
|
||||
_readWriteLock.readLock().unlock();
|
||||
|
||||
@@ -89,10 +89,6 @@ public class HallServer extends AbstractServer {
|
||||
return Collections.unmodifiableMap(_supportedFormats);
|
||||
}
|
||||
|
||||
public Set<League> getRunningLeagues() {
|
||||
return _leagueService.getActiveLeagues();
|
||||
}
|
||||
|
||||
private void cancelWaitingTables() {
|
||||
_hallDataAccessLock.writeLock().lock();
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gempukku.lotro.league;
|
||||
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.LeagueDAO;
|
||||
import com.gempukku.lotro.db.LeagueMatchDAO;
|
||||
import com.gempukku.lotro.db.LeaguePointsDAO;
|
||||
@@ -8,7 +7,7 @@ import com.gempukku.lotro.db.LeagueSerieDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.db.vo.LeagueMatch;
|
||||
import com.gempukku.lotro.db.vo.LeagueSerie;
|
||||
import com.gempukku.lotro.game.*;
|
||||
import com.gempukku.lotro.game.LotroGameMediator;
|
||||
import com.gempukku.lotro.logic.timing.GameResultListener;
|
||||
|
||||
import java.util.*;
|
||||
@@ -18,35 +17,18 @@ public class LeagueService {
|
||||
private LeagueSerieDAO _leagueSeasonDao;
|
||||
private LeaguePointsDAO _leaguePointsDao;
|
||||
private LeagueMatchDAO _leagueMatchDao;
|
||||
private CollectionsManager _collectionsManager;
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
|
||||
public LeagueService(LeagueDAO leagueDao, LeagueSerieDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao, CollectionsManager collectionsManager, LotroCardBlueprintLibrary library) {
|
||||
public LeagueService(LeagueDAO leagueDao, LeagueSerieDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao) {
|
||||
_leagueDao = leagueDao;
|
||||
_leagueSeasonDao = leagueSeasonDao;
|
||||
_leaguePointsDao = leaguePointsDao;
|
||||
_leagueMatchDao = leagueMatchDao;
|
||||
_collectionsManager = collectionsManager;
|
||||
_library = library;
|
||||
}
|
||||
|
||||
public Set<League> getActiveLeagues() {
|
||||
return _leagueDao.getActiveLeagues();
|
||||
}
|
||||
|
||||
public CardCollection getLeagueCollection(Player player, League league) {
|
||||
final CardCollection collectionForPlayer = _collectionsManager.getPlayerCollection(player, league.getType());
|
||||
if (collectionForPlayer == null) {
|
||||
DefaultCardCollection collection = new DefaultCardCollection();
|
||||
|
||||
MutableCardCollection baseCollection = league.getBaseCollection();
|
||||
for (CardCollection.Item item : baseCollection.getItems(null, _library))
|
||||
collection.addItem(item.getBlueprintId(), item.getCount());
|
||||
return collection;
|
||||
}
|
||||
return collectionForPlayer;
|
||||
}
|
||||
|
||||
public League getLeagueByType(String type) {
|
||||
for (League league : getActiveLeagues()) {
|
||||
if (league.getType().equals(type))
|
||||
|
||||
@@ -134,17 +134,10 @@ public class CollectionResource extends AbstractResource {
|
||||
}
|
||||
|
||||
private CardCollection getCollection(Player player, String collectionType) {
|
||||
CardCollection collection = null;
|
||||
if (collectionType.equals("default"))
|
||||
collection = _lotroServer.getDefaultCollection();
|
||||
else if (collectionType.equals("permanent")) {
|
||||
collection = _collectionsManager.getPlayerCollection(player, "permanent");
|
||||
} else {
|
||||
League league = _leagueService.getLeagueByType(collectionType);
|
||||
if (league != null)
|
||||
collection = _leagueService.getLeagueCollection(player, league);
|
||||
}
|
||||
return collection;
|
||||
return _lotroServer.getDefaultCollection();
|
||||
else
|
||||
return _collectionsManager.getPlayerCollection(player, collectionType);
|
||||
}
|
||||
|
||||
@Path("/{collectionType}")
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.PlayerDAO;
|
||||
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 CollectionsManagerProvider implements InjectableProvider<Context, Type> {
|
||||
private Injectable<CollectionsManager> _collectionsManagerInjectable;
|
||||
|
||||
@Context
|
||||
private PlayerDAO _playerDao;
|
||||
@Context
|
||||
private CollectionDAO _collectionDao;
|
||||
|
||||
@Override
|
||||
public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
|
||||
if (type.equals(CollectionsManager.class))
|
||||
return getCollectionsManagerInjectable();
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized Injectable<CollectionsManager> getCollectionsManagerInjectable() {
|
||||
if (_collectionsManagerInjectable == null) {
|
||||
final CollectionsManager collectionsManager = new CollectionsManager(_playerDao, _collectionDao);
|
||||
_collectionsManagerInjectable = new Injectable<CollectionsManager>() {
|
||||
@Override
|
||||
public CollectionsManager getValue() {
|
||||
return collectionsManager;
|
||||
}
|
||||
};
|
||||
}
|
||||
return _collectionsManagerInjectable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentScope getScope() {
|
||||
return ComponentScope.Singleton;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.db.vo.LeagueSerie;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.lotro.hall.HallException;
|
||||
import com.gempukku.lotro.hall.HallInfoVisitor;
|
||||
import com.gempukku.lotro.hall.HallServer;
|
||||
import com.gempukku.lotro.league.LeagueService;
|
||||
import com.sun.jersey.spi.resource.Singleton;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
@@ -26,6 +28,8 @@ import java.util.Set;
|
||||
public class HallResource extends AbstractResource {
|
||||
@Context
|
||||
private HallServer _hallServer;
|
||||
@Context
|
||||
private LeagueService _leagueService;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@@ -52,11 +56,14 @@ public class HallResource extends AbstractResource {
|
||||
formatElem.appendChild(doc.createTextNode(format.getValue().getName()));
|
||||
hall.appendChild(formatElem);
|
||||
}
|
||||
for (League league : _hallServer.getRunningLeagues()) {
|
||||
Element formatElem = doc.createElement("format");
|
||||
formatElem.setAttribute("type", league.getType());
|
||||
formatElem.appendChild(doc.createTextNode(league.getName()));
|
||||
hall.appendChild(formatElem);
|
||||
for (League league : _leagueService.getActiveLeagues()) {
|
||||
final LeagueSerie currentLeagueSerie = _leagueService.getCurrentLeagueSerie(league);
|
||||
if (currentLeagueSerie != null) {
|
||||
Element formatElem = doc.createElement("format");
|
||||
formatElem.setAttribute("type", league.getType());
|
||||
formatElem.appendChild(doc.createTextNode(league.getName()));
|
||||
hall.appendChild(formatElem);
|
||||
}
|
||||
}
|
||||
|
||||
doc.appendChild(hall);
|
||||
|
||||
@@ -22,10 +22,15 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
||||
private Injectable<LeagueService> _leagueServerInjectable;
|
||||
private Injectable<HallServer> _hallServerInjectable;
|
||||
private Injectable<LotroServer> _lotroServerInjectable;
|
||||
private Injectable<CollectionsManager> _collectionsManagerInjectable;
|
||||
|
||||
@Context
|
||||
private PlayerDAO _playerDao;
|
||||
@Context
|
||||
private DeckDAO _deckDao;
|
||||
@Context
|
||||
private CollectionDAO _collectionDao;
|
||||
@Context
|
||||
private LeagueDAO _leagueDao;
|
||||
@Context
|
||||
private LeagueSerieDAO _leagueSeasonDao;
|
||||
@@ -34,8 +39,6 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
||||
@Context
|
||||
private LeaguePointsDAO _leaguePointsDao;
|
||||
@Context
|
||||
private CollectionsManager _collectionsManager;
|
||||
@Context
|
||||
private GameHistoryDAO _gameHistoryDao;
|
||||
@Context
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
@@ -50,12 +53,14 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
||||
return getHallServerInjectable();
|
||||
if (type.equals(LeagueService.class))
|
||||
return getLeagueServiceInjectable();
|
||||
if (type.equals(CollectionsManager.class))
|
||||
return getCollectionsManagerInjectable();
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized Injectable<LeagueService> getLeagueServiceInjectable() {
|
||||
if (_leagueServerInjectable == null) {
|
||||
final LeagueService leagueService = new LeagueService(_leagueDao, _leagueSeasonDao, _leaguePointsDao, _leagueMatchDao, _collectionsManager, _library);
|
||||
final LeagueService leagueService = new LeagueService(_leagueDao, _leagueSeasonDao, _leaguePointsDao, _leagueMatchDao);
|
||||
_leagueServerInjectable = new Injectable<LeagueService>() {
|
||||
@Override
|
||||
public LeagueService getValue() {
|
||||
@@ -68,7 +73,7 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
||||
|
||||
private synchronized Injectable<HallServer> getHallServerInjectable() {
|
||||
if (_hallServerInjectable == null) {
|
||||
final HallServer hallServer = new HallServer(getLotroServerInjectable().getValue(), getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(), _library, _collectionsManager, false);
|
||||
final HallServer hallServer = new HallServer(getLotroServerInjectable().getValue(), getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(), _library, getCollectionsManagerInjectable().getValue(), false);
|
||||
hallServer.startServer();
|
||||
_hallServerInjectable = new Injectable<HallServer>() {
|
||||
@Override
|
||||
@@ -108,6 +113,19 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
|
||||
return _chatServerInjectable;
|
||||
}
|
||||
|
||||
private synchronized Injectable<CollectionsManager> getCollectionsManagerInjectable() {
|
||||
if (_collectionsManagerInjectable == null) {
|
||||
final CollectionsManager collectionsManager = new CollectionsManager(_playerDao, _collectionDao, getLeagueServiceInjectable().getValue());
|
||||
_collectionsManagerInjectable = new Injectable<CollectionsManager>() {
|
||||
@Override
|
||||
public CollectionsManager getValue() {
|
||||
return collectionsManager;
|
||||
}
|
||||
};
|
||||
}
|
||||
return _collectionsManagerInjectable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentScope getScope() {
|
||||
return ComponentScope.Singleton;
|
||||
|
||||
Reference in New Issue
Block a user