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