@Test public void testUpdateBackboneDataset() throws Exception { assertEquals("The GBIF Backbone Taxonomy.\n Something more.", BackboneDatasetUpdater.SOURCE_LIST_PATTERN.matcher("The GBIF Backbone Taxonomy.\n Something more." + "\n\nThe following 57 sources from the <a href='http: .replaceAll("")); }
public Dataset updateBackboneDataset(DatasetMetrics metrics) { LOG.info("Updating backbone dataset metadata"); Dataset nub = datasetService.get(Constants.NUB_DATASET_KEY); nub.setPubDate(metrics.getCreated()); List<TaxonomicCoverage> taxa = Lists.<TaxonomicCoverage>newArrayList(); for (Kingdom k : Kingdom.values()) { new TaxonomicCoverage(k.scientificName(), null, new InterpretedEnum<String, Rank>("Kingdom", Rank.KINGDOM)); } nub.setTaxonomicCoverages(Lists.newArrayList(new TaxonomicCoverages("All life", taxa))); nub.setRights("CC0 1.0"); int plaziCounts = 0; List<NubConstituent> constituents = Lists.newArrayList(); for (Map.Entry<UUID, Integer> src : metrics.getCountByConstituent().entrySet()) { Dataset d = datasetService.get(src.getKey()); if (d.getPublishingOrganizationKey().equals(Constants.PLAZI_ORG_KEY)) { plaziCounts += src.getValue(); } else { constituents.add(new NubConstituent(src.getKey(), d.getTitle(), src.getValue())); } } if (plaziCounts > 0) { Organization plazi = organizationService.get(Constants.PLAZI_ORG_KEY); constituents.add(new NubConstituent(Constants.PLAZI_ORG_KEY, plazi.getTitle(), plaziCounts)); } Collections.sort(constituents); StringBuilder description = new StringBuilder(); description.append(SOURCE_LIST_PATTERN.matcher(nub.getDescription()).replaceAll("")); description.append("\n\nThe following " + constituents.size() + " sources from the " + "<a href='http: "have been used to assemble the GBIF backbone:\n"); description.append("<ul>"); for (NubConstituent nc : constituents) { description.append("<li>" + nc.title+ " - " + nc.count+ " names</li>"); } description.append("</ul>"); nub.setDescription(description.toString()); try { StringWriter writer = new StringWriter(); EMLWriter.write(nub, writer); writer.close(); InputStream stream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes(Charsets.UTF_8)); datasetService.insertMetadata(Constants.NUB_DATASET_KEY, stream); } catch (RuntimeException | IOException e) { LOG.error("Failed to update backbone dataset metadata", e); } Set<UUID> constituentKeys = Sets.newHashSet(metrics.getCountByConstituent().keySet()); LOG.info("Updating backbone source network with {} constituents", constituentKeys.size()); for (Dataset d : Iterables.networkDatasets(Constants.NUB_NETWORK_KEY, null, networkService)) { if (!constituentKeys.remove(d.getKey())) { LOG.debug("Remove backbone source network constituent {} {}", d.getKey(), d.getTitle()); networkService.removeConstituent(Constants.NUB_NETWORK_KEY, d.getKey()); } } for (UUID datasetKey : constituentKeys) { LOG.debug("Add new backbone source network constituent {}", datasetKey); networkService.addConstituent(Constants.NUB_NETWORK_KEY, datasetKey); } return nub; }
BackboneDatasetUpdater { public Dataset updateBackboneDataset(DatasetMetrics metrics) { LOG.info("Updating backbone dataset metadata"); Dataset nub = datasetService.get(Constants.NUB_DATASET_KEY); nub.setPubDate(metrics.getCreated()); List<TaxonomicCoverage> taxa = Lists.<TaxonomicCoverage>newArrayList(); for (Kingdom k : Kingdom.values()) { new TaxonomicCoverage(k.scientificName(), null, new InterpretedEnum<String, Rank>("Kingdom", Rank.KINGDOM)); } nub.setTaxonomicCoverages(Lists.newArrayList(new TaxonomicCoverages("All life", taxa))); nub.setRights("CC0 1.0"); int plaziCounts = 0; List<NubConstituent> constituents = Lists.newArrayList(); for (Map.Entry<UUID, Integer> src : metrics.getCountByConstituent().entrySet()) { Dataset d = datasetService.get(src.getKey()); if (d.getPublishingOrganizationKey().equals(Constants.PLAZI_ORG_KEY)) { plaziCounts += src.getValue(); } else { constituents.add(new NubConstituent(src.getKey(), d.getTitle(), src.getValue())); } } if (plaziCounts > 0) { Organization plazi = organizationService.get(Constants.PLAZI_ORG_KEY); constituents.add(new NubConstituent(Constants.PLAZI_ORG_KEY, plazi.getTitle(), plaziCounts)); } Collections.sort(constituents); StringBuilder description = new StringBuilder(); description.append(SOURCE_LIST_PATTERN.matcher(nub.getDescription()).replaceAll("")); description.append("\n\nThe following " + constituents.size() + " sources from the " + "<a href='http: "have been used to assemble the GBIF backbone:\n"); description.append("<ul>"); for (NubConstituent nc : constituents) { description.append("<li>" + nc.title+ " - " + nc.count+ " names</li>"); } description.append("</ul>"); nub.setDescription(description.toString()); try { StringWriter writer = new StringWriter(); EMLWriter.write(nub, writer); writer.close(); InputStream stream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes(Charsets.UTF_8)); datasetService.insertMetadata(Constants.NUB_DATASET_KEY, stream); } catch (RuntimeException | IOException e) { LOG.error("Failed to update backbone dataset metadata", e); } Set<UUID> constituentKeys = Sets.newHashSet(metrics.getCountByConstituent().keySet()); LOG.info("Updating backbone source network with {} constituents", constituentKeys.size()); for (Dataset d : Iterables.networkDatasets(Constants.NUB_NETWORK_KEY, null, networkService)) { if (!constituentKeys.remove(d.getKey())) { LOG.debug("Remove backbone source network constituent {} {}", d.getKey(), d.getTitle()); networkService.removeConstituent(Constants.NUB_NETWORK_KEY, d.getKey()); } } for (UUID datasetKey : constituentKeys) { LOG.debug("Add new backbone source network constituent {}", datasetKey); networkService.addConstituent(Constants.NUB_NETWORK_KEY, datasetKey); } return nub; } }
BackboneDatasetUpdater { public Dataset updateBackboneDataset(DatasetMetrics metrics) { LOG.info("Updating backbone dataset metadata"); Dataset nub = datasetService.get(Constants.NUB_DATASET_KEY); nub.setPubDate(metrics.getCreated()); List<TaxonomicCoverage> taxa = Lists.<TaxonomicCoverage>newArrayList(); for (Kingdom k : Kingdom.values()) { new TaxonomicCoverage(k.scientificName(), null, new InterpretedEnum<String, Rank>("Kingdom", Rank.KINGDOM)); } nub.setTaxonomicCoverages(Lists.newArrayList(new TaxonomicCoverages("All life", taxa))); nub.setRights("CC0 1.0"); int plaziCounts = 0; List<NubConstituent> constituents = Lists.newArrayList(); for (Map.Entry<UUID, Integer> src : metrics.getCountByConstituent().entrySet()) { Dataset d = datasetService.get(src.getKey()); if (d.getPublishingOrganizationKey().equals(Constants.PLAZI_ORG_KEY)) { plaziCounts += src.getValue(); } else { constituents.add(new NubConstituent(src.getKey(), d.getTitle(), src.getValue())); } } if (plaziCounts > 0) { Organization plazi = organizationService.get(Constants.PLAZI_ORG_KEY); constituents.add(new NubConstituent(Constants.PLAZI_ORG_KEY, plazi.getTitle(), plaziCounts)); } Collections.sort(constituents); StringBuilder description = new StringBuilder(); description.append(SOURCE_LIST_PATTERN.matcher(nub.getDescription()).replaceAll("")); description.append("\n\nThe following " + constituents.size() + " sources from the " + "<a href='http: "have been used to assemble the GBIF backbone:\n"); description.append("<ul>"); for (NubConstituent nc : constituents) { description.append("<li>" + nc.title+ " - " + nc.count+ " names</li>"); } description.append("</ul>"); nub.setDescription(description.toString()); try { StringWriter writer = new StringWriter(); EMLWriter.write(nub, writer); writer.close(); InputStream stream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes(Charsets.UTF_8)); datasetService.insertMetadata(Constants.NUB_DATASET_KEY, stream); } catch (RuntimeException | IOException e) { LOG.error("Failed to update backbone dataset metadata", e); } Set<UUID> constituentKeys = Sets.newHashSet(metrics.getCountByConstituent().keySet()); LOG.info("Updating backbone source network with {} constituents", constituentKeys.size()); for (Dataset d : Iterables.networkDatasets(Constants.NUB_NETWORK_KEY, null, networkService)) { if (!constituentKeys.remove(d.getKey())) { LOG.debug("Remove backbone source network constituent {} {}", d.getKey(), d.getTitle()); networkService.removeConstituent(Constants.NUB_NETWORK_KEY, d.getKey()); } } for (UUID datasetKey : constituentKeys) { LOG.debug("Add new backbone source network constituent {}", datasetKey); networkService.addConstituent(Constants.NUB_NETWORK_KEY, datasetKey); } return nub; } BackboneDatasetUpdater(DatasetService datasetService, OrganizationService organizationService, NetworkService networkService); }
BackboneDatasetUpdater { public Dataset updateBackboneDataset(DatasetMetrics metrics) { LOG.info("Updating backbone dataset metadata"); Dataset nub = datasetService.get(Constants.NUB_DATASET_KEY); nub.setPubDate(metrics.getCreated()); List<TaxonomicCoverage> taxa = Lists.<TaxonomicCoverage>newArrayList(); for (Kingdom k : Kingdom.values()) { new TaxonomicCoverage(k.scientificName(), null, new InterpretedEnum<String, Rank>("Kingdom", Rank.KINGDOM)); } nub.setTaxonomicCoverages(Lists.newArrayList(new TaxonomicCoverages("All life", taxa))); nub.setRights("CC0 1.0"); int plaziCounts = 0; List<NubConstituent> constituents = Lists.newArrayList(); for (Map.Entry<UUID, Integer> src : metrics.getCountByConstituent().entrySet()) { Dataset d = datasetService.get(src.getKey()); if (d.getPublishingOrganizationKey().equals(Constants.PLAZI_ORG_KEY)) { plaziCounts += src.getValue(); } else { constituents.add(new NubConstituent(src.getKey(), d.getTitle(), src.getValue())); } } if (plaziCounts > 0) { Organization plazi = organizationService.get(Constants.PLAZI_ORG_KEY); constituents.add(new NubConstituent(Constants.PLAZI_ORG_KEY, plazi.getTitle(), plaziCounts)); } Collections.sort(constituents); StringBuilder description = new StringBuilder(); description.append(SOURCE_LIST_PATTERN.matcher(nub.getDescription()).replaceAll("")); description.append("\n\nThe following " + constituents.size() + " sources from the " + "<a href='http: "have been used to assemble the GBIF backbone:\n"); description.append("<ul>"); for (NubConstituent nc : constituents) { description.append("<li>" + nc.title+ " - " + nc.count+ " names</li>"); } description.append("</ul>"); nub.setDescription(description.toString()); try { StringWriter writer = new StringWriter(); EMLWriter.write(nub, writer); writer.close(); InputStream stream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes(Charsets.UTF_8)); datasetService.insertMetadata(Constants.NUB_DATASET_KEY, stream); } catch (RuntimeException | IOException e) { LOG.error("Failed to update backbone dataset metadata", e); } Set<UUID> constituentKeys = Sets.newHashSet(metrics.getCountByConstituent().keySet()); LOG.info("Updating backbone source network with {} constituents", constituentKeys.size()); for (Dataset d : Iterables.networkDatasets(Constants.NUB_NETWORK_KEY, null, networkService)) { if (!constituentKeys.remove(d.getKey())) { LOG.debug("Remove backbone source network constituent {} {}", d.getKey(), d.getTitle()); networkService.removeConstituent(Constants.NUB_NETWORK_KEY, d.getKey()); } } for (UUID datasetKey : constituentKeys) { LOG.debug("Add new backbone source network constituent {}", datasetKey); networkService.addConstituent(Constants.NUB_NETWORK_KEY, datasetKey); } return nub; } BackboneDatasetUpdater(DatasetService datasetService, OrganizationService organizationService, NetworkService networkService); Dataset updateBackboneDataset(DatasetMetrics metrics); }
BackboneDatasetUpdater { public Dataset updateBackboneDataset(DatasetMetrics metrics) { LOG.info("Updating backbone dataset metadata"); Dataset nub = datasetService.get(Constants.NUB_DATASET_KEY); nub.setPubDate(metrics.getCreated()); List<TaxonomicCoverage> taxa = Lists.<TaxonomicCoverage>newArrayList(); for (Kingdom k : Kingdom.values()) { new TaxonomicCoverage(k.scientificName(), null, new InterpretedEnum<String, Rank>("Kingdom", Rank.KINGDOM)); } nub.setTaxonomicCoverages(Lists.newArrayList(new TaxonomicCoverages("All life", taxa))); nub.setRights("CC0 1.0"); int plaziCounts = 0; List<NubConstituent> constituents = Lists.newArrayList(); for (Map.Entry<UUID, Integer> src : metrics.getCountByConstituent().entrySet()) { Dataset d = datasetService.get(src.getKey()); if (d.getPublishingOrganizationKey().equals(Constants.PLAZI_ORG_KEY)) { plaziCounts += src.getValue(); } else { constituents.add(new NubConstituent(src.getKey(), d.getTitle(), src.getValue())); } } if (plaziCounts > 0) { Organization plazi = organizationService.get(Constants.PLAZI_ORG_KEY); constituents.add(new NubConstituent(Constants.PLAZI_ORG_KEY, plazi.getTitle(), plaziCounts)); } Collections.sort(constituents); StringBuilder description = new StringBuilder(); description.append(SOURCE_LIST_PATTERN.matcher(nub.getDescription()).replaceAll("")); description.append("\n\nThe following " + constituents.size() + " sources from the " + "<a href='http: "have been used to assemble the GBIF backbone:\n"); description.append("<ul>"); for (NubConstituent nc : constituents) { description.append("<li>" + nc.title+ " - " + nc.count+ " names</li>"); } description.append("</ul>"); nub.setDescription(description.toString()); try { StringWriter writer = new StringWriter(); EMLWriter.write(nub, writer); writer.close(); InputStream stream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes(Charsets.UTF_8)); datasetService.insertMetadata(Constants.NUB_DATASET_KEY, stream); } catch (RuntimeException | IOException e) { LOG.error("Failed to update backbone dataset metadata", e); } Set<UUID> constituentKeys = Sets.newHashSet(metrics.getCountByConstituent().keySet()); LOG.info("Updating backbone source network with {} constituents", constituentKeys.size()); for (Dataset d : Iterables.networkDatasets(Constants.NUB_NETWORK_KEY, null, networkService)) { if (!constituentKeys.remove(d.getKey())) { LOG.debug("Remove backbone source network constituent {} {}", d.getKey(), d.getTitle()); networkService.removeConstituent(Constants.NUB_NETWORK_KEY, d.getKey()); } } for (UUID datasetKey : constituentKeys) { LOG.debug("Add new backbone source network constituent {}", datasetKey); networkService.addConstituent(Constants.NUB_NETWORK_KEY, datasetKey); } return nub; } BackboneDatasetUpdater(DatasetService datasetService, OrganizationService organizationService, NetworkService networkService); Dataset updateBackboneDataset(DatasetMetrics metrics);  }