use of alfio.model.modification.SendCodeModification in project alf.io by alfio-event.
the class SpecialPriceManager method linkAssigneeToCode.
public List<SendCodeModification> linkAssigneeToCode(List<SendCodeModification> input, String eventName, int categoryId, String username) {
final Event event = eventManager.getSingleEvent(eventName, username);
Set<SendCodeModification> set = new LinkedHashSet<>(input);
List<String> availableCodes = checkCodeAssignment(set, categoryId, event, username);
final Iterator<String> codes = availableCodes.iterator();
return Stream.concat(set.stream().filter(IS_CODE_PRESENT), input.stream().filter(IS_CODE_PRESENT.negate()).map(p -> new SendCodeModification(codes.next(), p.getAssignee(), p.getEmail(), p.getLanguage()))).collect(toList());
}
use of alfio.model.modification.SendCodeModification in project alf.io by alfio-event.
the class SpecialPriceManagerTest method validationErrorRequestedCodeIsNotAvailable.
@Test(expected = IllegalArgumentException.class)
public void validationErrorRequestedCodeIsNotAvailable() throws Exception {
List<SendCodeModification> notExistingCode = asList(new SendCodeModification("AAA", "A 123", "123@123", "it"), new SendCodeModification("456", "A 456", "456@456", "en"));
specialPriceManager.linkAssigneeToCode(notExistingCode, "test", 0, "username");
}
use of alfio.model.modification.SendCodeModification in project alf.io by alfio-event.
the class SpecialPriceManagerTest method trimLanguageTag.
@Test
public void trimLanguageTag() throws Exception {
assertTrue(specialPriceManager.sendCodeToAssignee(singletonList(new SendCodeModification("123", "me", "me@domain.com", " it")), "", 0, ""));
ArgumentCaptor<TextTemplateGenerator> templateCaptor = ArgumentCaptor.forClass(TextTemplateGenerator.class);
verify(notificationManager).sendSimpleEmail(eq(event), eq("me@domain.com"), anyString(), templateCaptor.capture());
templateCaptor.getValue().generate();
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
verify(templateManager).renderTemplate(any(Event.class), eq(TemplateResource.SEND_RESERVED_CODE), captor.capture(), eq(Locale.ITALIAN));
Map<String, Object> model = captor.getValue();
assertEquals("123", model.get("code"));
assertEquals(event, model.get("event"));
assertEquals(organization, model.get("organization"));
assertEquals("http://my-event", model.get("eventPage"));
assertEquals("me", model.get("assignee"));
verify(messageSource).getMessage(eq("email-code.subject"), eq(new Object[] { "Event Name" }), eq(Locale.ITALIAN));
}
use of alfio.model.modification.SendCodeModification in project alf.io by alfio-event.
the class SpecialPriceManagerTest method validationErrorTooManyCodesRequested.
@Test(expected = IllegalArgumentException.class)
public void validationErrorTooManyCodesRequested() throws Exception {
List<SendCodeModification> oneMore = new ArrayList<>();
oneMore.addAll(CODES_REQUESTED);
oneMore.add(new SendCodeModification("123", "", "", ""));
specialPriceManager.linkAssigneeToCode(oneMore, "test", 0, "username");
}
use of alfio.model.modification.SendCodeModification in project alf.io by alfio-event.
the class SpecialPriceManager method sendCodeToAssignee.
public boolean sendCodeToAssignee(List<SendCodeModification> input, String eventName, int categoryId, String username) {
final Event event = eventManager.getSingleEvent(eventName, username);
final Organization organization = eventManager.loadOrganizer(event, username);
Set<SendCodeModification> set = new LinkedHashSet<>(input);
checkCodeAssignment(set, categoryId, event, username);
Validate.isTrue(set.stream().allMatch(IS_CODE_PRESENT), "There are missing codes. Please check input file.");
List<ContentLanguage> eventLanguages = i18nManager.getEventLanguages(event.getLocales());
Validate.isTrue(!eventLanguages.isEmpty(), "No locales have been defined for the event. Please check the configuration");
ContentLanguage defaultLocale = eventLanguages.contains(ContentLanguage.ENGLISH) ? ContentLanguage.ENGLISH : eventLanguages.get(0);
set.forEach(m -> {
Locale locale = Locale.forLanguageTag(StringUtils.defaultString(StringUtils.trimToNull(m.getLanguage()), defaultLocale.getLanguage()));
Map<String, Object> model = TemplateResource.prepareModelForSendReservedCode(organization, event, m, eventManager.getEventUrl(event));
notificationManager.sendSimpleEmail(event, m.getEmail(), messageSource.getMessage("email-code.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.SEND_RESERVED_CODE, model, locale));
int marked = specialPriceRepository.markAsSent(ZonedDateTime.now(event.getZoneId()), m.getAssignee().trim(), m.getEmail().trim(), m.getCode().trim());
Validate.isTrue(marked == 1, "Expected exactly one row updated, got " + marked);
});
return true;
}
Aggregations