Skip to content

Commit

Permalink
getResourceInternal implementation for cmis and jcloud (geonetwork#8466)
Browse files Browse the repository at this point in the history
* getResourceInternal implementation for cmis and jcloud

* Implementation in ResourceLoggerStore

* User filesystemStore bean instead of resourceStore
  • Loading branch information
wangf1122 authored and ianwallen committed Nov 1, 2024
1 parent 2ece228 commit aefe1af
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/fao/geonet/util/XslUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,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,
Expand Down

0 comments on commit aefe1af

Please sign in to comment.