Skip to content

Commit

Permalink
Add nub source list to nub dataset description
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoering committed Aug 14, 2015
1 parent fff6e50 commit f2ae43e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Expand Up @@ -29,12 +29,12 @@ public class ChecklistMatcher implements Runnable {
private final NameUsageMatchingService matchingService;
private final UUID datasetKey;

public ChecklistMatcher(MatchConfiguration cfg, UUID datasetKey, MetricRegistry registry,
public ChecklistMatcher(NubChangedConfiguration cfg, UUID datasetKey, MetricRegistry registry,
NameUsageService usageService, NameUsageMatchingService matchingService) {
this.datasetKey = datasetKey;
this.usageService = usageService;
this.matchingService = matchingService;
this.matchMeter = registry.getMeters().get(MatchService.MATCH_METER);
this.matchMeter = registry.getMeters().get(NubChangedService.MATCH_METER);
}

public void run() {
Expand Down
Expand Up @@ -7,17 +7,17 @@
import org.kohsuke.MetaInfServices;

@MetaInfServices(Command.class)
public class MatchCommand extends ServiceCommand {
public class NubChangedCommand extends ServiceCommand {

private final MatchConfiguration configuration = new MatchConfiguration();
private final NubChangedConfiguration configuration = new NubChangedConfiguration();

public MatchCommand() {
super("nub-matcher");
public NubChangedCommand() {
super("nub-changed");
}

@Override
protected Service getService() {
return new MatchService(configuration);
return new NubChangedService(configuration);
}

@Override
Expand Down
Expand Up @@ -15,7 +15,7 @@
*
*/
@SuppressWarnings("PublicField")
public class MatchConfiguration {
public class NubChangedConfiguration {

@ParametersDelegate
@Valid
Expand Down
Expand Up @@ -26,8 +26,10 @@
import java.io.StringWriter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
Expand All @@ -39,15 +41,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MatchService extends AbstractIdleService implements MessageCallback<BackboneChangedMessage> {
public class NubChangedService extends AbstractIdleService implements MessageCallback<BackboneChangedMessage> {

private static final Logger LOG = LoggerFactory.getLogger(MatchService.class);
private static final Logger LOG = LoggerFactory.getLogger(NubChangedService.class);

public static final String QUEUE = "clb-matcher";

public static final String MATCH_METER = "taxon.match";

private final MatchConfiguration cfg;
private final NubChangedConfiguration cfg;
private MessageListener listener;
private MessagePublisher publisher;
private IdLookup nubLookup;
Expand All @@ -56,7 +58,7 @@ public class MatchService extends AbstractIdleService implements MessageCallback
private final MetricRegistry registry = new MetricRegistry("matcher");
private final Timer timer = registry.timer("nub matcher process time");

public MatchService(MatchConfiguration configuration) {
public NubChangedService(NubChangedConfiguration configuration) {
this.cfg = configuration;
registry.meter(MATCH_METER);
Injector regInj = cfg.registry.createRegistryInjector();
Expand Down Expand Up @@ -118,6 +120,22 @@ private void updateBackboneDataset(BackboneChangedMessage msg) {
new TaxonomicCoverage(k.scientificName(), null, new InterpretedEnum<String, Rank>("Kingdom", Rank.KINGDOM));
}
nub.setTaxonomicCoverages(Lists.newArrayList(new TaxonomicCoverages("All life", taxa)));

// build new description reusing the existing intro and then list the current sources
StringBuilder description = new StringBuilder();
// remove existing source list
Pattern SOURCE_LIST_PATTERN = Pattern.compile("\\n*The following sources have been used.+$");
description.append(SOURCE_LIST_PATTERN.matcher(nub.getDescription()).replaceAll(""));
// append new source list
description.append("\n\nThe following sources have been used to assemble the GBIF backbone:\n");
description.append("<u>");
for (Map.Entry<UUID, Integer> src : msg.getMetrics().getCountByConstituent().entrySet()) {
Dataset d = datasetService.get(src.getKey());
description.append("<li>" + src.getValue() + " names from "+ d.getTitle() +"</li>");
}
description.append("</u>");
nub.setDescription(description.toString());

// convert to EML and send to registry
try {
StringWriter writer = new StringWriter();
Expand Down

0 comments on commit f2ae43e

Please sign in to comment.