use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method getTrustBundlesByDomain.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<TrustBundleDomainReltn> getTrustBundlesByDomain(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<TrustBundleDomainReltn> retVal = null;
try {
final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain = ?1");
select.setParameter(1, domain);
retVal = (Collection<TrustBundleDomainReltn>) select.getResultList();
if (retVal.size() == 0)
return Collections.emptyList();
for (TrustBundleDomainReltn reltn : retVal) {
if (!reltn.getTrustBundle().getTrustBundleAnchors().isEmpty())
for (TrustBundleAnchor anchor : reltn.getTrustBundle().getTrustBundleAnchors()) anchor.getData();
}
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to execute trust bundle relation DAO query.", e);
}
return retVal;
}
use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.
the class DomainDaoImpl method getDomains.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.store.dao.DomainDao#getDomains(java.lang.String, org.nhindirect.config.store.EntityStatus)
*
* Convert the list of names into a String to be used in an IN clause (i.e.
* {"One", "Two", "Three"} --> ('One', 'Two', 'Three'))
*/
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Domain> getDomains(List<String> names, EntityStatus status) {
if (log.isDebugEnabled())
log.debug("Enter");
List<Domain> result = null;
Query select = null;
if (names != null) {
StringBuffer nameList = new StringBuffer("(");
for (String aName : names) {
if (nameList.length() > 1) {
nameList.append(", ");
}
nameList.append("'").append(aName.toUpperCase(Locale.getDefault())).append("'");
}
nameList.append(")");
String query = "SELECT d from Domain d WHERE UPPER(d.domainName) IN " + nameList.toString();
if (status != null) {
select = entityManager.createQuery(query + " AND d.status = ?1");
select.setParameter(1, status);
} else {
select = entityManager.createQuery(query);
}
} else {
if (status != null) {
select = entityManager.createQuery("SELECT d from Domain d WHERE d.status = ?1");
select.setParameter(1, status);
} else {
select = entityManager.createQuery("SELECT d from Domain d");
}
}
@SuppressWarnings("rawtypes") List rs = select.getResultList();
if ((rs.size() != 0) && (rs.get(0) instanceof Domain)) {
result = (List<Domain>) rs;
} else {
result = new ArrayList<Domain>();
}
if (log.isDebugEnabled())
log.debug("Exit");
return result;
}
use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.
the class DomainDaoImpl method listDomains.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.store.dao.DomainDao#listDomains(java.lang.String, int)
*/
// TODO I'm not sure if this is doing the right thing. I suspect that the
// real intent is to do some kind of db paging
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Domain> listDomains(String name, int count) {
if (log.isDebugEnabled())
log.debug("Enter");
List<Domain> result = null;
Query select = null;
if (name != null) {
select = entityManager.createQuery("SELECT d from Domain d WHERE UPPER(d.domainName) = ?1");
select.setParameter(1, name.toUpperCase(Locale.getDefault()));
} else {
select = entityManager.createQuery("SELECT d from Domain d");
}
// assuming that a count of zero really means no limit
if (count > 0) {
select.setMaxResults(count);
}
@SuppressWarnings("rawtypes") List rs = select.getResultList();
if ((rs.size() != 0) && (rs.get(0) instanceof Domain)) {
result = (List<Domain>) rs;
}
if (log.isDebugEnabled())
log.debug("Exit");
return result;
}
use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method disassociateTrustBundlesFromDomain.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundlesFromDomain(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");
try {
final Query delete = entityManager.createQuery("DELETE from TrustBundleDomainReltn tbd where tbd.domain = ?1");
delete.setParameter(1, domain);
delete.executeUpdate();
entityManager.flush();
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to dissaccociate trust bundle from domain id ." + domainId, e);
}
}
use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.
the class SpringBaseTest method cleanDataStore.
protected void cleanDataStore() throws Exception {
final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
final AddressDao addressDao = (AddressDao) ctx.getBean("addressDaoImpl");
final TrustBundleDao trustDao = (TrustBundleDao) ctx.getBean("trustBundleDao");
final DomainDao domainDao = (DomainDao) ctx.getBean("domainDao");
final AnchorDao anchorDao = (AnchorDao) ctx.getBean("anchorDao");
final CertificateDao certDao = (CertificateDao) ctx.getBean("certificateDao");
final DNSDao dnsDao = (DNSDao) ctx.getBean("DNSDaoImpl");
final SettingDao settingDao = (SettingDao) ctx.getBean("settingDao");
final CertPolicyDao policyDao = (CertPolicyDao) ctx.getBean("certPolicyDao");
// clean anchors
final List<Anchor> anchors = anchorDao.listAll();
if (!anchors.isEmpty()) {
final List<Long> anchorIds = new ArrayList<Long>();
for (Anchor anchor : anchors) anchorIds.add(anchor.getId());
anchorDao.delete(anchorIds);
}
// clean domains and the trust bundle domain relationships
final List<Domain> domains = domainDao.listDomains(null, domainDao.count());
if (domains != null) {
for (Domain domain : domains) {
Collection<Address> addresses = addressDao.getByDomain(domain, null);
if (addresses != null) {
for (Address address : addresses) {
addressDao.delete(address.getEmailAddress());
}
}
trustDao.disassociateTrustBundlesFromDomain(domain.getId());
domainDao.delete(domain.getId());
}
}
assertEquals(0, domainDao.count());
//clean trust bundles
Collection<TrustBundle> bundles = trustDao.getTrustBundles();
for (TrustBundle bundle : bundles) trustDao.deleteTrustBundles(new long[] { bundle.getId() });
bundles = trustDao.getTrustBundles();
assertEquals(0, bundles.size());
// clean certificates
final List<Certificate> certs = certDao.list((String) null);
if (!certs.isEmpty()) {
for (Certificate cert : certs) {
certDao.delete(cert.getOwner());
}
}
// clean DNS records
final Collection<DNSRecord> records = dnsDao.get(Type.ANY);
if (!records.isEmpty()) {
for (DNSRecord record : records) dnsDao.remove(record.getId());
}
// clean settings
final Collection<Setting> settings = settingDao.getAll();
if (!settings.isEmpty()) {
for (Setting setting : settings) settingDao.delete(Arrays.asList(setting.getName()));
}
// clean policies
final Collection<CertPolicy> policies = policyDao.getPolicies();
if (!policies.isEmpty()) {
for (CertPolicy policy : policies) policyDao.deletePolicies(new long[] { policy.getId() });
}
// clean policy groups
final Collection<CertPolicyGroup> groups = policyDao.getPolicyGroups();
if (!groups.isEmpty()) {
for (CertPolicyGroup group : groups) policyDao.deletePolicyGroups(new long[] { group.getId() });
}
}
Aggregations