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());
}
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);
}
}
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);
}
}
Aggregations