use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.
the class DomainDaoImpl method add.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.store.dao.DomainDao#add(org.nhindirect.config.store.Domain)
*/
@Transactional(readOnly = false)
public void add(Domain item) {
if (log.isDebugEnabled())
log.debug("Enter");
if (item.getDomainName() == null || item.getDomainName().isEmpty())
throw new ConfigurationStoreException("Domain name cannot be empty or null");
// to work.
if (item != null) {
String pm = item.getPostMasterEmail();
Long pmId = item.getPostmasterAddressId();
Collection<Address> addresses = item.getAddresses();
if ((pmId != null) && (pmId.longValue() == 0)) {
item.setPostmasterAddressId((Long) null);
}
item.setAddresses(null);
item.setCreateTime(Calendar.getInstance());
item.setUpdateTime(item.getCreateTime());
if (log.isDebugEnabled())
log.debug("Calling JPA to persist the Domain");
entityManager.persist(item);
entityManager.flush();
if (log.isDebugEnabled())
log.debug("Persisted the bare Domain");
boolean needUpdate = false;
if ((addresses != null) && (addresses.size() > 0)) {
item.setAddresses(addresses);
needUpdate = true;
}
if ((pm != null) && (pm.length() > 0)) {
item.setPostMasterEmail(pm);
needUpdate = true;
}
if (needUpdate) {
if (log.isDebugEnabled())
log.debug("Updating the domain with Address info");
update(item);
}
if (log.isDebugEnabled())
log.debug("Returned from JPA: Domain ID=" + item.getId());
}
if (log.isDebugEnabled())
log.debug("Exit");
}
use of org.nhindirect.config.store.ConfigurationStoreException 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.ConfigurationStoreException 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.ConfigurationStoreException 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.ConfigurationStoreException 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