class PiisConsentLazyMigrationService {

    public ConsentEntity migrateIfNeeded(ConsentEntity consentEntity) {
        if (consentEntity.getData() == null) {
            Optional<PiisConsentEntity> obsoletePiisConsentOptional = obsoletePiisConsentJpaRepository.findByExternalId(consentEntity.getExternalId());
            if (obsoletePiisConsentOptional.isPresent()) {
                byte[] consentData = getConsentData(obsoletePiisConsentOptional.get());
                consentEntity.setData(consentData);
                consentJpaRepository.save(consentEntity);
            }
        }
        return consentEntity;
    }

}