@Before public void setup() { // set small list of source column names representing a source file to be mapped columns = new ArrayList<String>(); columns.add("identificationID"); columns.add("identificationQualifier"); columns.add("unknown"); columns.add("occurrenceID"); // create a new Extension, that represents the Darwin Core Occurrence Core Extension extension = new Extension(); extension.setRowType(Constants.DWC_ROWTYPE_OCCURRENCE); List<ExtensionProperty> extensionProperties = new ArrayList<ExtensionProperty>(); ExtensionProperty extensionProperty = new ExtensionProperty(); extensionProperty.setQualname(DwcTerm.occurrenceID.qualifiedName()); extensionProperties.add(extensionProperty); extension.setProperties(extensionProperties); // an ExtensionMapping to Extension Darwin Core Occurrence Core extensionMapping = new ExtensionMapping(); extensionMapping.setExtension(extension); // 2 translated fields pointing at same source column Set<PropertyMapping> fields = Sets.newHashSet(); PropertyMapping mappingCoreid = new PropertyMapping(); mappingCoreid.setTerm(DwcTerm.occurrenceID); mappingCoreid.setIndex(0); fields.add(mappingCoreid); extensionMapping.setFields(fields); // Resource resource = new Resource(); resource.setShortname("myResource"); resource.addMapping(extensionMapping); validator = new ExtensionMappingValidator(); }
/** * Reconstruct published version, using version's Eml file, version history, etc. * * @param version version to assign to reconstructed resource * @param shortname shortname to assign to reconstructed resource * @param doi DOI to assign to reconstructed resource * @param organisation organisation to assign to reconstructed resource * @param versionHistory VersionHistory corresponding to resource version being reconstructed * @param versionEmlFile eml file corresponding to version of resource being reconstructed * @param key GBIF UUID to assign to reconstructed resource * @return published version reconstructed */ public static Resource reconstructVersion( @NotNull BigDecimal version, @NotNull String shortname, @NotNull DOI doi, @Nullable Organisation organisation, @Nullable VersionHistory versionHistory, @Nullable File versionEmlFile, @Nullable UUID key) { Preconditions.checkNotNull(version); Preconditions.checkNotNull(shortname); Preconditions.checkNotNull(doi); if (organisation == null || versionHistory == null || versionEmlFile == null) { throw new IllegalArgumentException( "Failed to reconstruct resource version because not all of organisation, version history, or version eml file were provided"); } // initiate new version, and set properties Resource resource = new Resource(); resource.setShortname(shortname); resource.setEmlVersion(version); resource.setDoi(doi); resource.setOrganisation(organisation); resource.setKey(key); resource.setStatus(versionHistory.getPublicationStatus()); resource.setIdentifierStatus(versionHistory.getStatus()); resource.setRecordsPublished(versionHistory.getRecordsPublished()); resource.setLastPublished(versionHistory.getReleased()); if (versionEmlFile.exists()) { Eml eml = EmlUtils.loadWithLocale(versionEmlFile, Locale.US); resource.setEml(eml); } else { throw new IllegalArgumentException( "Failed to reconstruct resource: " + versionEmlFile.getAbsolutePath() + " not found!"); } return resource; }