use of alfio.manager.system.ConfigurationLevel in project alf.io by alfio-event.
the class NotificationManager method processMessage.
private int processMessage(EmailMessage message, PurchaseContext purchaseContext) {
int messageId = message.getId();
ConfigurationLevel configurationLevel = ConfigurationLevel.purchaseContext(purchaseContext);
if (message.getAttempts() >= configurationManager.getFor(ConfigurationKeys.MAIL_ATTEMPTS_COUNT, configurationLevel).getValueAsIntOrDefault(10)) {
tx.execute(status -> emailMessageRepository.updateStatusAndAttempts(messageId, ERROR.name(), message.getAttempts(), Arrays.asList(IN_PROCESS.name(), WAITING.name(), RETRY.name())));
log.warn("Message with id {} will be discarded", messageId);
return 0;
}
try {
int result = Optional.ofNullable(tx.execute(status -> emailMessageRepository.updateStatus(messageId, message.getChecksum(), IN_PROCESS.name(), Arrays.asList(WAITING.name(), RETRY.name())))).orElse(0);
if (result > 0) {
return Optional.ofNullable(tx.execute(status -> {
sendMessage(purchaseContext, message);
return 1;
})).orElse(0);
} else {
log.debug("no messages have been updated on DB for the following criteria: id: {}, checksum: {}", messageId, message.getChecksum());
}
} catch (Exception e) {
tx.execute(status -> emailMessageRepository.updateStatusAndAttempts(message.getId(), RETRY.name(), ZonedDateTime.now(clockProvider.getClock()).plusMinutes(message.getAttempts() + 1L), message.getAttempts() + 1, Arrays.asList(IN_PROCESS.name(), WAITING.name(), RETRY.name())));
log.warn("could not send message: ", e);
}
return 0;
}
use of alfio.manager.system.ConfigurationLevel in project alf.io by alfio-event.
the class CheckInManagerTest method setUp.
@BeforeEach
public void setUp() {
eventRepository = mock(EventRepository.class);
configurationManager = mock(ConfigurationManager.class);
OrganizationRepository organizationRepository = mock(OrganizationRepository.class);
Event event = mock(Event.class);
Organization organization = mock(Organization.class);
ConfigurationLevel cl = ConfigurationLevel.event(event);
when(event.getConfigurationLevel()).thenReturn(cl);
when(eventRepository.findOptionalByShortName(EVENT_NAME)).thenReturn(Optional.of(event));
when(event.getId()).thenReturn(EVENT_ID);
when(event.getOrganizationId()).thenReturn(ORG_ID);
when(organizationRepository.findOrganizationForUser(USERNAME, ORG_ID)).thenReturn(Optional.of(organization));
when(organization.getId()).thenReturn(ORG_ID);
when(eventRepository.retrieveCheckInStatisticsForEvent(EVENT_ID)).thenReturn(new CheckInStatistics(0, 0, new Date()));
checkInManager = new CheckInManager(null, eventRepository, null, null, null, null, null, configurationManager, organizationRepository, null, null, null, null, null, TestUtil.clockProvider());
}
use of alfio.manager.system.ConfigurationLevel in project alf.io by alfio-event.
the class EuVatCheckerTest method init.
@BeforeEach
public void init() {
client = mock(EUVatChecker.class);
configurationManager = mock(ConfigurationManager.class);
eventAndOrganizationId = mock(EventAndOrganizationId.class);
ConfigurationLevel cl = ConfigurationLevel.event(eventAndOrganizationId);
when(eventAndOrganizationId.getConfigurationLevel()).thenReturn(cl);
when(configurationManager.getFor(eq(ConfigurationKeys.ENABLE_EU_VAT_DIRECTIVE), any(ConfigurationLevel.class))).thenReturn(existing(ConfigurationKeys.ENABLE_EU_VAT_DIRECTIVE, "true"));
when(configurationManager.getFor(eq(ConfigurationKeys.ENABLE_VIES_VALIDATION), any(ConfigurationLevel.class))).thenReturn(existing(ConfigurationKeys.ENABLE_VIES_VALIDATION, "true"));
when(configurationManager.getForSystem(ConfigurationKeys.EU_COUNTRIES_LIST)).thenReturn(existing(ConfigurationKeys.EU_COUNTRIES_LIST, "IE"));
when(configurationManager.getFor(eq(ConfigurationKeys.COUNTRY_OF_BUSINESS), any(ConfigurationLevel.class))).thenReturn(existing(ConfigurationKeys.COUNTRY_OF_BUSINESS, "IT"));
when(configurationManager.getFor(eq(EnumSet.of(ConfigurationKeys.ENABLE_EU_VAT_DIRECTIVE, ConfigurationKeys.COUNTRY_OF_BUSINESS, ConfigurationKeys.ENABLE_REVERSE_CHARGE_ONLINE, ConfigurationKeys.ENABLE_REVERSE_CHARGE_IN_PERSON)), any())).thenReturn(Map.of(ConfigurationKeys.ENABLE_EU_VAT_DIRECTIVE, existing(ConfigurationKeys.ENABLE_EU_VAT_DIRECTIVE, "true"), ConfigurationKeys.COUNTRY_OF_BUSINESS, existing(ConfigurationKeys.COUNTRY_OF_BUSINESS, "IT"), ConfigurationKeys.ENABLE_REVERSE_CHARGE_ONLINE, missing(ConfigurationKeys.ENABLE_REVERSE_CHARGE_ONLINE), ConfigurationKeys.ENABLE_REVERSE_CHARGE_IN_PERSON, missing(ConfigurationKeys.ENABLE_REVERSE_CHARGE_IN_PERSON)));
}
use of alfio.manager.system.ConfigurationLevel in project alf.io by alfio-event.
the class MollieConnectManager method storeConnectedAccountId.
@Override
public AccessTokenResponseDetails storeConnectedAccountId(String code, int organizationId) {
try {
ConfigurationLevel configurationLevel = ConfigurationLevel.organization(organizationId);
var options = configurationManager.getFor(Set.of(MOLLIE_API_KEY, MOLLIE_CONNECT_CLIENT_ID, MOLLIE_CONNECT_CLIENT_SECRET, MOLLIE_CONNECT_CALLBACK, BASE_URL), configurationLevel);
OAuth20Service service = new ServiceBuilder(options.get(MOLLIE_CONNECT_CLIENT_ID).getRequiredValue()).apiSecret(options.get(MOLLIE_CONNECT_CLIENT_SECRET).getRequiredValue()).callback(options.get(MOLLIE_CONNECT_CALLBACK).getRequiredValue()).build(new MollieConnectApi());
OAuth2AccessToken accessTokenResponse = service.getAccessToken(code);
var refreshToken = accessTokenResponse.getRefreshToken();
if (refreshToken != null) {
configurationManager.saveConfig(Configuration.from(organizationId, MOLLIE_CONNECT_REFRESH_TOKEN), refreshToken);
}
return new AccessTokenResponseDetails(accessTokenResponse.getAccessToken(), refreshToken, null, true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("Request interrupted while retrieving access token", e);
return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
} catch (Exception e) {
log.warn("Got exception while retrieving access token", e);
return new AccessTokenResponseDetails(null, null, e.getMessage(), false);
}
}
use of alfio.manager.system.ConfigurationLevel in project alf.io by alfio-event.
the class MollieWebhookPaymentManager method getInfo.
@Override
public Optional<PaymentInformation> getInfo(Transaction transaction, PurchaseContext purchaseContext) {
ConfigurationLevel configurationLevel = purchaseContext.getConfigurationLevel();
var configuration = getConfiguration(configurationLevel);
try {
var getPaymentResponse = callGetPayment(transaction.getPaymentId(), configuration, configurationLevel);
if (HttpUtils.callSuccessful(getPaymentResponse)) {
try (var responseReader = new InputStreamReader(getPaymentResponse.body(), UTF_8)) {
var body = new MolliePaymentDetails(JsonParser.parseReader(responseReader).getAsJsonObject());
var paidAmount = body.getPaidAmount();
var refundAmount = body.getRefundAmount().map(PaymentAmount::getValue).orElse(null);
return Optional.of(new PaymentInformation(paidAmount.getValue(), refundAmount, null, null));
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("Request interrupted while calling getInfo", e);
} catch (Exception e) {
log.warn("got exception while calling getInfo", e);
}
return Optional.empty();
}
Aggregations