Skip to content

Commit

Permalink
getResourceInternal implementation for cmis and jcloud (#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 Nov 1, 2024
1 parent b62e6c2 commit c93b5b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
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 @@ -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,
Expand Down
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

0 comments on commit c93b5b1

Please sign in to comment.