Search in sources :

Example 26 with Domain

use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.

the class DomainDaoImpl method getDomainByName.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#getDomainByName(java.lang.String)
     */
@Transactional(readOnly = true)
public Domain getDomainByName(String name) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    Domain result = null;
    if (name != null) {
        Query select = entityManager.createQuery("SELECT DISTINCT d from Domain d WHERE UPPER(d.domainName) = ?1");
        Query paramQuery = select.setParameter(1, name.toUpperCase(Locale.getDefault()));
        if (paramQuery.getResultList().size() > 0)
            result = (Domain) paramQuery.getSingleResult();
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return result;
}
Also used : Query(javax.persistence.Query) Domain(org.nhindirect.config.store.Domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with Domain

use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.

the class DomainDaoImpl method delete.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#delete(java.lang.String)
     */
@Transactional(readOnly = false)
public void delete(Long anId) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    final Domain domain = getDomain(anId);
    if (domain != null) {
        disassociateTrustBundlesFromDomain(domain.getId());
        removePolicyGroupFromDomain(domain.getId());
        entityManager.remove(domain);
    } else {
        log.warn("No domain matching the id: " + anId + " found.  Unable to delete.");
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : Domain(org.nhindirect.config.store.Domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with Domain

use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.

the class DomainDaoImpl method delete.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#delete(java.lang.String)
     */
@Transactional(readOnly = false)
public void delete(String name) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // delete addresses first if they exist
    final Domain domain = getDomainByName(name);
    if (domain != null) {
        disassociateTrustBundlesFromDomain(domain.getId());
        removePolicyGroupFromDomain(domain.getId());
        entityManager.remove(domain);
    } else {
        log.warn("No domain matching the name: " + name + " found.  Unable to delete.");
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : Domain(org.nhindirect.config.store.Domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with Domain

use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.

the class DomainDaoImpl method searchDomain.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#searchDomain(java.lang.String, org.nhindirect.config.store.EntityStatus)
     */
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Domain> searchDomain(String name, EntityStatus status) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Domain> result = null;
    StringBuffer query = new StringBuffer("");
    Query select = null;
    if (name != null) {
        String search = name.replace('*', '%').toUpperCase(Locale.getDefault());
        search.replace('?', '_');
        query.append("SELECT d from Domain d WHERE UPPER(d.domainName) LIKE ?1 ");
        if (status != null) {
            query.append("AND d.status = ?2");
            select = entityManager.createQuery(query.toString());
            select.setParameter(1, search);
            select.setParameter(2, status);
        } else {
            select = entityManager.createQuery(query.toString());
            select.setParameter(1, search);
        }
    } else {
        if (status != null) {
            query.append("SELECT d from Domain d WHERE d.status = ?1");
            select = entityManager.createQuery(query.toString());
            select.setParameter(1, status);
        } else {
            select = entityManager.createQuery("SELECT d from Domain d");
        }
    }
    result = (List<Domain>) select.getResultList();
    if (result == null) {
        result = new ArrayList<Domain>();
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return result;
}
Also used : Query(javax.persistence.Query) Domain(org.nhindirect.config.store.Domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with Domain

use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method disassociatePolicyGroupsFromDomain.

@Override
@Transactional(readOnly = false)
public void disassociatePolicyGroupsFromDomain(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 CertPolicyGroupDomainReltn cpr where cpr.domain  = ?1");
        delete.setParameter(1, domain);
        delete.executeUpdate();
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to dissaccociate group policies from domain id ." + domainId, e);
    }
}
Also used : Query(javax.persistence.Query) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Domain (org.nhindirect.config.store.Domain)32 Transactional (org.springframework.transaction.annotation.Transactional)14 Query (javax.persistence.Query)10 Expectations (org.jmock.Expectations)10 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)10 TrustBundle (org.nhindirect.config.store.TrustBundle)9 NoResultException (javax.persistence.NoResultException)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)8 DomainDao (org.nhindirect.config.store.dao.DomainDao)7 ApplicationContext (org.springframework.context.ApplicationContext)7 File (java.io.File)5 DomainServiceImpl (org.nhindirect.config.service.impl.DomainServiceImpl)5 Address (org.nhindirect.config.store.Address)5 ArrayList (java.util.ArrayList)4 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)4 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)4 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)3 AddressDao (org.nhindirect.config.store.dao.AddressDao)3 List (java.util.List)2 Anchor (org.nhindirect.config.store.Anchor)2