Search in sources :

Example 6 with TrustBundleDomainReltn

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

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

use of org.nhindirect.config.store.TrustBundleDomainReltn 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)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)8 TrustBundle (org.nhindirect.config.store.TrustBundle)7 File (java.io.File)5 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)5 ApplicationContext (org.springframework.context.ApplicationContext)5 NoResultException (javax.persistence.NoResultException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Query (javax.persistence.Query)2 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)1