Search in sources :

Example 1 with ConfigurationKeys

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;
    }
}
Also used : Ticket(alfio.model.Ticket) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Organization(alfio.model.user.Organization) KeyStore(java.security.KeyStore) PassSigningException(com.ryantenney.passkit4j.sign.PassSigningException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) Event(alfio.model.Event)

Example 2 with ConfigurationKeys

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);
}
Also used : ConfigurationKeys(alfio.model.system.ConfigurationKeys) StrSubstitutor(org.apache.commons.text.StrSubstitutor) HashMap(java.util.HashMap)

Aggregations

ConfigurationKeys (alfio.model.system.ConfigurationKeys)2 Event (alfio.model.Event)1 Ticket (alfio.model.Ticket)1 Organization (alfio.model.user.Organization)1 PassSigningException (com.ryantenney.passkit4j.sign.PassSigningException)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStore (java.security.KeyStore)1 HashMap (java.util.HashMap)1 StrSubstitutor (org.apache.commons.text.StrSubstitutor)1