use of alfio.model.system.ConfigurationKeys in project alf.io by alfio-event.
the class PassBookManager method getPassBook.
byte[] getPassBook(Map<String, String> model) {
try {
Ticket ticket = Json.fromJson(model.get("ticket"), Ticket.class);
int eventId = ticket.getEventId();
Event event = eventRepository.findById(eventId);
Organization organization = organizationRepository.getById(Integer.valueOf(model.get("organizationId"), 10));
int organizationId = organization.getId();
Function<ConfigurationKeys, Configuration.ConfigurationPathKey> partial = Configuration.from(organizationId, eventId);
Map<ConfigurationKeys, Optional<String>> pbookConf = configurationManager.getStringConfigValueFrom(partial.apply(ConfigurationKeys.PASSBOOK_TYPE_IDENTIFIER), partial.apply(ConfigurationKeys.PASSBOOK_KEYSTORE), partial.apply(ConfigurationKeys.PASSBOOK_KEYSTORE_PASSWORD), partial.apply(ConfigurationKeys.PASSBOOK_TEAM_IDENTIFIER));
// check if all are set
if (pbookConf.values().stream().anyMatch(o -> !o.isPresent())) {
log.trace("Cannot generate Passbook. Missing configuration keys, check if all 4 are presents");
return null;
}
//
String teamIdentifier = pbookConf.get(ConfigurationKeys.PASSBOOK_TEAM_IDENTIFIER).orElseThrow(IllegalStateException::new);
String typeIdentifier = pbookConf.get(ConfigurationKeys.PASSBOOK_TYPE_IDENTIFIER).orElseThrow(IllegalStateException::new);
byte[] keystoreRaw = Base64.getDecoder().decode(pbookConf.get(ConfigurationKeys.PASSBOOK_KEYSTORE).orElseThrow(IllegalStateException::new));
String keystorePwd = pbookConf.get(ConfigurationKeys.PASSBOOK_KEYSTORE_PASSWORD).orElseThrow(IllegalStateException::new);
// ugly, find an alternative way?
Optional<KeyStore> ksJks = loadKeyStore(keystoreRaw);
if (ksJks.isPresent()) {
return buildPass(ticket, event, organization, teamIdentifier, typeIdentifier, keystorePwd, ksJks.get());
} else {
log.warn("Cannot generate Passbook. Not able to load keystore. Please check configuration.");
return null;
}
} catch (Exception ex) {
log.warn("Got Exception while generating Passbook. Please check configuration.", ex);
return null;
}
}
use of alfio.model.system.ConfigurationKeys in project alf.io by alfio-event.
the class LocationDescriptor method getMapUrl.
public static String getMapUrl(String lat, String lng, Map<ConfigurationKeys, Optional<String>> geoConf) {
Map<String, String> params = new HashMap<>();
params.put("latitude", lat);
params.put("longitude", lng);
ConfigurationKeys.GeoInfoProvider provider = getProvider(geoConf);
String mapUrl = mapUrl(provider);
fillParams(provider, geoConf, params);
return new StrSubstitutor(params).replace(mapUrl);
}
Aggregations