Search in sources :

Example 11 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method associatePolicyGroupToDomain.

@Override
@Transactional(readOnly = false)
public void associatePolicyGroupToDomain(long domainId, long policyGroupId) throws ConfigurationStoreException {
    validateState();
    // make sure the domain exists
    final Domain domain = domainDao.getDomain(domainId);
    if (domain == null)
        throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
    // make sure the policy group exists
    final CertPolicyGroup policyGroup = this.getPolicyGroupById(policyGroupId);
    if (policyGroup == null)
        throw new ConfigurationStoreException("Policy group with id " + policyGroup + " does not exist");
    try {
        final CertPolicyGroupDomainReltn policyGroupDomainAssoc = new CertPolicyGroupDomainReltn();
        policyGroupDomainAssoc.setDomain(domain);
        policyGroupDomainAssoc.setCertPolicyGroup(policyGroup);
        entityManager.persist(policyGroupDomainAssoc);
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to associate policy group to domain.", e);
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method disassociatePolicyGroupFromDomains.

@Override
@Transactional(readOnly = false)
public void disassociatePolicyGroupFromDomains(long policyGroupId) throws ConfigurationStoreException {
    validateState();
    // make sure the policy group exists
    final CertPolicyGroup policyGroup = this.getPolicyGroupById(policyGroupId);
    if (policyGroup == null)
        throw new ConfigurationStoreException("Policy group with id " + policyGroupId + " does not exist");
    try {
        final Query delete = entityManager.createQuery("DELETE from CertPolicyGroupDomainReltn cpr where cpr.certPolicyGroup  = ?1");
        delete.setParameter(1, policyGroup);
        delete.executeUpdate();
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to dissaccociate domains from policy group id ." + policyGroupId, e);
    }
}
Also used : Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with CertPolicyGroup

use of org.nhindirect.config.store.CertPolicyGroup in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method getPolicyGroupByName.

@Override
@Transactional(readOnly = true)
public CertPolicyGroup getPolicyGroupByName(String policyGroupName) throws ConfigurationStoreException {
    validateState();
    try {
        final Query select = entityManager.createQuery("SELECT cpg from CertPolicyGroup cpg WHERE UPPER(cpg.policyGroupName) = ?1");
        select.setParameter(1, policyGroupName.toUpperCase(Locale.getDefault()));
        final CertPolicyGroup rs = (CertPolicyGroup) select.getSingleResult();
        // load relationships now as they were deferred by lazy loading 
        rs.getCertPolicyGroupReltn().size();
        return rs;
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute certificate policy group DAO query.", e);
    }
}
Also used : Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)13 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)10 Transactional (org.springframework.transaction.annotation.Transactional)10 NoResultException (javax.persistence.NoResultException)9 Query (javax.persistence.Query)5 Domain (org.nhindirect.config.store.Domain)4 CertPolicy (org.nhindirect.config.store.CertPolicy)3 ArrayList (java.util.ArrayList)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)2 Certificate (org.nhindirect.config.store.Certificate)2 DNSRecord (org.nhindirect.config.store.DNSRecord)2 Setting (org.nhindirect.config.store.Setting)2 TrustBundle (org.nhindirect.config.store.TrustBundle)2 AddressDao (org.nhindirect.config.store.dao.AddressDao)2 AnchorDao (org.nhindirect.config.store.dao.AnchorDao)2 CertPolicyDao (org.nhindirect.config.store.dao.CertPolicyDao)2 CertificateDao (org.nhindirect.config.store.dao.CertificateDao)2 DNSDao (org.nhindirect.config.store.dao.DNSDao)2