use of org.nhindirect.config.store.TrustBundle 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.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method getTrustBundleById.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = true)
public TrustBundle getTrustBundleById(long id) throws ConfigurationStoreException {
validateState();
try {
Query select = entityManager.createQuery("SELECT tb from TrustBundle tb WHERE tb.id = ?1");
select.setParameter(1, id);
TrustBundle rs = (TrustBundle) select.getSingleResult();
// make sure the anchors are loaded
if (!rs.getTrustBundleAnchors().isEmpty())
for (TrustBundleAnchor anchor : rs.getTrustBundleAnchors()) anchor.getData();
return rs;
} catch (NoResultException e) {
return null;
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to execute trust bundle DAO query.", e);
}
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method updateTrustBundleSigningCertificate.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void updateTrustBundleSigningCertificate(long trustBundleId, X509Certificate signingCert) throws ConfigurationStoreException {
validateState();
try {
final TrustBundle existingBundle = this.getTrustBundleById(trustBundleId);
if (existingBundle == null)
throw new ConfigurationStoreException("Trust bundle does not exist");
if (signingCert == null)
existingBundle.setSigningCertificateData(null);
else
existingBundle.setSigningCertificateData(signingCert.getEncoded());
entityManager.persist(existingBundle);
entityManager.flush();
} catch (ConfigurationStoreException cse) {
throw cse;
}///CLOVER:OFF
catch (Exception e) {
throw new ConfigurationStoreException("Failed to update bundle last refresh error.", e);
}
///CLOVER:ON
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method getTrustBundleByName.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = true)
public TrustBundle getTrustBundleByName(String bundleName) throws ConfigurationStoreException {
validateState();
try {
Query select = entityManager.createQuery("SELECT tb from TrustBundle tb WHERE UPPER(tb.bundleName) = ?1");
select.setParameter(1, bundleName.toUpperCase(Locale.getDefault()));
TrustBundle rs = (TrustBundle) select.getSingleResult();
// make sure the anchors are loaded
if (!rs.getTrustBundleAnchors().isEmpty())
for (TrustBundleAnchor anchor : rs.getTrustBundleAnchors()) anchor.getData();
return rs;
} catch (NoResultException e) {
return null;
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to execute trust bundle DAO query.", e);
}
}
use of org.nhindirect.config.store.TrustBundle in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method addTrustBundle.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void addTrustBundle(TrustBundle bundle) throws ConfigurationStoreException {
validateState();
try {
final TrustBundle existingBundle = this.getTrustBundleByName(bundle.getBundleName());
if (existingBundle != null)
throw new ConfigurationStoreException("Trust bundle " + bundle.getBundleName() + " already exists");
bundle.setCreateTime(Calendar.getInstance(Locale.getDefault()));
entityManager.persist(bundle);
entityManager.flush();
} catch (ConfigurationStoreException cse) {
throw cse;
}///CLOVER:OFF
catch (Exception e) {
throw new ConfigurationStoreException("Failed to add trust bundle " + bundle.getBundleName(), e);
}
///CLOVER:ON
}
Aggregations