use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class DNSDaoImpl method update.
/**
* {@inheritDoc}}
*/
@Override
@Transactional(readOnly = false)
public void update(long id, DNSRecord record) {
if (log.isDebugEnabled())
log.debug("remove(long id, DNSRecord record) Enter");
try {
// get the record
if (record.getType() == Type.ANY)
throw new ConfigurationStoreException("Record type for update cannot be ANY");
DNSRecord toUpdate = get(id);
if (toUpdate == null)
throw new ConfigurationStoreException("Record with id " + id + " does not exist.");
toUpdate.setType(record.getType());
toUpdate.setName(record.getName());
toUpdate.setTtl(record.getTtl());
toUpdate.setDclass(record.getDclass());
toUpdate.setData(record.getData());
entityManager.merge(toUpdate);
entityManager.flush();
if (log.isDebugEnabled())
log.debug("1 DNS record updated.");
} finally {
if (log.isDebugEnabled())
log.debug("remove(long id, DNSRecord record) Exit");
}
}
use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class DNSDaoImpl method add.
/**
* {@inheritDoc}}
*/
@Override
@Transactional(readOnly = false)
public void add(Collection<DNSRecord> records) {
if (log.isDebugEnabled())
log.debug("add() Enter");
try {
if (records != null && records.size() > 0) {
for (DNSRecord record : records) {
if (record.getType() == Type.ANY)
throw new ConfigurationStoreException("Cannot add records with type ANY.");
else {
Collection<DNSRecord> checkRecs = get(record.getName(), record.getType());
if (checkRecs.contains(record))
throw new ConfigurationStoreException("Record name " + record.getName() + " and type " + record.getType() + " already exists with same rdata.");
}
record.setCreateTime(Calendar.getInstance());
if (log.isDebugEnabled())
log.debug("Persisting DNS record\r\n\tName: " + record.getName() + "\r\n\tType: " + record.getType());
entityManager.persist(record);
}
if (log.isDebugEnabled())
log.debug("Flushing " + records.size() + " added records.");
entityManager.flush();
}
} finally {
if (log.isDebugEnabled())
log.debug("add() Exit");
}
}
use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class SettingDaoImpl method add.
/**
* {@inheritDoc}
*/
@Transactional(readOnly = false)
public void add(String name, String value) {
if (log.isDebugEnabled())
log.debug("Enter");
if (name == null || name.isEmpty() || value == null)
return;
// make sure this setting doesn't already exist
if (this.getByNames(Arrays.asList(name)).size() > 0)
throw new ConfigurationStoreException("Setting " + name + " already exists.");
Setting setting = new Setting();
setting.setName(name);
setting.setValue(value);
setting.setCreateTime(Calendar.getInstance());
setting.setUpdateTime(setting.getCreateTime());
if (log.isDebugEnabled())
log.debug("Calling JPA to persist the setting");
entityManager.persist(setting);
entityManager.flush();
if (log.isDebugEnabled())
log.debug("Returned from JPA: Setting ID=" + setting.getId());
if (log.isDebugEnabled())
log.debug("Exit");
}
use of org.nhindirect.config.store.ConfigurationStoreException 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.ConfigurationStoreException in project nhin-d by DirectProject.
the class TrustBundleDaoImpl method disassociateTrustBundleFromDomains.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundleFromDomains(long trustBundleId) throws ConfigurationStoreException {
validateState();
// 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 delete = entityManager.createQuery("DELETE from TrustBundleDomainReltn tbd where tbd.trustBundle = ?1");
delete.setParameter(1, trustBundle);
delete.executeUpdate();
entityManager.flush();
} catch (Exception e) {
throw new ConfigurationStoreException("Failed to dissaccociate domains from trust bundle id ." + trustBundleId, e);
}
}
Aggregations