// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/repositories/CloudCredentialsRepository.java
// @Transactional(readOnly = true)
// public interface CloudCredentialsRepository extends CrudRepository<CloudCredentials, Long> {
// 
// }
// 
// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/services/CertificateServiceImpl.java
// @Repository
// @Transactional(readOnly = true)
// public class CertificateServiceImpl implements ICertificateService {
// 
//     private CertificateTransformer tranformer;
//     @Autowired
//     private CertificateRepository repository;
// 
//     public CertificateServiceImpl() {
//         tranformer = Mappers.getMapper(CertificateTransformer.class);
//     }
// 
//     @Override
//     @Transactional
//     public CertificateDTO save(CertificateDTO certificateDTO) {
//         Certificate certificate = tranformer.certificateDTOToEntity(certificateDTO);
//         return tranformer.certificateEntityToDTO(repository.save(certificate));
//     }
// 
//     @Override
//     public void remove(CertificateDTO certificateDTO) {
//         Certificate certificate = tranformer.certificateDTOToEntity(certificateDTO);
//         repository.delete(certificate);
//     }
// 
//     @Override
//     public List<CertificateDTO> getActiveCertificates() {
//         List<CertificateDTO> certificateDTOList = new ArrayList<>();
//         repository.getActiveCertificates().stream().forEach(certificate -> certificateDTOList
//                 .add(tranformer.certificateEntityToDTO(certificate)));
//         return certificateDTOList;
//     }
// 
//     @Override
//     public List<CertificateDTO> getDisableCertificates() {
//         List<CertificateDTO> certificateDTOList = new ArrayList<>();
//         repository.getDisableCertificates().stream().forEach(certificate -> certificateDTOList
//                 .add(tranformer.certificateEntityToDTO(certificate)));
//         return certificateDTOList;
//     }
// 
//     @Override
//     public List<CertificateDTO> getAllCertificates() {
//         List<CertificateDTO> certificateDTOList = new ArrayList<>();
//         repository.findAll().forEach(certificate -> certificateDTOList
//                 .add(tranformer.certificateEntityToDTO(certificate)));
//         return certificateDTOList;
//     }
// }
// 
// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/services/KeyStorePasswordServiceImpl.java
// @Repository
// @Transactional
// public class KeyStorePasswordServiceImpl implements IKeyStorePasswordService {
// 
//     private KeyStorePasswordTransformer transformer;
//     @Autowired
//     private KeyStorePasswordRepository repository;
// 
//     public KeyStorePasswordServiceImpl() {
//         transformer = Mappers.getMapper(KeyStorePasswordTransformer.class);
//     }
// 
//     @Override
//     public KeyStorePasswordDTO save(KeyStorePasswordDTO passwordDTO) {
//         List<KeyStorePasswordDTO> keyStorePasswordDTOs = getAllPasswords();
//         if (keyStorePasswordDTOs.size() > 0) {
//             return keyStorePasswordDTOs.get(0);
//         }
//         KeyStorePassword password = transformer.keyStorePasswordDTOToEntity(passwordDTO);
//         return transformer.keyStorePasswordEntityToDTO(repository.save(password));
//     }
// 
//     @Override
//     public KeyStorePasswordDTO getPassword() {
//         List<KeyStorePasswordDTO> keyStorePasswordDTOList = getAllPasswords();
//         if (keyStorePasswordDTOList.size() == 0) {
//             KeyStorePasswordDTO newKeyStorePasswordDTO = new KeyStorePasswordDTO(
//                     UUID.randomUUID().toString());
//             return save(newKeyStorePasswordDTO);
//         }
//         return keyStorePasswordDTOList.get(0);
//     }
// 
//     private List<KeyStorePasswordDTO> getAllPasswords() {
//         List<KeyStorePasswordDTO> keyStorePasswordDTOList = new ArrayList<>();
//         repository.findAll().forEach(keyStorePassword -> keyStorePasswordDTOList
//                 .add(transformer.keyStorePasswordEntityToDTO(keyStorePassword)));
//         return keyStorePasswordDTOList;
//     }
// }


import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import com.stnetix.ariaddna.commonutils.logger.AriaddnaLogger;
import com.stnetix.ariaddna.persistence.repositories.AccessTokenRepository;
import com.stnetix.ariaddna.persistence.repositories.CertificateRepository;
import com.stnetix.ariaddna.persistence.repositories.CloudCredentialsRepository;
import com.stnetix.ariaddna.persistence.repositories.KeyStorePasswordRepository;
import com.stnetix.ariaddna.persistence.services.AccessTokenServiceImpl;
import com.stnetix.ariaddna.persistence.services.CertificateServiceImpl;
import com.stnetix.ariaddna.persistence.services.CloudCredentialsServiceImpl;
import com.stnetix.ariaddna.persistence.services.ICertificateService;
import com.stnetix.ariaddna.persistence.services.IKeyStorePasswordService;
import com.stnetix.ariaddna.persistence.services.IMetatableService;
import com.stnetix.ariaddna.persistence.services.KeyStorePasswordServiceImpl;
import com.stnetix.ariaddna.persistence.services.MetatableServiceImpl;
    public IKeyStorePasswordService keyStorePasswordServiceImpl() {
        return new KeyStorePasswordServiceImpl();
    }

    @Bean
    public RepositoryFactorySupport repositoryFactorySupport() {
        LOGGER.info("In bean repositoryFactorySupport() entity manager is : {}", em.toString());
        return new JpaRepositoryFactory(em);
    }

    @Bean CertificateRepository certificateRepository() {
        return repositoryFactorySupport().getRepository(CertificateRepository.class);
    }

    @Bean
    public KeyStorePasswordRepository keyStorePasswordRepository() {
        return repositoryFactorySupport().getRepository(KeyStorePasswordRepository.class);
    }

    @Bean
    public AccessTokenRepository accessTokenRepository() {
        return repositoryFactorySupport().getRepository(AccessTokenRepository.class);
    }

    @Bean
    public AccessTokenServiceImpl accessTokenServiceImpl() {
        return new AccessTokenServiceImpl();
    }

    @Bean
// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/repositories/CloudCredentialsRepository.java
// @Transactional(readOnly = true)
// public interface CloudCredentialsRepository extends CrudRepository<CloudCredentials, Long> {
// 
// }
// 
// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/services/CertificateServiceImpl.java
// @Repository
// @Transactional(readOnly = true)
// public class CertificateServiceImpl implements ICertificateService {
// 
//     private CertificateTransformer tranformer;
//     @Autowired
//     private CertificateRepository repository;
// 
//     public CertificateServiceImpl() {
//         tranformer = Mappers.getMapper(CertificateTransformer.class);
//     }
// 
//     @Override
//     @Transactional
//     public CertificateDTO save(CertificateDTO certificateDTO) {
//         Certificate certificate = tranformer.certificateDTOToEntity(certificateDTO);
//         return tranformer.certificateEntityToDTO(repository.save(certificate));
//     }
// 
//     @Override
//     public void remove(CertificateDTO certificateDTO) {
//         Certificate certificate = tranformer.certificateDTOToEntity(certificateDTO);
//         repository.delete(certificate);
//     }
// 
//     @Override
//     public List<CertificateDTO> getActiveCertificates() {
//         List<CertificateDTO> certificateDTOList = new ArrayList<>();
//         repository.getActiveCertificates().stream().forEach(certificate -> certificateDTOList
//                 .add(tranformer.certificateEntityToDTO(certificate)));
//         return certificateDTOList;
//     }
// 
//     @Override
//     public List<CertificateDTO> getDisableCertificates() {
//         List<CertificateDTO> certificateDTOList = new ArrayList<>();
//         repository.getDisableCertificates().stream().forEach(certificate -> certificateDTOList
//                 .add(tranformer.certificateEntityToDTO(certificate)));
//         return certificateDTOList;
//     }
// 
//     @Override
//     public List<CertificateDTO> getAllCertificates() {
//         List<CertificateDTO> certificateDTOList = new ArrayList<>();
//         repository.findAll().forEach(certificate -> certificateDTOList
//                 .add(tranformer.certificateEntityToDTO(certificate)));
//         return certificateDTOList;
//     }
// }
// 
// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/services/KeyStorePasswordServiceImpl.java
// @Repository
// @Transactional
// public class KeyStorePasswordServiceImpl implements IKeyStorePasswordService {
// 
//     private KeyStorePasswordTransformer transformer;
//     @Autowired
//     private KeyStorePasswordRepository repository;
// 
//     public KeyStorePasswordServiceImpl() {
//         transformer = Mappers.getMapper(KeyStorePasswordTransformer.class);
//     }
// 
//     @Override
//     public KeyStorePasswordDTO save(KeyStorePasswordDTO passwordDTO) {
//         List<KeyStorePasswordDTO> keyStorePasswordDTOs = getAllPasswords();
//         if (keyStorePasswordDTOs.size() > 0) {
//             return keyStorePasswordDTOs.get(0);
//         }
//         KeyStorePassword password = transformer.keyStorePasswordDTOToEntity(passwordDTO);
//         return transformer.keyStorePasswordEntityToDTO(repository.save(password));
//     }
// 
//     @Override
//     public KeyStorePasswordDTO getPassword() {
//         List<KeyStorePasswordDTO> keyStorePasswordDTOList = getAllPasswords();
//         if (keyStorePasswordDTOList.size() == 0) {
//             KeyStorePasswordDTO newKeyStorePasswordDTO = new KeyStorePasswordDTO(
//                     UUID.randomUUID().toString());
//             return save(newKeyStorePasswordDTO);
//         }
//         return keyStorePasswordDTOList.get(0);
//     }
// 
//     private List<KeyStorePasswordDTO> getAllPasswords() {
//         List<KeyStorePasswordDTO> keyStorePasswordDTOList = new ArrayList<>();
//         repository.findAll().forEach(keyStorePassword -> keyStorePasswordDTOList
//                 .add(transformer.keyStorePasswordEntityToDTO(keyStorePassword)));
//         return keyStorePasswordDTOList;
//     }
// }


// Path: storage-service/src/main/java/com/stnetix/ariaddna/persistence/utils/AppConfiguration.java
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import com.stnetix.ariaddna.commonutils.logger.AriaddnaLogger;
import com.stnetix.ariaddna.persistence.repositories.AccessTokenRepository;
import com.stnetix.ariaddna.persistence.repositories.CertificateRepository;
import com.stnetix.ariaddna.persistence.repositories.CloudCredentialsRepository;
import com.stnetix.ariaddna.persistence.repositories.KeyStorePasswordRepository;
import com.stnetix.ariaddna.persistence.services.AccessTokenServiceImpl;
import com.stnetix.ariaddna.persistence.services.CertificateServiceImpl;
import com.stnetix.ariaddna.persistence.services.CloudCredentialsServiceImpl;
import com.stnetix.ariaddna.persistence.services.ICertificateService;
import com.stnetix.ariaddna.persistence.services.IKeyStorePasswordService;
import com.stnetix.ariaddna.persistence.services.IMetatableService;
import com.stnetix.ariaddna.persistence.services.KeyStorePasswordServiceImpl;
import com.stnetix.ariaddna.persistence.services.MetatableServiceImpl;

    public IKeyStorePasswordService keyStorePasswordServiceImpl() {
        return new KeyStorePasswordServiceImpl();
    }

    @Bean
    public RepositoryFactorySupport repositoryFactorySupport() {
        LOGGER.info("In bean repositoryFactorySupport() entity manager is : {}", em.toString());
        return new JpaRepositoryFactory(em);
    }

    @Bean CertificateRepository certificateRepository() {
        return repositoryFactorySupport().getRepository(CertificateRepository.class);
    }

    @Bean
    public KeyStorePasswordRepository keyStorePasswordRepository() {
        return repositoryFactorySupport().getRepository(KeyStorePasswordRepository.class);
    }

    @Bean
    public AccessTokenRepository accessTokenRepository() {
        return repositoryFactorySupport().getRepository(AccessTokenRepository.class);
    }

    @Bean
    public AccessTokenServiceImpl accessTokenServiceImpl() {
        return new AccessTokenServiceImpl();
    }

    @Bean
    public CloudCredentialsRepository cloudCredentialsRepository() {