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));
}
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;
}
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;
}
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);
}
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();
}
Aggregations