use of org.nhindirect.config.store.Anchor in project nhin-d by DirectProject.
the class AnchorServiceImpl method getAnchor.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.service.AnchorService#getAnchor(java.lang.String, java.lang.String, org.nhindirect.config.service.impl.CertificateGetOptions)
*/
public Anchor getAnchor(String owner, String thumbprint, CertificateGetOptions options) throws ConfigurationServiceException {
List<String> owners = new ArrayList<String>();
owners.add(owner);
List<Anchor> anchors = dao.list(owners);
if (anchors == null || anchors.size() == 0)
return null;
for (Anchor anchor : anchors) if (anchor.getThumbprint().equalsIgnoreCase(thumbprint))
return anchor;
return null;
}
use of org.nhindirect.config.store.Anchor 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("addressDao");
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("dnsDao");
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() });
}
}
use of org.nhindirect.config.store.Anchor in project nhin-d by DirectProject.
the class AnchorServiceTest method testAddAnchors.
/**
* Test the addAnchors method.
*/
public void testAddAnchors() {
final AnchorDao anchorDao = context.mock(AnchorDao.class);
final Collection<Anchor> anchors = Arrays.asList(new Anchor());
context.checking(new Expectations() {
{
for (Anchor anchor : anchors) oneOf(anchorDao).add(anchor);
}
});
AnchorServiceImpl service = new AnchorServiceImpl();
service.setDao(anchorDao);
try {
service.addAnchors(anchors);
} catch (Exception e) {
fail("Exception thrown");
}
}
use of org.nhindirect.config.store.Anchor in project nhin-d by DirectProject.
the class AnchorServiceTest method testListAnchors.
/**
* Test the listAnchors method.
*/
public void testListAnchors() {
final AnchorDao anchorDao = context.mock(AnchorDao.class);
final Long anchorId = 7L;
final int maxResults = 7;
final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
context.checking(new Expectations() {
{
oneOf(anchorDao).listAll();
will(returnValue(Collections.<Anchor>emptyList()));
}
});
AnchorServiceImpl service = new AnchorServiceImpl();
service.setDao(anchorDao);
try {
Collection<Anchor> output = service.listAnchors(anchorId, maxResults, certificateOptions);
assertNotNull("Output is null when passing valid params", output);
assertEquals("Output does not match mocked return value when using valid params", Collections.<Anchor>emptyList(), output);
} catch (Exception e) {
fail("Exception thrown");
}
}
use of org.nhindirect.config.store.Anchor in project nhin-d by DirectProject.
the class AnchorDaoImpl method setStatus.
/*
* (non-Javadoc)
*
* @see org.nhindirect.config.store.dao.AnchorDao#setStatus(java.util.List, org.nhindirect.config.store.EntityStatus)
*/
@Transactional(readOnly = false)
public void setStatus(List<Long> anchorIDs, EntityStatus status) {
if (log.isDebugEnabled())
log.debug("Enter");
List<Anchor> anchors = listByIds(anchorIDs);
if (anchors == null || anchors.size() == 0)
return;
for (Anchor anchor : anchors) {
anchor.setStatus(status);
entityManager.merge(anchor);
}
if (log.isDebugEnabled())
log.debug("Exit");
}
Aggregations