Search in sources :

Example 21 with Domain

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

the class TrustBundleService_realDataTest method testAssociateDomainToBundle_incomingAndOutgoingTrue_assertIncomingAndOutgoingFlags.

public void testAssociateDomainToBundle_incomingAndOutgoingTrue_assertIncomingAndOutgoingFlags() throws Exception {
    File bundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    // add a bundle
    TrustBundleService trustService = (TrustBundleService) ctx.getBean("trustBundleSvc");
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Test Bundle");
    bundle.setBundleURL(filePrefix + bundleLocation.getAbsolutePath());
    trustService.addTrustBundle(bundle);
    // add a domain
    DomainService domainService = (DomainService) ctx.getBean("domainSvc");
    Domain domain = new Domain();
    domain.setDomainName("Test Domain");
    domain.setStatus(EntityStatus.ENABLED);
    domainService.addDomain(domain);
    //associate domain to bundle
    trustService.associateTrustBundleToDomain(domain.getId(), bundle.getId(), true, true);
    // assert the association
    Collection<TrustBundleDomainReltn> associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    assertEquals(1, associatedBundel.size());
    TrustBundleDomainReltn reltn = associatedBundel.iterator().next();
    assertTrue(reltn.isIncoming());
    assertTrue(reltn.isOutgoing());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Example 22 with Domain

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

the class TrustBundleService_realDataTest method testAssociateDomainToBundle_incomingFalseOutgoingTrue_assertIncomingAndOutgoingFlags.

public void testAssociateDomainToBundle_incomingFalseOutgoingTrue_assertIncomingAndOutgoingFlags() throws Exception {
    File bundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    // add a bundle
    TrustBundleService trustService = (TrustBundleService) ctx.getBean("trustBundleSvc");
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Test Bundle");
    bundle.setBundleURL(filePrefix + bundleLocation.getAbsolutePath());
    trustService.addTrustBundle(bundle);
    // add a domain
    DomainService domainService = (DomainService) ctx.getBean("domainSvc");
    Domain domain = new Domain();
    domain.setDomainName("Test Domain");
    domain.setStatus(EntityStatus.ENABLED);
    domainService.addDomain(domain);
    //associate domain to bundle
    trustService.associateTrustBundleToDomain(domain.getId(), bundle.getId(), false, true);
    // assert the association
    Collection<TrustBundleDomainReltn> associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    assertEquals(1, associatedBundel.size());
    TrustBundleDomainReltn reltn = associatedBundel.iterator().next();
    assertTrue(reltn.isOutgoing());
    assertFalse(reltn.isIncoming());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Example 23 with Domain

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

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

the class TrustBundleDaoImpl method disassociateTrustBundleFromDomain.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundleFromDomain(long domainId, long trustBundleId) 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 trust bundle exists
    final TrustBundle trustBundle = this.getTrustBundleById(trustBundleId);
    if (trustBundle == null)
        throw new ConfigurationStoreException("Trust budnel with id " + trustBundle + " does not exist");
    try {
        final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain  = ?1 " + " and tbd.trustBundle = ?2 ");
        select.setParameter(1, domain);
        select.setParameter(2, trustBundle);
        final TrustBundleDomainReltn reltn = (TrustBundleDomainReltn) select.getSingleResult();
        entityManager.remove(reltn);
        entityManager.flush();
    } catch (NoResultException e) {
        throw new ConfigurationStoreException("Association between domain id " + domainId + " and trust bundle id" + trustBundleId + " does not exist", e);
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to delete trust bundle to domain relation.", e);
    }
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) 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) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Domain

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

the class TrustBundleDaoImpl method associateTrustBundleToDomain.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void associateTrustBundleToDomain(long domainId, long trustBundleId, boolean incoming, boolean outgoing) 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 trust bundle exists
    final TrustBundle trustBundle = this.getTrustBundleById(trustBundleId);
    if (trustBundle == null)
        throw new ConfigurationStoreException("Trust budnel with id " + trustBundle + " does not exist");
    try {
        final TrustBundleDomainReltn domainTrustBundleAssoc = new TrustBundleDomainReltn();
        domainTrustBundleAssoc.setDomain(domain);
        domainTrustBundleAssoc.setTrustBundle(trustBundle);
        domainTrustBundleAssoc.setIncoming(incoming);
        domainTrustBundleAssoc.setOutgoing(outgoing);
        entityManager.persist(domainTrustBundleAssoc);
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to associate trust bundle to domain.", e);
    }
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Domain (org.nhindirect.config.store.Domain)32 Transactional (org.springframework.transaction.annotation.Transactional)14 Query (javax.persistence.Query)10 Expectations (org.jmock.Expectations)10 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)10 TrustBundle (org.nhindirect.config.store.TrustBundle)9 NoResultException (javax.persistence.NoResultException)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)8 DomainDao (org.nhindirect.config.store.dao.DomainDao)7 ApplicationContext (org.springframework.context.ApplicationContext)7 File (java.io.File)5 DomainServiceImpl (org.nhindirect.config.service.impl.DomainServiceImpl)5 Address (org.nhindirect.config.store.Address)5 ArrayList (java.util.ArrayList)4 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)4 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)4 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)3 AddressDao (org.nhindirect.config.store.dao.AddressDao)3 List (java.util.List)2 Anchor (org.nhindirect.config.store.Anchor)2