@Test public void testAddDomainUrl() throws Exception { service.addDomainUrl("test.com", "www.test.com", 1000); assertEquals(1, domainRepo.count()); MongoDomainURL domainURL = domainRepo.findOne("{_id: #}", "www.test.com").as(MongoDomainURL.class); assertEquals("www.test.com", domainURL.getAddress()); assertEquals("test.com", domainURL.getName()); assertEquals(1000, domainURL.getCoolDownPeriod()); }
public DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod) { MongoDomainURL old = domainRepo.findOne("{'_id': #}", domainUrl).projection("{_id: 1}").as(MongoDomainURL.class); if (old == null) { domainRepo.findAndModify("{'_id': #}", domainUrl).upsert().with( "{$set: { name: #, address: #, coolDownPeriod: #}}", domainName, domainUrl, coolDownPeriod).as(MongoDomainURL.class); } return new DomainURL(domainName, domainUrl, coolDownPeriod); }
MongoUrlServiceImpl implements UrlService { public DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod) { MongoDomainURL old = domainRepo.findOne("{'_id': #}", domainUrl).projection("{_id: 1}").as(MongoDomainURL.class); if (old == null) { domainRepo.findAndModify("{'_id': #}", domainUrl).upsert().with( "{$set: { name: #, address: #, coolDownPeriod: #}}", domainName, domainUrl, coolDownPeriod).as(MongoDomainURL.class); } return new DomainURL(domainName, domainUrl, coolDownPeriod); } }
MongoUrlServiceImpl implements UrlService { public DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod) { MongoDomainURL old = domainRepo.findOne("{'_id': #}", domainUrl).projection("{_id: 1}").as(MongoDomainURL.class); if (old == null) { domainRepo.findAndModify("{'_id': #}", domainUrl).upsert().with( "{$set: { name: #, address: #, coolDownPeriod: #}}", domainName, domainUrl, coolDownPeriod).as(MongoDomainURL.class); } return new DomainURL(domainName, domainUrl, coolDownPeriod); }  }
MongoUrlServiceImpl implements UrlService { public DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod) { MongoDomainURL old = domainRepo.findOne("{'_id': #}", domainUrl).projection("{_id: 1}").as(MongoDomainURL.class); if (old == null) { domainRepo.findAndModify("{'_id': #}", domainUrl).upsert().with( "{$set: { name: #, address: #, coolDownPeriod: #}}", domainName, domainUrl, coolDownPeriod).as(MongoDomainURL.class); } return new DomainURL(domainName, domainUrl, coolDownPeriod); }  @PostConstruct void init(); DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod); @Override void addSimpleUrls(List<String> urls, String status, String domainURL, String sourceDomainName); @Override void addDomainLinks(List<DomainLink> domainLinks); @Override List<DomainURL> findDomains(Pageable pageable); @Override Collection<SimpleURL> findURLs(String address, String status, int pageNo, int pageSize); @Override Collection<SimpleURL> findExternalURLs(String address, String status, int pageNo, int pageSize); void removeSimpleUrl(String url); @Override void updateSimpleUrlsStatus(List<String> urls, String status); @Override void updateSimpleUrlErrorStatus(String url, int errorDelta); void removeDomainUrl(String domainURL); @Override void removeDomains(); @Override List<Entries> query(String query); @Override long countAllNodes(); @Override long countAllDomains(); @Override long countAllLinks(); @Override long countDomainLinks(String domainUrl); }
MongoUrlServiceImpl implements UrlService { public DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod) { MongoDomainURL old = domainRepo.findOne("{'_id': #}", domainUrl).projection("{_id: 1}").as(MongoDomainURL.class); if (old == null) { domainRepo.findAndModify("{'_id': #}", domainUrl).upsert().with( "{$set: { name: #, address: #, coolDownPeriod: #}}", domainName, domainUrl, coolDownPeriod).as(MongoDomainURL.class); } return new DomainURL(domainName, domainUrl, coolDownPeriod); }  @PostConstruct void init(); DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod); @Override void addSimpleUrls(List<String> urls, String status, String domainURL, String sourceDomainName); @Override void addDomainLinks(List<DomainLink> domainLinks); @Override List<DomainURL> findDomains(Pageable pageable); @Override Collection<SimpleURL> findURLs(String address, String status, int pageNo, int pageSize); @Override Collection<SimpleURL> findExternalURLs(String address, String status, int pageNo, int pageSize); void removeSimpleUrl(String url); @Override void updateSimpleUrlsStatus(List<String> urls, String status); @Override void updateSimpleUrlErrorStatus(String url, int errorDelta); void removeDomainUrl(String domainURL); @Override void removeDomains(); @Override List<Entries> query(String query); @Override long countAllNodes(); @Override long countAllDomains(); @Override long countAllLinks(); @Override long countDomainLinks(String domainUrl); @Autowired
    public MetricsConfig metricsConfig; @Autowired
    public MongoConfig mongoConfig; public MongoCollection domainRepo; public MongoCollection urlRepo; }