use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method newRaid.
public Raid newRaid(User raidCreator, Raid raid, Guild guild, Config config, String rawMessage) {
RaidEntity raidEntity = getActiveOrFallbackToExRaidEntity(raid.getGym(), raid.getRegion());
if (raidEntity != null) {
if ((raidEntity.isExRaid() && !raid.isExRaid()) || (!raidEntity.isExRaid() && raid.isExRaid())) {
// This is a situation we should allow, in case Niantic now allows for raids to happen at EX gyms
} else {
throw new RaidExistsException(raidCreator, getRaidInstance(raidEntity), localeService, localeService.getLocaleForUser(raidCreator));
}
}
final Raid raidInstance = getRaidInstance(saveRaid(raidCreator, raid));
trackingService.notifyTrackers(guild, raidInstance, config, raidCreator, rawMessage);
return raidInstance;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method changePokemon.
public Raid changePokemon(Raid raid, Pokemon pokemon, Guild guild, Config config, User user, String rawMessage) {
RaidEntity raidEntity = getActiveOrFallbackToExRaidEntity(raid.getGym(), raid.getRegion());
if (!raidEntity.getPokemon().equalsIgnoreCase(raid.getPokemon().getName())) {
throw new IllegalStateException("Database issues. Please notify the developer: " + "magnus.mickelsson@gmail.com and describe what happened.");
}
raidEntity.setPokemon(pokemon.getName());
raidEntity = raidEntityRepository.save(raidEntity);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Changed pokemon for raid " + raid + " to " + pokemon + ".");
}
final Raid raidInstance = getRaidInstance(raidEntity);
trackingService.notifyTrackers(guild, raidInstance, config, user, rawMessage);
return raidInstance;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method deleteGroup.
public RaidGroup deleteGroup(String raidId, String groupId) {
final RaidEntity entity = findEntityByRaidId(raidId);
if (entity == null) {
return null;
}
final RaidGroup removedGroup = entity.removeGroup(groupId);
if (removedGroup == null) {
throw new RuntimeException("No group with ID " + groupId + " for raid " + entity);
}
return removedGroup;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method getGroups.
public Set<RaidGroup> getGroups(Raid raid) {
RaidEntity entity = findEntityByRaidId(raid.getId());
final Set<RaidGroup> groups = entity.getGroupsAsSet();
return groups;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidRepository method getActiveOrFallbackToExRaidEntity.
private RaidEntity getActiveOrFallbackToExRaidEntity(Gym gym, String region) {
RaidEntity raidEntity = null;
List<RaidEntity> raidEntities = raidEntityRepository.findByGymAndRegionOrderByEndOfRaidAsc(gym.getName(), region);
RaidEntity exEntity = null;
for (RaidEntity entity : raidEntities) {
if (entity.isExpired(clockService)) {
LOGGER.info("Removing expired raid: " + entity.getId());
raidEntityRepository.delete(entity);
} else if (Utils.isRaidExPokemon(entity.getPokemon())) {
exEntity = entity;
break;
} else {
if (raidEntity != null) {
throw new IllegalStateException("Raid state in database seems off. " + "Please notify the bot developer so it can be checked: " + raidEntity);
}
raidEntity = entity;
}
}
if (raidEntity == null) {
if (exEntity != null) {
raidEntity = exEntity;
}
}
return raidEntity;
}
Aggregations