Skip to content

Commit

Permalink
Fix for reading resource.xml files generated in an older IPT.
Browse files Browse the repository at this point in the history
XStream since 1.4.9 requires this fix.
  • Loading branch information
MattBlissett committed Sep 7, 2020
1 parent 5a3e137 commit 44dfd15
Show file tree
Hide file tree
Showing 12 changed files with 835 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.gbif.doi.service.DoiException;
import org.gbif.doi.service.DoiExistsException;
import org.gbif.doi.service.InvalidMetadataException;
import org.gbif.dwc.terms.DcTerm;
import org.gbif.dwc.terms.DwcTerm;
import org.gbif.dwc.terms.GbifTerm;
import org.gbif.dwc.terms.IucnTerm;
import org.gbif.dwc.terms.Term;
import org.gbif.dwc.terms.TermFactory;
import org.gbif.dwca.io.Archive;
Expand Down Expand Up @@ -679,10 +676,6 @@ private void defineXstreamMapping(UserEmailConverter userConverter, Organisation
xstream.registerConverter(passwordConverter);

xstream.addDefaultImplementation(ExtensionProperty.class, Term.class);
xstream.addDefaultImplementation(DwcTerm.class, Term.class);
xstream.addDefaultImplementation(DcTerm.class, Term.class);
xstream.addDefaultImplementation(GbifTerm.class, Term.class);
xstream.addDefaultImplementation(IucnTerm.class, Term.class);
xstream.registerConverter(orgConverter);
xstream.registerConverter(jdbcInfoConverter);
}
Expand Down Expand Up @@ -1121,7 +1114,7 @@ private Resource loadFromDir(File resourceDir, @Nullable User creator, ActionLog

LOG.debug("Read resource configuration for " + shortname);
return resource;
} catch (FileNotFoundException e) {
} catch (Exception e) {
LOG.error("Cannot read resource configuration for " + shortname, e);
throw new InvalidConfigException(TYPE.RESOURCE_CONFIG,
"Cannot read resource configuration for " + shortname + ": " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,18 @@ public ResourceManagerImpl getResourceManagerImpl() throws IOException, SAXExcep
InputStream eventCoreIs = ResourceManagerImplTest.class.getResourceAsStream("/extensions/dwc_event_2015-04-24.xml");
Extension eventCore = extensionFactory.build(eventCoreIs);

// construct simple images extension
InputStream simpleImageIs = ResourceManagerImplTest.class.getResourceAsStream("/extensions/simple_image.xml");
Extension simpleImage = extensionFactory.build(simpleImageIs);

ExtensionManager extensionManager = mock(ExtensionManager.class);

// mock ExtensionManager returning different Extensions
when(extensionManager.get("http://rs.tdwg.org/dwc/terms/Occurrence")).thenReturn(occurrenceCore);
when(extensionManager.get("http://rs.tdwg.org/dwc/terms/Event")).thenReturn(eventCore);
when(extensionManager.get("http://rs.tdwg.org/dwc/xsd/simpledarwincore/SimpleDarwinRecord"))
.thenReturn(occurrenceCore);
when(extensionManager.get("http://rs.gbif.org/terms/1.0/Image")).thenReturn(simpleImage);

ExtensionRowTypeConverter extensionRowTypeConverter = new ExtensionRowTypeConverter(extensionManager);
ConceptTermConverter conceptTermConverter = new ConceptTermConverter(extensionRowTypeConverter);
Expand Down Expand Up @@ -490,6 +495,93 @@ public void testCreateFromSingleGzipFile()
assertTrue(res.getEml().getDescription().isEmpty());
}

/**
* test resource (with extension) creation from zipped resource folder.
*/
@Test
public void testCreateWithExtensionFromZippedFile()
throws AlreadyExistingException, ImportException, SAXException, ParserConfigurationException, IOException,
InvalidFilenameException {
// retrieve sample zipped resource folder
File resourceXML = FileUtils.getClasspathFile("resources/amphibians/resource.xml");
// mock finding resource.xml file
when(mockedDataDir.resourceFile(anyString(), anyString())).thenReturn(resourceXML);

// retrieve sample zipped resource folder
File emlXML = FileUtils.getClasspathFile("resources/amphibians/eml.xml");
// mock finding eml.xml file
when(mockedDataDir.resourceEmlFile(anyString(), any(BigDecimal.class))).thenReturn(emlXML);

// create instance of manager
ResourceManager resourceManager = getResourceManagerImpl();

// retrieve sample zipped resource folder
File zippedResourceFolder = FileUtils.getClasspathFile("resources/amphibians.zip");

// create a new resource.
resourceManager.create("amphibians", null, zippedResourceFolder, creator, baseAction);

// test if new resource was added to the resources list.
assertEquals(1, resourceManager.list().size());

// get added resource.
Resource res = resourceManager.get("amphibians");

// test if resource was added correctly.
assertEquals("amphibians", res.getShortname());
assertEquals(creator, res.getCreator());
assertEquals(creator, res.getModifier());

// test if resource.xml was created.
assertTrue(mockedDataDir.resourceFile("amphibians", ResourceManagerImpl.PERSISTENCE_FILE).exists());

// properties that get preserved
// there are 2 source files
assertEquals(2, res.getSources().size());
assertEquals("danbifdb", res.getSources().get(0).getName());
assertEquals(65, res.getSource("danbifdb").getColumns());

// there is 1 mapping
assertEquals(2, res.getMappings().size());
assertEquals("danbifdb", res.getMappings().get(0).getSource().getName());
assertEquals(Constants.DWC_ROWTYPE_OCCURRENCE, res.getMappings().get(0).getExtension().getRowType());
assertEquals("http://rs.gbif.org/terms/1.0/Image", res.getMappings().get(1).getExtension().getRowType());

// properties that get reset
assertEquals(Constants.INITIAL_RESOURCE_VERSION, res.getEmlVersion());
// the resource shouldn't be registered
assertFalse(res.isRegistered());
// the resource shouldn't have any managers
assertEquals(0, res.getManagers().size());
// the resource shouldn't have a last published date
assertNull(res.getLastPublished());
// the resource shouldn't be registered (no org, no key)
assertNull(res.getKey());
assertNull(res.getOrganisation());
// the status should be private
assertEquals(PublicationStatus.PRIVATE, res.getStatus());
// the resource should have a created date
assertNotNull(res.getCreated());
// the record count is 0
assertEquals(0, res.getRecordsPublished());
// the DOI was reset
assertNull(res.getDoi());
assertEquals(IdentifierStatus.UNRESERVED, res.getIdentifierStatus());
assertNull(res.getDoiOrganisationKey());
// the change summary was reset
assertNull(res.getChangeSummary());
// the VersionHistory was cleared
assertEquals(0, res.getVersionHistory().size());
// the auto-publication was reset
assertEquals(PublicationMode.AUTO_PUBLISH_OFF, res.getPublicationMode());
assertNull(res.getUpdateFrequency());
assertNull(res.getNextPublished());
// the other last modified dates were also reset
assertNull(res.getMetadataModified());
assertNull(res.getMappingsModified());
assertNull(res.getSourcesModified());
}

/**
* test resource creation from zipped file, but resource.xml references non-existent extension.
*/
Expand Down
31 changes: 31 additions & 0 deletions src/test/resources/extensions/simple_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/style/human.xsl"?>
<extension xmlns="http://rs.gbif.org/extension/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dc="http://purl.org/dc/terms/"
xsi:schemaLocation="http://rs.gbif.org/extension/ http://rs.gbif.org/schema/extension.xsd"
dc:title="Simple Images (deprecated)" name="Image"
namespace="http://rs.gbif.org/terms/1.0" rowType="http://rs.gbif.org/terms/1.0/Image"
dc:issued="2015-02-13"
dc:subject="dwc:Taxon dwc:Occurrence"
dc:relation="http://rs.gbif.org/extension/gbif/1.0/images.xml"
dc:description="This extension has been DEPRECATED! Please use the newer Multimedia extension instead: http://rs.gbif.org/extension/gbif/1.0/multimedia.xml">

<property name="identifier" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/identifier" dc:description='The public URL that identifies and locates the image file directly, not a html page.' examples='http://farm6.static.flickr.com/5127/5242866958_98afd8cbce_o.jpg' type="uri" required="true"/>
<property name='references' namespace='http://purl.org/dc/terms/' qualName='http://purl.org/dc/terms/references' dc:relation='http://rs.tdwg.org/dwc/terms/index.htm#dcterms:references' dc:description='A html webpage that shows the image or its metadata. This link should be used for html based image viewers like FSI and should be used as a source link wherever the image is shown.' examples='http://www.flickr.com/photos/victorsaavedramartinez/1866107071/' type="uri" required='false'/>
<property name="title" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/title" dc:description='The image title' examples='Andorinha-do-rio (Tachycineta albiventer)' />
<property name="description" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/description" dc:description='A longer description for this image' examples='Female Tachycineta albiventer photographed in the Amazon, Brazil, in November 2010.' />
<property name='spatial' namespace='http://purl.org/dc/terms/' qualName='http://purl.org/dc/terms/spatial' dc:relation='' dc:description='The locality this picture was taken at' examples='Görlitzer Park, Berlin' required='false'/>
<property name='latitude' namespace='http://www.w3.org/2003/01/geo/wgs84_pos#' qualName='http://www.w3.org/2003/01/geo/wgs84_pos#latitude' type='decimal' dc:relation='http://www.w3.org/2003/01/geo/wgs84_pos#' dc:description='The WGS84 latitude in decimal degrees of the location the image was taken. A decimal number ranging from -90 through 90. Decimal fractions of a degree should be expressed to the precision available. Latitudes north of the equator MAY be specified by a plus sign (+), or by the absence of a minus sign (-). Latitudes south of the Equator MUST be designated by a minus sign (-) preceding the digits designating degrees.' examples='52.496451' required='false'/>
<property name='longitude' namespace='http://www.w3.org/2003/01/geo/wgs84_pos#' qualName='http://www.w3.org/2003/01/geo/wgs84_pos#longitude' type='decimal' dc:relation='http://www.w3.org/2003/01/geo/wgs84_pos#' dc:description='The WGS84 longitude in decimal degrees of the location the image was taken. A decimal number ranging from -180 through 180. Decimal fractions of a degree should be expressed to the precision available. Longitudes east of the prime meridian shall be specified by a plus sign (+), or by the absence of a minus sign (-). Longitudes west of the prime meridian MUST be designated by a minus sign (-) preceding the digits designating degrees.' examples='13.437732' required='false'/>
<property name="format" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/format" dc:description='The format the image is exposed in' examples='jpeg' />
<property name="created" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/created" dc:description='The date and time this image was taken' examples='2010-09-29' type="date"/>
<property name="creator" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/creator" dc:description='The person that took the image' examples='David Remsen' />
<property name="contributor" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/contributor" dc:description='Any contributor in addition to the creator that helped in taking the image' examples='David Beckham' />
<property name="publisher" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/publisher" dc:description='An entity responsible for making the image available.' examples='Encyclopedia of Life' />
<property name='audience' namespace='http://purl.org/dc/terms/' qualName='http://purl.org/dc/terms/audience' dc:relation='' dc:description='A class or description for whom the image is intended or useful' examples='"experts", "general public", "children"' required='false'/>
<property name="license" namespace="http://purl.org/dc/terms/" qualName="http://purl.org/dc/terms/license" dc:description='License for this image. Can be text or a url like creative commons uses' examples='http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en' />
<property name='rightsHolder' namespace='http://purl.org/dc/terms/' qualName='http://purl.org/dc/terms/rightsHolder' dc:relation='' dc:description='A person or organization owning or managing rights over the image.' examples='' required='false'/>
<property name='datasetID' namespace='http://rs.tdwg.org/dwc/terms/' qualName='http://rs.tdwg.org/dwc/terms/datasetID' dc:relation='http://rs.tdwg.org/dwc/terms/index.htm#datasetID' dc:description='An identifier for a subset of data.' examples='' required='false'/>

</extension>
Binary file added src/test/resources/resources/amphibians.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\froman\fcharset0 Times Bold;}{\f2\froman\fcharset0 Arial;}{\f3\froman\fcharset0 Times;}{\f4\froman\fcharset0 Times Roman;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red255\green0\blue0;\red0\green0\blue255;}{\stylesheet {\style\s0 \ql\fi0\li0\ri0\f2\fs24\cf0 Normal;}{\style\s3 \ql\fi0\li0\ri0\f2\fs26\b\cf0 heading 3;}{\style\s2 \ql\fi0\li0\ri0\f2\fs28\b\i\cf0 heading 2;}{\style\s1 \ql\fi0\li0\ri0\f2\fs32\b\cf0 heading 1;}}{\*\listtable}{\*\listoverridetable}{\*\generator iText 2.1.7 by 1T3XT}{\info{\author Mihail-Constantin Carausu}{\creationdate \yr2012\mo02\dy06\hr08\min45\sec13}{\title Amphibians and Reptiles collection at the Natural History Museum of Denmark (SNM)}{\keywords }}\paperw11907\paperh16840\margl1440\margr1440\margt1440\margb1440\pgwsxn11907\pghsxn16840\marglsxn1440\margrsxn1440\margtsxn1440\margbsxn1440\pard\plain\s0\qc\fi0\li0\ri0\plain\f3\fs28\b\cf0 Amphibians and Reptiles collection at the Natural History Museum of Denmark (SNM)\b0\par\f0 \par \pard\plain\s0\qc\fi0\li0\ri0\sl320\plain\f3\fs24\cf0 Mogens \f3\fs24\cf0 Andersen\f3\fs24\cf0\super 1\nosupersub\par\f0 \par \pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\cf0 1 \f3\fs24\cf0 SNM, \f3\fs24\cf0 Universitetsparken 15, \f3\fs24\cf0 2100, \f3\fs24\cf0 Copenhagen OE\f3\fs24\cf0 , Denmark\par\f0 \par \pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\b\cf0 Corresponding author(s): \b0\f3\fs24\cf0 Mogens \f3\fs24\cf0 Andersen\f3\fs24\cf0 (mandersen@snm.ku.dk)\f3\fs24\cf0 \par \par\pard\plain\s0\fi0\li0\ri0\sl320\plain\f3\fs24\cf0 Received \f3\fs24\cf2 \{date\}\f3\fs24\cf0 ; Revised \f3\fs24\cf2 \{date\}\f3\fs24\cf0 ; Accepted \f3\fs24\cf2 \{date\}\f3\fs24\cf0 ; Published \f3\fs24\cf2 \{date\}\f3\fs24\cf0 \par \par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\b\cf0 Citation: \b0\f3\fs24\cf2 Combination of authors, year of data paper publication (in parenthesis), Title, Journal Name, Volume, Issue number (in paranthesis), and doi of the data paper.\f3\fs24\cf2 \par \par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\b\cf0 Abstract\b0\f3\fs24\cf0 \par \f3\fs24\cf0 \par \f3\fs24\cf0 The Danish reptiles and amphibians are well represented in the collections, and not least thanks to a single collector (R. Skovgaard), the Museum has representative collections from the rest of Europe as well. The Museum possesses fine exotic collections from the earlier colonies of Denmark, e.g., from the earlier Danish West Indies. This material was treated by Reinhardt & L\u252?tken (1862). From the earlier settlements on the Coast of Guinea, the Museum possesses a small, but very fine collection of snakes, many of which formed the basis for the description of new species (Reinhardt, 1843), among others the spitting cobra, Naja nigricollis. Reinhardt\u180?s paper has been translated in English (Rasmussen & Hughes, 1997). Reinhardt increased the collections personally by undertaking three collecting trips to Brazil. The material was later treated by Reinhardt & L\u252?tken (1861). Most of the very-representative collections of reptiles and amphibians can be traced back to a single expedition or a single person. Thus, the Noona Dan Expedition (1961-1962) brought home a fine collection of terrestrial amphibians and reptiles from the Philippines and Melanesia and marine sea snakes from the Pacific. Since 1985, Arne Redsted Rasmussen has personally more than doubled the number of sea snakes in the collections. The Museum has fine collections of anuran amphibians, most of which have been collected by Arne Schi\u248?tz in connection with his studies on tree frogs from West Africa (1967). Later Arne Schi\u248?tz extended his studies (1985) to include the East African tree frogs as well. Since 1970, the Museum, including the staff at the herpetological section, has made extensive collection tours to East Africa. In consequence, the section has abundant collections (especially snakes) from this area. In May 2005 the then curator of herpetology, Jens B. Rasmussen passed away after a short period of illness. Jens Rasmussen was curator of herpetology at the museum since 1977. His research area focused on phylogeny and biogeography of African snakes and through his work Jens became one of the leading specialists in this field. During his last years Jens worked with a comprehensive revision of the material kept in major collections, with the aim of producing a speciation atlas for African snakes. The work will be published posthumously. For more information, please contact Professor, Dr. scient., Jon Fjeldsaa or assistant curator Mogens Andersen.\f3\fs24\cf0 \par \par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\cf0 \par \par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\b\cf0 Datasets\b0\f3\fs24\cf0 \par \f3\fs24\cf0 \par \f3\fs24\b\cf0 Dataset description\b0\f3\fs24\cf0 \par \f3\fs24\b\cf0 Object name: \b0\f3\fs24\cf0 Darwin Core Archive Amphibians and Reptiles collection at the Natural History Museum of Denmark (SNM)\f3\fs24\cf0 \par \f3\fs24\b\cf0 Character encoding: \b0\f3\fs24\cf0 UTF-8\f3\fs24\cf0 \par \f3\fs24\b\cf0 Format name: \b0\f3\fs24\cf0 Darwin Core Archive format\f3\fs24\cf0 \par \f3\fs24\b\cf0 Format version: \b0\f3\fs24\cf0 1.0\f3\fs24\cf0 \par \f3\fs24\b\cf0 Distribution: \b0\f0{\field{\*\fldinst HYPERLINK http://192.38.112.86:8080/ipt/archive.do?r=amphibians_and_reptiles_snm}{\fldrslt \pard\plain\f3\fs24\ul\cf3 http://192.38.112.86:8080/ipt/archive.do?r=amphibians_and_reptiles_snm\ul0 }}\f3\fs24\cf0 \par \f3\fs24\b\cf0 Publication date of data: \b0\f3\fs24\cf0 0007-08-05\f3\fs24\cf0 \par \f3\fs24\b\cf0 Language: \b0\f3\fs24\cf0 English\f3\fs24\cf0 \par \f3\fs24\b\cf0 Licenses of use: \b0\f3\fs24\cf0 Zoological Museum - Natural History Museum of Denmark This work is licensed under a Creative Commons Attribution-Noncommercial License (http://creativecommons.org/licenses/by-nc/3.0/).\f3\fs24\cf0 \par \par\pard\plain\s0\qj\fi0\li0\ri0\sl320\plain\f3\fs24\b\cf0 Metadata language: \b0\f3\fs24\cf0 English\f3\fs24\cf0 \par \f3\fs24\b\cf0 Date of metadata creation: \b0\f3\fs24\cf0 2012-02-06\f3\fs24\cf0 \par \f3\fs24\b\cf0 Hierarchy level: \b0\f3\fs24\cf0 Dataset\f3\fs24\cf0 \par \par}
Loading

0 comments on commit 44dfd15

Please sign in to comment.