diff --git a/core/src/main/java/org/fao/geonet/util/XslUtil.java b/core/src/main/java/org/fao/geonet/util/XslUtil.java index c6e5ca26576..452ab855e75 100644 --- a/core/src/main/java/org/fao/geonet/util/XslUtil.java +++ b/core/src/main/java/org/fao/geonet/util/XslUtil.java @@ -1246,7 +1246,7 @@ public static String buildDataUrl(String url, Integer size) { Matcher m = Pattern.compile(settingManager.getNodeURL() + "api/records/(.*)/attachments/(.*)$").matcher(url); BufferedImage image; if (m.find()) { - Store store = ApplicationContextHolder.get().getBean(FilesystemStore.class); + Store store = ApplicationContextHolder.get().getBean("filesystemStore", Store.class); try (Store.ResourceHolder file = store.getResourceInternal( m.group(1), MetadataResourceVisibility.PUBLIC, diff --git a/datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java b/datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java index a158ae9a319..989dc719fc4 100644 --- a/datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java +++ b/datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java @@ -190,7 +190,20 @@ public ResourceHolder getResource(final ServiceContext context, final String met @Override public ResourceHolder getResourceInternal(String metadataUuid, MetadataResourceVisibility visibility, String resourceId, Boolean approved) throws Exception { - throw new UnsupportedOperationException("CMISStore does not support getResourceInternal."); + int metadataId = getAndCheckMetadataId(metadataUuid, approved); + checkResourceId(resourceId); + + try { + ServiceContext context = ServiceContext.get(); + final CmisObject object = cmisConfiguration.getClient().getObjectByPath(getKey(context, metadataUuid, metadataId, visibility, resourceId)); + return new ResourceHolderImpl(object, createResourceDescription(context, metadataUuid, visibility, resourceId, + (Document) object, metadataId, approved)); + } catch (CmisObjectNotFoundException e) { + throw new ResourceNotFoundException( + String.format("Metadata resource '%s' not found for metadata '%s'", resourceId, metadataUuid)) + .withMessageKey("exception.resourceNotFound.resource", new String[]{resourceId}) + .withDescriptionKey("exception.resourceNotFound.resource.description", new String[]{resourceId, metadataUuid}); + } } protected String getKey(final ServiceContext context, String metadataUuid, int metadataId, MetadataResourceVisibility visibility, String resourceId) { diff --git a/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java b/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java index ba300c53254..e4016a72e37 100644 --- a/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java +++ b/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java @@ -191,7 +191,22 @@ public ResourceHolder getResource(final ServiceContext context, final String met @Override public ResourceHolder getResourceInternal(String metadataUuid, MetadataResourceVisibility visibility, String resourceId, Boolean approved) throws Exception { - throw new UnsupportedOperationException("JCloud does not support getResourceInternal."); + int metadataId = getAndCheckMetadataId(metadataUuid, approved); + checkResourceId(resourceId); + + try { + ServiceContext context = ServiceContext.get(); + final Blob object = jCloudConfiguration.getClient().getBlobStore().getBlob( + jCloudConfiguration.getContainerName(), getKey(context, metadataUuid, metadataId, visibility, resourceId)); + return new ResourceHolderImpl(object, createResourceDescription(context, metadataUuid, visibility, resourceId, + object.getMetadata(), metadataId, approved)); + } catch (ContainerNotFoundException e) { + throw new ResourceNotFoundException( + String.format("Metadata resource '%s' not found for metadata '%s'", resourceId, metadataUuid)) + .withMessageKey("exception.resourceNotFound.resource", new String[]{resourceId}) + .withDescriptionKey("exception.resourceNotFound.resource.description", new String[]{resourceId, metadataUuid}); + } + } protected String getKey(final ServiceContext context, String metadataUuid, int metadataId, MetadataResourceVisibility visibility, String resourceId) {