@Test public void testGetAssociatedMultiMediaUris() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); List<ServiceAccessPoint> serviceAccessPoints = null; int listSize = 0; CrsSpecimenTransformer crsSpecimenTransformer = new CrsSpecimenTransformer(etlStatistics); CrsExtractor extractor = new CrsExtractor(specimenFile, etlStatistics); for (XMLRecordInfo extracted : extractor) { CommonReflectionUtil.setField(AbstractTransformer.class, crsSpecimenTransformer, "objectID", "RMNH.ART.354"); CommonReflectionUtil.setField(AbstractTransformer.class, crsSpecimenTransformer, "input", extracted); Object returned = CommonReflectionUtil.callMethod(null, null, crsSpecimenTransformer, "getAssociatedMultiMediaUris"); serviceAccessPoints = (List<ServiceAccessPoint>) returned; listSize = serviceAccessPoints.size(); } URI expectedUri = URI.create("https: assertEquals( "01", 2, listSize); assertTrue("02", serviceAccessPoints.get(0).getAccessUri().equals(expectedUri)); expectedUri = URI.create("https: assertEquals("03", serviceAccessPoints.get(1).getAccessUri(), expectedUri); }
private List<ServiceAccessPoint> getAssociatedMultiMediaUris() { Element record = input.getRecord(); List<Element> fileUriElems = DOMUtil.getDescendants(record, "abcd:fileuri"); if (fileUriElems == null) { if (logger.isDebugEnabled()) { debug("Missing or empty element <abcd:fileuri>"); } return null; } List<Element> multimediaPublic = DOMUtil.getDescendants(record, "abcd:MultiMediaPublic"); if (multimediaPublic == null || multimediaPublic.size() == 0) { return null; } List<ServiceAccessPoint> serviceAccessPoints = new ArrayList<>(fileUriElems.size()); int n = 0; for (Element e : fileUriElems) { if (multimediaPublic.get(n++).getTextContent().trim().equals("0")) { continue; } String uriStr = e.getTextContent().trim(); if (uriStr == null || uriStr.length() == 0) continue; if (uriStr.startsWith(MEDIALIB_HTTP_URL) && !uriStr.startsWith(MEDIALIB_HTTPS_URL)) { uriStr = uriStr.replace(MEDIALIB_HTTP_URL, MEDIALIB_HTTPS_URL); } try { @SuppressWarnings("unused") URI uri = new URI(uriStr); } catch (URISyntaxException exc) { stats.objectsRejected++; if (!suppressErrors) { logger.error("Invalid image URL for object {}. URI has been skipped: {}", objectID, uriStr); } continue; } String medialibId = uriStr.substring(MEDIALIB_URL_START.length()); int x = medialibId.indexOf('/'); if (x != -1) { medialibId = medialibId.substring(0, x); } String mimeType = mimetypeCache.getMimeType(medialibId); if (mimeType != null) { serviceAccessPoints.add(new ServiceAccessPoint(uriStr, mimeType, DEFAULT_IMAGE_QUALITY)); } else if (uriStr.length() > 0 && mimeType == null) { logger.error("Multimedia URI from object {} has no mime type! URI has been skipped: {}", objectID, uriStr); } } return (serviceAccessPoints.size() == 0) ? null : serviceAccessPoints; }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<ServiceAccessPoint> getAssociatedMultiMediaUris() { Element record = input.getRecord(); List<Element> fileUriElems = DOMUtil.getDescendants(record, "abcd:fileuri"); if (fileUriElems == null) { if (logger.isDebugEnabled()) { debug("Missing or empty element <abcd:fileuri>"); } return null; } List<Element> multimediaPublic = DOMUtil.getDescendants(record, "abcd:MultiMediaPublic"); if (multimediaPublic == null || multimediaPublic.size() == 0) { return null; } List<ServiceAccessPoint> serviceAccessPoints = new ArrayList<>(fileUriElems.size()); int n = 0; for (Element e : fileUriElems) { if (multimediaPublic.get(n++).getTextContent().trim().equals("0")) { continue; } String uriStr = e.getTextContent().trim(); if (uriStr == null || uriStr.length() == 0) continue; if (uriStr.startsWith(MEDIALIB_HTTP_URL) && !uriStr.startsWith(MEDIALIB_HTTPS_URL)) { uriStr = uriStr.replace(MEDIALIB_HTTP_URL, MEDIALIB_HTTPS_URL); } try { @SuppressWarnings("unused") URI uri = new URI(uriStr); } catch (URISyntaxException exc) { stats.objectsRejected++; if (!suppressErrors) { logger.error("Invalid image URL for object {}. URI has been skipped: {}", objectID, uriStr); } continue; } String medialibId = uriStr.substring(MEDIALIB_URL_START.length()); int x = medialibId.indexOf('/'); if (x != -1) { medialibId = medialibId.substring(0, x); } String mimeType = mimetypeCache.getMimeType(medialibId); if (mimeType != null) { serviceAccessPoints.add(new ServiceAccessPoint(uriStr, mimeType, DEFAULT_IMAGE_QUALITY)); } else if (uriStr.length() > 0 && mimeType == null) { logger.error("Multimedia URI from object {} has no mime type! URI has been skipped: {}", objectID, uriStr); } } return (serviceAccessPoints.size() == 0) ? null : serviceAccessPoints; } }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<ServiceAccessPoint> getAssociatedMultiMediaUris() { Element record = input.getRecord(); List<Element> fileUriElems = DOMUtil.getDescendants(record, "abcd:fileuri"); if (fileUriElems == null) { if (logger.isDebugEnabled()) { debug("Missing or empty element <abcd:fileuri>"); } return null; } List<Element> multimediaPublic = DOMUtil.getDescendants(record, "abcd:MultiMediaPublic"); if (multimediaPublic == null || multimediaPublic.size() == 0) { return null; } List<ServiceAccessPoint> serviceAccessPoints = new ArrayList<>(fileUriElems.size()); int n = 0; for (Element e : fileUriElems) { if (multimediaPublic.get(n++).getTextContent().trim().equals("0")) { continue; } String uriStr = e.getTextContent().trim(); if (uriStr == null || uriStr.length() == 0) continue; if (uriStr.startsWith(MEDIALIB_HTTP_URL) && !uriStr.startsWith(MEDIALIB_HTTPS_URL)) { uriStr = uriStr.replace(MEDIALIB_HTTP_URL, MEDIALIB_HTTPS_URL); } try { @SuppressWarnings("unused") URI uri = new URI(uriStr); } catch (URISyntaxException exc) { stats.objectsRejected++; if (!suppressErrors) { logger.error("Invalid image URL for object {}. URI has been skipped: {}", objectID, uriStr); } continue; } String medialibId = uriStr.substring(MEDIALIB_URL_START.length()); int x = medialibId.indexOf('/'); if (x != -1) { medialibId = medialibId.substring(0, x); } String mimeType = mimetypeCache.getMimeType(medialibId); if (mimeType != null) { serviceAccessPoints.add(new ServiceAccessPoint(uriStr, mimeType, DEFAULT_IMAGE_QUALITY)); } else if (uriStr.length() > 0 && mimeType == null) { logger.error("Multimedia URI from object {} has no mime type! URI has been skipped: {}", objectID, uriStr); } } return (serviceAccessPoints.size() == 0) ? null : serviceAccessPoints; } CrsSpecimenTransformer(ETLStatistics stats); }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<ServiceAccessPoint> getAssociatedMultiMediaUris() { Element record = input.getRecord(); List<Element> fileUriElems = DOMUtil.getDescendants(record, "abcd:fileuri"); if (fileUriElems == null) { if (logger.isDebugEnabled()) { debug("Missing or empty element <abcd:fileuri>"); } return null; } List<Element> multimediaPublic = DOMUtil.getDescendants(record, "abcd:MultiMediaPublic"); if (multimediaPublic == null || multimediaPublic.size() == 0) { return null; } List<ServiceAccessPoint> serviceAccessPoints = new ArrayList<>(fileUriElems.size()); int n = 0; for (Element e : fileUriElems) { if (multimediaPublic.get(n++).getTextContent().trim().equals("0")) { continue; } String uriStr = e.getTextContent().trim(); if (uriStr == null || uriStr.length() == 0) continue; if (uriStr.startsWith(MEDIALIB_HTTP_URL) && !uriStr.startsWith(MEDIALIB_HTTPS_URL)) { uriStr = uriStr.replace(MEDIALIB_HTTP_URL, MEDIALIB_HTTPS_URL); } try { @SuppressWarnings("unused") URI uri = new URI(uriStr); } catch (URISyntaxException exc) { stats.objectsRejected++; if (!suppressErrors) { logger.error("Invalid image URL for object {}. URI has been skipped: {}", objectID, uriStr); } continue; } String medialibId = uriStr.substring(MEDIALIB_URL_START.length()); int x = medialibId.indexOf('/'); if (x != -1) { medialibId = medialibId.substring(0, x); } String mimeType = mimetypeCache.getMimeType(medialibId); if (mimeType != null) { serviceAccessPoints.add(new ServiceAccessPoint(uriStr, mimeType, DEFAULT_IMAGE_QUALITY)); } else if (uriStr.length() > 0 && mimeType == null) { logger.error("Multimedia URI from object {} has no mime type! URI has been skipped: {}", objectID, uriStr); } } return (serviceAccessPoints.size() == 0) ? null : serviceAccessPoints; } CrsSpecimenTransformer(ETLStatistics stats);  }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<ServiceAccessPoint> getAssociatedMultiMediaUris() { Element record = input.getRecord(); List<Element> fileUriElems = DOMUtil.getDescendants(record, "abcd:fileuri"); if (fileUriElems == null) { if (logger.isDebugEnabled()) { debug("Missing or empty element <abcd:fileuri>"); } return null; } List<Element> multimediaPublic = DOMUtil.getDescendants(record, "abcd:MultiMediaPublic"); if (multimediaPublic == null || multimediaPublic.size() == 0) { return null; } List<ServiceAccessPoint> serviceAccessPoints = new ArrayList<>(fileUriElems.size()); int n = 0; for (Element e : fileUriElems) { if (multimediaPublic.get(n++).getTextContent().trim().equals("0")) { continue; } String uriStr = e.getTextContent().trim(); if (uriStr == null || uriStr.length() == 0) continue; if (uriStr.startsWith(MEDIALIB_HTTP_URL) && !uriStr.startsWith(MEDIALIB_HTTPS_URL)) { uriStr = uriStr.replace(MEDIALIB_HTTP_URL, MEDIALIB_HTTPS_URL); } try { @SuppressWarnings("unused") URI uri = new URI(uriStr); } catch (URISyntaxException exc) { stats.objectsRejected++; if (!suppressErrors) { logger.error("Invalid image URL for object {}. URI has been skipped: {}", objectID, uriStr); } continue; } String medialibId = uriStr.substring(MEDIALIB_URL_START.length()); int x = medialibId.indexOf('/'); if (x != -1) { medialibId = medialibId.substring(0, x); } String mimeType = mimetypeCache.getMimeType(medialibId); if (mimeType != null) { serviceAccessPoints.add(new ServiceAccessPoint(uriStr, mimeType, DEFAULT_IMAGE_QUALITY)); } else if (uriStr.length() > 0 && mimeType == null) { logger.error("Multimedia URI from object {} has no mime type! URI has been skipped: {}", objectID, uriStr); } } return (serviceAccessPoints.size() == 0) ? null : serviceAccessPoints; } CrsSpecimenTransformer(ETLStatistics stats);   }