Search in sources :

Example 1 with RaidEntitySignUp

use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.

the class RaidRepository method getRaidInstance.

private Raid getRaidInstance(RaidEntity raidEntity) {
    Validate.notNull(raidEntity);
    final String region = raidEntity.getRegion();
    final Raid raid = new Raid(pokemonRepository.getByName(raidEntity.getPokemon()), raidEntity.getEndOfRaid(), gymRepository.findByName(raidEntity.getGym(), region), localeService, region);
    raid.setCreator(raidEntity.getCreator());
    raid.setId(raidEntity.getId());
    Map<String, SignUp> signUps = new ConcurrentHashMap<>();
    for (RaidEntitySignUp signUp : raidEntity.getSignUpsAsSet()) {
        signUps.put(signUp.getResponsible(), new SignUp(signUp.getResponsible(), signUp.getNumberOfPeople(), LocalTime.parse(signUp.getEta(), Utils.timeParseFormatter)));
    }
    raid.setSignUps(signUps);
    return raid;
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) SignUp(pokeraidbot.domain.raid.signup.SignUp) RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with RaidEntitySignUp

use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.

the class RaidRepository method modifySignUp.

public Raid modifySignUp(String raidId, User user, int mystic, int instinct, int valor, int plebs, LocalDateTime startAt) {
    RaidEntity raidEntity = findEntityByRaidId(raidId);
    RaidEntitySignUp signUp = raidEntity.getSignUp(user.getName());
    final String startAtTime = Utils.printTime(startAt.toLocalTime());
    if (signUp == null) {
        final int sum = mystic + instinct + valor + plebs;
        assertSumNotLessThanOne(user, sum);
        raidEntity.addSignUp(new RaidEntitySignUp(user.getName(), sum, startAtTime));
    } else {
        int sum = signUp.getNumberOfPeople();
        if (startAt.toLocalTime().equals(Utils.parseTime(user, signUp.getEta(), localeService))) {
            sum = sum + mystic + instinct + valor + plebs;
        } else {
            signUp.setEta(startAtTime);
            // Reset number of signups to what the input gives since we changed time
            sum = mystic + instinct + valor + plebs;
        }
        assertSumNotLessThanOne(user, sum);
        signUp.setNumberOfPeople(sum, localeService, user);
    }
    raidEntity = raidEntityRepository.save(raidEntity);
    return getRaidInstance(raidEntity);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 3 with RaidEntitySignUp

use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.

the class RaidRepository method moveAllSignUpsForTimeToNewTime.

public void moveAllSignUpsForTimeToNewTime(String raidId, LocalDateTime currentStartAt, LocalDateTime newDateTime, User user) {
    Validate.notNull(raidId, "Raid ID cannot be null");
    Validate.notNull(currentStartAt, "Current start time cannot be null");
    Validate.notNull(newDateTime, "New start time cannot be null");
    Validate.notNull(user, "User cannot be null");
    RaidEntity entity = raidEntityRepository.findOne(raidId);
    if (entity != null) {
        for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
            if (signUp.getArrivalTime().equals(currentStartAt.toLocalTime())) {
                signUp.setEta(Utils.printTime(newDateTime.toLocalTime()));
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Changed ETA for signup: " + signUp);
                }
            }
        }
        raidEntityRepository.save(entity);
    } else {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
    }
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 4 with RaidEntitySignUp

use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.

the class RaidEntityRepositoryTest method createSignUp.

@Transactional(propagation = Propagation.REQUIRES_NEW)
public RaidEntitySignUp createSignUp(String id, Integer thread, LocalTime now, Random random, int i) {
    RaidEntitySignUp signUp = new RaidEntitySignUp("Mupp" + thread + "_" + i, random.nextInt(4) + 1, printTime(now));
    RaidEntity entity = entityRepository.findOne(id);
    entity.addSignUp(signUp);
    entityRepository.save(entity);
    LOGGER.warn("Created: " + signUp);
    return signUp;
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with RaidEntitySignUp

use of pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp in project pokeraidbot by magnusmickelsson.

the class RaidEntityRepositoryTest method deleteSomeSignUps.

@Transactional(propagation = Propagation.REQUIRES_NEW)
public int deleteSomeSignUps(String id) {
    int numberDeleted = 0;
    final RaidEntity theEntity = entityRepository.findOne(id);
    for (RaidEntitySignUp signUp : theEntity.getSignUpsAsSet()) {
        if (signUp.getNumberOfPeople().equals(3)) {
            theEntity.removeSignUp(signUp);
            LOGGER.warn("Removed: " + signUp);
            numberDeleted++;
        }
    }
    entityRepository.save(theEntity);
    return numberDeleted;
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)11 RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)9 Transactional (org.springframework.transaction.annotation.Transactional)3 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)3 SignUp (pokeraidbot.domain.raid.signup.SignUp)2 LocalTime (java.time.LocalTime)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 WrongNumberOfArgumentsException (pokeraidbot.domain.errors.WrongNumberOfArgumentsException)1 Gym (pokeraidbot.domain.gym.Gym)1 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)1