@SuppressWarnings("unchecked") @Test public void testTransformOne() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); List<Taxon> list = null; MultiMediaObject actual = null; NsrExtractor extractor = new NsrExtractor(nsrFile, etlStatistics); NsrTaxonTransformer nsrTaxonTransformer = new NsrTaxonTransformer(etlStatistics); NsrMultiMediaTransformer mediaTransformer = new NsrMultiMediaTransformer(etlStatistics); for (XMLRecordInfo extracted : extractor) { CommonReflectionUtil.setField(AbstractTransformer.class, nsrTaxonTransformer, "objectID", "D3KF0JNQ0UA"); CommonReflectionUtil.setField(AbstractTransformer.class, nsrTaxonTransformer, "input", extracted); Object taxonObject = CommonReflectionUtil.callMethod(null, null, nsrTaxonTransformer, "doTransform"); CommonReflectionUtil.setField(AbstractTransformer.class, mediaTransformer, "objectID", "D3KF0JNQ0UA"); CommonReflectionUtil.setField(AbstractTransformer.class, mediaTransformer, "input", extracted); list = (List<Taxon>) taxonObject; mediaTransformer.setTaxon(list.get(0)); List<Element> imageElems = getDescendants(extracted.getRecord(), "image"); Object returned = ReflectionUtil.call(mediaTransformer, "transformOne", new Class[] {Element.class}, new Object[] {imageElems.get(0)}); actual = (MultiMediaObject) returned; } String expectedAssociatedTaxRef = "D3KF0JNQ0UA@NSR"; String expectedCreator = "Arnold Wijker"; String expectedCollectionType = null; String expectedCaption = "Adult winter"; String expectedDescription = "Adult winter"; String expectedId = "D3KF0JNQ0UA_1011552535@NSR"; String expectedLicenseType = "Copyright"; String expectedLicense = "CC BY-NC-ND"; String expectedOwner = "Naturalis Biodiversity Center"; String expectedSourceId = "LNG NSR"; String expectedSourceSystemId = "D3KF0JNQ0UA_1011552535"; String expectedUnitId = "D3KF0JNQ0UA_1011552535"; assertEquals("01",expectedAssociatedTaxRef, actual.getAssociatedTaxonReference()); assertEquals("01",expectedCreator, actual.getCreator()); assertEquals("02",expectedCollectionType, actual.getCollectionType()); assertEquals("03",expectedCaption, actual.getCaption()); assertEquals("04",expectedDescription, actual.getDescription()); assertEquals("05",expectedId, actual.getId()); assertEquals("06",expectedLicenseType, actual.getLicenseType().toString()); assertEquals("07",expectedLicense, actual.getLicense().toString()); assertEquals("08",expectedOwner, actual.getOwner()); assertEquals("09",expectedSourceId, actual.getSourceID()); assertEquals("10",expectedSourceSystemId, actual.getSourceSystemId()); assertEquals("11",expectedUnitId, actual.getUnitID()); }
private MultiMediaObject transformOne(Image image) { stats.objectsProcessed++; try { URI uri = getUri(image); if (uri == null) return null; MultiMediaObject mmo = newMediaObject(); String uriHash = String.valueOf(uri.hashCode()).replace('-', '0'); mmo.setSourceSystemId(objectID + '_' + uriHash); mmo.setUnitID(mmo.getSourceSystemId()); mmo.setId(getElasticsearchId(NSR, mmo.getUnitID())); String format = val(image.getMime_type()); if (format == null || format.length() == 0) { if (!suppressErrors) { String fmt = "Missing mime type for image \"%s\" (taxon \"%s\")."; warn(fmt, uri, taxon.getAcceptedName().getFullScientificName()); } format = guessMimeType(uri.toString()); } mmo.addServiceAccessPoint(new ServiceAccessPoint(uri, format, DEFAULT_IMAGE_QUALITY)); mmo.setCreator(val(image.getPhotographer_name())); mmo.setCopyrightText(val(image.getCopyright())); mmo.setLicenseType(LicenseType.parse(val(image.getLicence_type()))); mmo.setLicense(License.parse(val(image.getLicence()))); mmo.setDescription(val(image.getShort_description())); mmo.setCaption(mmo.getDescription()); String date = val(image.getDate_taken()); if (date != null && date.equalsIgnoreCase("in prep")) { date = null; if (logger.isDebugEnabled()) { logger.debug("Invalid date: \"{}\"", date); } } String locality = val(image.getGeography()); if (locality != null || date != null) { MultiMediaGatheringEvent ge = new MultiMediaGatheringEvent(); mmo.setGatheringEvents(Arrays.asList(ge)); if (locality != null) { ge.setLocalityText(locality); } if (date != null) { ge.setDateTimeBegin(parseDateTaken(date)); ge.setDateTimeEnd(ge.getDateTimeBegin()); } } stats.objectsAccepted++; return mmo; } catch (Throwable t) { handleError(t); return null; } }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private MultiMediaObject transformOne(Image image) { stats.objectsProcessed++; try { URI uri = getUri(image); if (uri == null) return null; MultiMediaObject mmo = newMediaObject(); String uriHash = String.valueOf(uri.hashCode()).replace('-', '0'); mmo.setSourceSystemId(objectID + '_' + uriHash); mmo.setUnitID(mmo.getSourceSystemId()); mmo.setId(getElasticsearchId(NSR, mmo.getUnitID())); String format = val(image.getMime_type()); if (format == null || format.length() == 0) { if (!suppressErrors) { String fmt = "Missing mime type for image \"%s\" (taxon \"%s\")."; warn(fmt, uri, taxon.getAcceptedName().getFullScientificName()); } format = guessMimeType(uri.toString()); } mmo.addServiceAccessPoint(new ServiceAccessPoint(uri, format, DEFAULT_IMAGE_QUALITY)); mmo.setCreator(val(image.getPhotographer_name())); mmo.setCopyrightText(val(image.getCopyright())); mmo.setLicenseType(LicenseType.parse(val(image.getLicence_type()))); mmo.setLicense(License.parse(val(image.getLicence()))); mmo.setDescription(val(image.getShort_description())); mmo.setCaption(mmo.getDescription()); String date = val(image.getDate_taken()); if (date != null && date.equalsIgnoreCase("in prep")) { date = null; if (logger.isDebugEnabled()) { logger.debug("Invalid date: \"{}\"", date); } } String locality = val(image.getGeography()); if (locality != null || date != null) { MultiMediaGatheringEvent ge = new MultiMediaGatheringEvent(); mmo.setGatheringEvents(Arrays.asList(ge)); if (locality != null) { ge.setLocalityText(locality); } if (date != null) { ge.setDateTimeBegin(parseDateTaken(date)); ge.setDateTimeEnd(ge.getDateTimeBegin()); } } stats.objectsAccepted++; return mmo; } catch (Throwable t) { handleError(t); return null; } } }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private MultiMediaObject transformOne(Image image) { stats.objectsProcessed++; try { URI uri = getUri(image); if (uri == null) return null; MultiMediaObject mmo = newMediaObject(); String uriHash = String.valueOf(uri.hashCode()).replace('-', '0'); mmo.setSourceSystemId(objectID + '_' + uriHash); mmo.setUnitID(mmo.getSourceSystemId()); mmo.setId(getElasticsearchId(NSR, mmo.getUnitID())); String format = val(image.getMime_type()); if (format == null || format.length() == 0) { if (!suppressErrors) { String fmt = "Missing mime type for image \"%s\" (taxon \"%s\")."; warn(fmt, uri, taxon.getAcceptedName().getFullScientificName()); } format = guessMimeType(uri.toString()); } mmo.addServiceAccessPoint(new ServiceAccessPoint(uri, format, DEFAULT_IMAGE_QUALITY)); mmo.setCreator(val(image.getPhotographer_name())); mmo.setCopyrightText(val(image.getCopyright())); mmo.setLicenseType(LicenseType.parse(val(image.getLicence_type()))); mmo.setLicense(License.parse(val(image.getLicence()))); mmo.setDescription(val(image.getShort_description())); mmo.setCaption(mmo.getDescription()); String date = val(image.getDate_taken()); if (date != null && date.equalsIgnoreCase("in prep")) { date = null; if (logger.isDebugEnabled()) { logger.debug("Invalid date: \"{}\"", date); } } String locality = val(image.getGeography()); if (locality != null || date != null) { MultiMediaGatheringEvent ge = new MultiMediaGatheringEvent(); mmo.setGatheringEvents(Arrays.asList(ge)); if (locality != null) { ge.setLocalityText(locality); } if (date != null) { ge.setDateTimeBegin(parseDateTaken(date)); ge.setDateTimeEnd(ge.getDateTimeBegin()); } } stats.objectsAccepted++; return mmo; } catch (Throwable t) { handleError(t); return null; } } NsrMultiMediaTransformer(ETLStatistics stats); }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private MultiMediaObject transformOne(Image image) { stats.objectsProcessed++; try { URI uri = getUri(image); if (uri == null) return null; MultiMediaObject mmo = newMediaObject(); String uriHash = String.valueOf(uri.hashCode()).replace('-', '0'); mmo.setSourceSystemId(objectID + '_' + uriHash); mmo.setUnitID(mmo.getSourceSystemId()); mmo.setId(getElasticsearchId(NSR, mmo.getUnitID())); String format = val(image.getMime_type()); if (format == null || format.length() == 0) { if (!suppressErrors) { String fmt = "Missing mime type for image \"%s\" (taxon \"%s\")."; warn(fmt, uri, taxon.getAcceptedName().getFullScientificName()); } format = guessMimeType(uri.toString()); } mmo.addServiceAccessPoint(new ServiceAccessPoint(uri, format, DEFAULT_IMAGE_QUALITY)); mmo.setCreator(val(image.getPhotographer_name())); mmo.setCopyrightText(val(image.getCopyright())); mmo.setLicenseType(LicenseType.parse(val(image.getLicence_type()))); mmo.setLicense(License.parse(val(image.getLicence()))); mmo.setDescription(val(image.getShort_description())); mmo.setCaption(mmo.getDescription()); String date = val(image.getDate_taken()); if (date != null && date.equalsIgnoreCase("in prep")) { date = null; if (logger.isDebugEnabled()) { logger.debug("Invalid date: \"{}\"", date); } } String locality = val(image.getGeography()); if (locality != null || date != null) { MultiMediaGatheringEvent ge = new MultiMediaGatheringEvent(); mmo.setGatheringEvents(Arrays.asList(ge)); if (locality != null) { ge.setLocalityText(locality); } if (date != null) { ge.setDateTimeBegin(parseDateTaken(date)); ge.setDateTimeEnd(ge.getDateTimeBegin()); } } stats.objectsAccepted++; return mmo; } catch (Throwable t) { handleError(t); return null; } } NsrMultiMediaTransformer(ETLStatistics stats); void setTaxon(Taxon taxon); }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private MultiMediaObject transformOne(Image image) { stats.objectsProcessed++; try { URI uri = getUri(image); if (uri == null) return null; MultiMediaObject mmo = newMediaObject(); String uriHash = String.valueOf(uri.hashCode()).replace('-', '0'); mmo.setSourceSystemId(objectID + '_' + uriHash); mmo.setUnitID(mmo.getSourceSystemId()); mmo.setId(getElasticsearchId(NSR, mmo.getUnitID())); String format = val(image.getMime_type()); if (format == null || format.length() == 0) { if (!suppressErrors) { String fmt = "Missing mime type for image \"%s\" (taxon \"%s\")."; warn(fmt, uri, taxon.getAcceptedName().getFullScientificName()); } format = guessMimeType(uri.toString()); } mmo.addServiceAccessPoint(new ServiceAccessPoint(uri, format, DEFAULT_IMAGE_QUALITY)); mmo.setCreator(val(image.getPhotographer_name())); mmo.setCopyrightText(val(image.getCopyright())); mmo.setLicenseType(LicenseType.parse(val(image.getLicence_type()))); mmo.setLicense(License.parse(val(image.getLicence()))); mmo.setDescription(val(image.getShort_description())); mmo.setCaption(mmo.getDescription()); String date = val(image.getDate_taken()); if (date != null && date.equalsIgnoreCase("in prep")) { date = null; if (logger.isDebugEnabled()) { logger.debug("Invalid date: \"{}\"", date); } } String locality = val(image.getGeography()); if (locality != null || date != null) { MultiMediaGatheringEvent ge = new MultiMediaGatheringEvent(); mmo.setGatheringEvents(Arrays.asList(ge)); if (locality != null) { ge.setLocalityText(locality); } if (date != null) { ge.setDateTimeBegin(parseDateTaken(date)); ge.setDateTimeEnd(ge.getDateTimeBegin()); } } stats.objectsAccepted++; return mmo; } catch (Throwable t) { handleError(t); return null; } } NsrMultiMediaTransformer(ETLStatistics stats); void setTaxon(Taxon taxon);  }