Search in sources :

Example 1 with RaidEntity

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;
}
Also used : RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) RaidExistsException(pokeraidbot.domain.errors.RaidExistsException)

Example 2 with RaidEntity

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;
}
Also used : RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 3 with RaidEntity

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;
}
Also used : RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 4 with RaidEntity

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;
}
Also used : RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 5 with RaidEntity

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;
}
Also used : RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Aggregations

RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)25 RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)9 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)4 LocalTime (java.time.LocalTime)3 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Guild (net.dv8tion.jda.core.entities.Guild)1 User (net.dv8tion.jda.core.entities.User)1 RaidExistsException (pokeraidbot.domain.errors.RaidExistsException)1 RaidNotFoundException (pokeraidbot.domain.errors.RaidNotFoundException)1 Gym (pokeraidbot.domain.gym.Gym)1 SignUp (pokeraidbot.domain.raid.signup.SignUp)1 Config (pokeraidbot.infrastructure.jpa.config.Config)1