Search in sources :

Example 16 with RaidEntity

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

the class RaidRepositoryTest method moveTimeForGroupWorks.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void moveTimeForGroupWorks() throws Exception {
    // We're not allowed to create signups at night, so mocking time
    clockService.setMockTime(LocalTime.of(10, 0));
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    when(user.getName()).thenReturn(raidCreatorName);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);
    try {
        repo.newRaid(user, enteiRaid, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    List<User> raiders = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        final User raider = mock(User.class);
        when(raider.getName()).thenReturn("User" + i);
        raiders.add(raider);
    }
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    final LocalDateTime raidGroupTime = endOfRaid.minusMinutes(10);
    for (User raider : raiders) {
        repo.addSignUp(raider, raid, new SignUp(raider.getName(), 2, raidGroupTime.toLocalTime()));
    }
    final LocalDateTime newRaidGroupTime = raidGroupTime.plusMinutes(2);
    RaidEntity entity = raidEntityRepository.findOne(raid.getId());
    repo.moveAllSignUpsForTimeToNewTime(raid.getId(), raidGroupTime, newRaidGroupTime, user);
    entity = raidEntityRepository.findOne(raid.getId());
    raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    entity = raidEntityRepository.findOne(raid.getId());
    assertThat(raid.getSignUps().size(), is(5));
    assertThat(raid.getNumberOfPeopleSignedUp(), is(10));
    assertThat(raid.getSignUpsAt(newRaidGroupTime.toLocalTime()).size(), is(5));
    assertThat(raid.getSignUpsAt(raidGroupTime.toLocalTime()).size(), is(0));
}
Also used : LocalDateTime(java.time.LocalDateTime) SignUp(pokeraidbot.domain.raid.signup.SignUp) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Gym(pokeraidbot.domain.gym.Gym) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with RaidEntity

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

the class RaidRepository method getActiveRaidOrFallbackToExRaid.

public Raid getActiveRaidOrFallbackToExRaid(Gym gym, String region, User user) {
    RaidEntity raidEntity = getActiveOrFallbackToExRaidEntity(gym, region);
    if (raidEntity == null) {
        throw new RaidNotFoundException(gym, localeService, user);
    }
    final Raid raid = getRaidInstance(raidEntity);
    return raid;
}
Also used : RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) RaidNotFoundException(pokeraidbot.domain.errors.RaidNotFoundException)

Example 18 with RaidEntity

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

the class RaidRepository method changeEndOfRaid.

public Raid changeEndOfRaid(String raidId, LocalDateTime newEndOfRaid, Guild guild, Config config, User user, String rawMessage) {
    RaidEntity raidEntity = findEntityByRaidId(raidId);
    raidEntity.setEndOfRaid(newEndOfRaid);
    raidEntity = raidEntityRepository.save(raidEntity);
    final Raid raidInstance = getRaidInstance(raidEntity);
    trackingService.notifyTrackers(guild, raidInstance, config, user, rawMessage);
    return raidInstance;
}
Also used : RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 19 with RaidEntity

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

the class RaidRepository method addSignUp.

public void addSignUp(User user, Raid raid, SignUp theSignUp) {
    RaidEntity entity = findEntityByRaidId(raid.getId());
    RaidEntitySignUp entitySignUp = entity.getSignUp(user.getName());
    if (entitySignUp == null) {
        entity.addSignUp(new RaidEntitySignUp(user.getName(), theSignUp.getHowManyPeople(), Utils.printTime(theSignUp.getArrivalTime())));
    } else {
        entitySignUp.setNumberOfPeople(theSignUp.getHowManyPeople(), localeService, user);
        entitySignUp.setEta(Utils.printTime(theSignUp.getArrivalTime()));
    }
    raidEntityRepository.save(entity);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 20 with RaidEntity

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

the class RaidRepository method listGroupsForRaid.

public String listGroupsForRaid(Raid raid, Set<RaidGroup> groups) {
    StringBuilder sb = new StringBuilder();
    if (groups.size() > 0) {
        sb.append(" " + Emotes.GROUP + " ");
        Set<String> times = new LinkedHashSet<>();
        int signUpsInGroups = 0;
        for (RaidGroup group : groups) {
            final LocalTime groupTime = group.getStartsAt().toLocalTime();
            final int numberOfPeopleInGroup = countSignups(raid.getSignUpsAt(groupTime));
            times.add(printTime(groupTime) + " (**" + numberOfPeopleInGroup + "**)");
            signUpsInGroups += numberOfPeopleInGroup;
        }
        sb.append(StringUtils.join(times, ", "));
        RaidEntity entity = findEntityByRaidId(raid.getId());
        final Set<RaidEntitySignUp> signUpsAsSet = entity.getSignUpsAsSet();
        final long totalSignUps = signUpsAsSet.stream().mapToInt(RaidEntitySignUp::getNumberOfPeople).sum();
        if (totalSignUps > signUpsInGroups) {
            sb.append(", -:- (**").append(totalSignUps - signUpsInGroups).append("**)");
        }
    }
    return sb.toString();
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) LocalTime(java.time.LocalTime) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) 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