<commit_before>import { _, Autowired, Bean, PreConstruct } from '@ag-community/grid-core';
import { MD5 } from './license/md5';

@Bean('licenseManager')
export class LicenseManager {
    private static RELEASE_INFORMATION: string = 'MTU3MTgyNDEzMDI0Mw==';
    private static licenseKey: string;
    private watermarkMessage: string | undefined = undefined;

    @Autowired('md5') private md5: MD5;

    @PreConstruct
    public validateLicense(): void {
        if (_.missingOrEmpty(LicenseManager.licenseKey)) {
            this.outputMissingLicenseKey();
        } else if (!_.missingOrEmpty(LicenseManager.licenseKey) && LicenseManager.licenseKey.length > 32) {
            const {md5, license, version, isTrial} = LicenseManager.extractLicenseComponents(LicenseManager.licenseKey);

            if (md5 === this.md5.md5(license)) {
                if (_.exists(version) && version) {
                    this.validateLicenseKeyForVersion(version, !!isTrial, license);
                } else {
                    this.validateLegacyKey(license);
                }
            } else {
                this.outputInvalidLicenseKey();
            }
        }
    }

    private static extractExpiry(license: string) {
        const restrictionHashed = license.substring(license.lastIndexOf('_') + 1, license.length);
        return new Date(parseInt(LicenseManager.decode(restrictionHashed), 10));
    }

    private static extractLicenseComponents(licenseKey: string) {
        const hashStart = licenseKey.length - 32;
        const md5 = licenseKey.substring(hashStart);
        const license = licenseKey.substring(0, hashStart);
        const [version, isTrial] = LicenseManager.extractBracketedInformation(licenseKey);
        return {md5, license, version, isTrial};
    }

    public getLicenseDetails(licenseKey: string) {
        const {md5, license, version, isTrial} = LicenseManager.extractLicenseComponents(licenseKey);
        let valid = (md5 === this.md5.md5(license));

        let expiry: Date | null = null;
        if (valid) {
            expiry = LicenseManager.extractExpiry(license);
            valid = !isNaN(expiry.getTime());
        }

        return {
            licenseKey,
            valid,
            expiry: valid ? LicenseManager.formatDate(expiry) : null,
            version: version ? version : 'legacy',<commit_msg>Bug fixes<commit_after>import { _, Autowired, Bean, PreConstruct } from '@ag-community/grid-core';
import { MD5 } from './license/md5';

@Bean('licenseManager')
export class LicenseManager {
    private static RELEASE_INFORMATION: string = 'MTU3MTgyNDEzMDI0Mw==';
    private static licenseKey: string;
    private watermarkMessage: string | undefined = undefined;

    @Autowired('md5') private md5: MD5;

    @PreConstruct
    public validateLicense(): void {
        if (_.missingOrEmpty(LicenseManager.licenseKey)) {
            this.outputMissingLicenseKey();
        } else if (LicenseManager.licenseKey.length > 32) {
            const {md5, license, version, isTrial} = LicenseManager.extractLicenseComponents(LicenseManager.licenseKey);

            if (md5 === this.md5.md5(license)) {
                if (_.exists(version) && version) {
                    this.validateLicenseKeyForVersion(version, !!isTrial, license);
                } else {
                    this.validateLegacyKey(license);
                }
            } else {
                this.outputInvalidLicenseKey();
            }
        } else {
            this.outputInvalidLicenseKey();
        }
    }

    private static extractExpiry(license: string) {
        const restrictionHashed = license.substring(license.lastIndexOf('_') + 1, license.length);
        return new Date(parseInt(LicenseManager.decode(restrictionHashed), 10));
    }

    private static extractLicenseComponents(licenseKey: string) {
        const hashStart = licenseKey.length - 32;
        const md5 = licenseKey.substring(hashStart);
        const license = licenseKey.substring(0, hashStart);
        const [version, isTrial] = LicenseManager.extractBracketedInformation(licenseKey);
        return {md5, license, version, isTrial};
    }

    public getLicenseDetails(licenseKey: string) {
        const {md5, license, version, isTrial} = LicenseManager.extractLicenseComponents(licenseKey);
        let valid = (md5 === this.md5.md5(license));

        let expiry: Date | null = null;
        if (valid) {
            expiry = LicenseManager.extractExpiry(license);
            valid = !isNaN(expiry.getTime());
        }

        return {
            licenseKey,
            valid,
            expiry: valid ? LicenseManager.formatDate(expiry) : null,
            version: version ? version : 'legacy',
{'fraction_non_alphanumeric': 0.10763374920702051, 'fraction_numerical': 0.010573059843518714, 'mean_word_length': 2.6024371667936026, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6882609', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1245, 'n_words': 271}