Search in sources :

Example 1 with CertPolicyGroupDomainReltn

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

the class CertPolicyDaoImpl method getPolicyGroupDomainReltns.

@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<CertPolicyGroupDomainReltn> getPolicyGroupDomainReltns() throws ConfigurationStoreException {
    validateState();
    try {
        final Query select = entityManager.createQuery("SELECT cpdr from CertPolicyGroupDomainReltn cpdr");
        final Collection<CertPolicyGroupDomainReltn> rs = select.getResultList();
        if (rs.size() == 0)
            return Collections.emptyList();
        for (CertPolicyGroupDomainReltn reltn : rs) {
            if (!reltn.getCertPolicyGroup().getCertPolicyGroupReltn().isEmpty())
                for (CertPolicyGroupReltn groupReltn : reltn.getCertPolicyGroup().getCertPolicyGroupReltn()) groupReltn.getCertPolicy().getPolicyData();
        }
        return rs;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute certificate policy DAO query.", e);
    }
}
Also used : CertPolicyGroupReltn(org.nhindirect.config.store.CertPolicyGroupReltn) CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) Query(javax.persistence.Query) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with CertPolicyGroupDomainReltn

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

the class CertPolicyDaoImpl method disassociatePolicyGroupFromDomain.

@Override
@Transactional(readOnly = false)
public void disassociatePolicyGroupFromDomain(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 Query select = entityManager.createQuery("SELECT cpr from CertPolicyGroupDomainReltn cpr where cpr.domain  = ?1 " + " and cpr.certPolicyGroup = ?2 ");
        select.setParameter(1, domain);
        select.setParameter(2, policyGroup);
        final CertPolicyGroupDomainReltn reltn = (CertPolicyGroupDomainReltn) select.getSingleResult();
        entityManager.remove(reltn);
        entityManager.flush();
    } catch (NoResultException e) {
        throw new ConfigurationStoreException("Association between domain id " + domainId + " and policy group id " + policyGroupId + " does not exist", e);
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to delete policy group from domain relation.", e);
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with CertPolicyGroupDomainReltn

use of org.nhindirect.config.store.CertPolicyGroupDomainReltn 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 4 with CertPolicyGroupDomainReltn

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

the class CertPolicyDaoImpl method getPolicyGroupsByDomain.

@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<CertPolicyGroupDomainReltn> getPolicyGroupsByDomain(long domainId) 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");
    Collection<CertPolicyGroupDomainReltn> retVal = null;
    try {
        final Query select = entityManager.createQuery("SELECT cpr from CertPolicyGroupDomainReltn cpr where cpr.domain = ?1");
        select.setParameter(1, domain);
        retVal = (Collection<CertPolicyGroupDomainReltn>) select.getResultList();
        if (retVal.size() == 0)
            return Collections.emptyList();
        for (CertPolicyGroupDomainReltn reltn : retVal) {
            if (!reltn.getCertPolicyGroup().getCertPolicyGroupReltn().isEmpty())
                for (CertPolicyGroupReltn groupReltn : reltn.getCertPolicyGroup().getCertPolicyGroupReltn()) groupReltn.getCertPolicy().getPolicyData();
        }
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute policy group to domain relation DAO query.", e);
    }
    return retVal;
}
Also used : CertPolicyGroupReltn(org.nhindirect.config.store.CertPolicyGroupReltn) CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) Query(javax.persistence.Query) 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)

Aggregations

NoResultException (javax.persistence.NoResultException)4 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)4 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Query (javax.persistence.Query)3 Domain (org.nhindirect.config.store.Domain)3 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 CertPolicyGroupReltn (org.nhindirect.config.store.CertPolicyGroupReltn)2