<commit_before>package com.sequenceiq.cloudbreak.domain.json;

import java.util.Optional;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;

public class EncryptedJsonToString extends JsonToString {

    private static final String SECRET;

    static {
        SECRET = Optional.ofNullable(System.getProperty("cb.client.secret")).orElse(System.getenv("CB_CLIENT_SECRET"));
    }

    private final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();

    private final StandardPBEStringEncryptor legacyEncryptor = new StandardPBEStringEncryptor();

    public EncryptedJsonToString() {
        encryptor.setPassword(SECRET);
        legacyEncryptor.setPassword("<PASSWORD>");
    }

    @Override
    public String convertToDatabaseColumn(Json attribute) {
        String json = super.convertToDatabaseColumn(attribute);
        return encryptor.encrypt(json);
    }

    @Override
    public Json convertToEntityAttribute(String dbData) {
        String json;
        try {
            json = encryptor.decrypt(dbData);
        } catch (EncryptionOperationNotPossibleException e) {
            try {
                json = legacyEncryptor.decrypt(dbData);
            } catch (EncryptionOperationNotPossibleException ignored) {
                json = dbData;
            }
        }
        return super.convertToEntityAttribute(json);
    }
}<commit_msg>CB-835 Log if the decrypt service is failing<commit_after>package com.sequenceiq.cloudbreak.domain.json;

import java.util.Optional;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EncryptedJsonToString extends JsonToString {

    private static final Logger LOGGER = LoggerFactory.getLogger(EncryptedJsonToString.class);

    private static final String SECRET;

    static {
        SECRET = Optional.ofNullable(System.getProperty("cb.client.secret")).orElse(System.getenv("CB_CLIENT_SECRET"));
    }

    private final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();

    private final StandardPBEStringEncryptor legacyEncryptor = new StandardPBEStringEncryptor();

    public EncryptedJsonToString() {
        encryptor.setPassword(SECRET);
        legacyEncryptor.setPassword("<PASSWORD>");
    }

    @Override
    public String convertToDatabaseColumn(Json attribute) {
        String json = super.convertToDatabaseColumn(attribute);
        return encryptor.encrypt(json);
    }

    @Override
    public Json convertToEntityAttribute(String dbData) {
        String json;
        try {
            json = encryptor.decrypt(dbData);
        } catch (EncryptionOperationNotPossibleException e) {
            try {
                json = legacyEncryptor.decrypt(dbData);
            } catch (EncryptionOperationNotPossibleException ex) {
                json = dbData;
                LOGGER.info("Cannot decrypt the data. {}", dbData, ex);
            }
        }
        return super.convertToEntityAttribute(json);
    }
}
{'fraction_non_alphanumeric': 0.08136234626300852, 'fraction_numerical': 0.001576789656259855, 'mean_word_length': 3.2864864864864867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7664774', 'n_tokens_mistral': 891, 'n_tokens_neox': 863, 'n_words': 163}