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