From 24067c5ff264af48e1affbe0a8c2e5b95ad2cbf2 Mon Sep 17 00:00:00 2001 From: wangf1122 <74916635+wangf1122@users.noreply.github.com> Date: Tue, 25 Jun 2024 07:00:11 -0400 Subject: [PATCH] Add info logs to make transaction of working copy merge more traceable (#8178) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add info logs to make transaction of working copy merge more traceable * build fix * Update listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java Co-authored-by: Jose García * Update listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java Co-authored-by: Jose García * Update datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java Co-authored-by: Jose García * Update datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java Co-authored-by: Jose García * add more logs for delete folder * build fix * build fix * Update core/src/main/java/org/fao/geonet/api/records/attachments/FilesystemStore.java Co-authored-by: Jose García --------- Co-authored-by: Jose García Co-authored-by: Ian --- .../fao/geonet/api/records/attachments/FilesystemStore.java | 1 + .../org/fao/geonet/api/records/attachments/CMISStore.java | 5 +++++ .../org/fao/geonet/api/records/attachments/JCloudStore.java | 1 + .../java/org/fao/geonet/api/records/attachments/S3Store.java | 4 ++++ .../fao/geonet/listener/metadata/draft/DraftUtilities.java | 2 ++ 5 files changed, 13 insertions(+) diff --git a/core/src/main/java/org/fao/geonet/api/records/attachments/FilesystemStore.java b/core/src/main/java/org/fao/geonet/api/records/attachments/FilesystemStore.java index 4fc31b3f7a2..fb0577bc8bd 100644 --- a/core/src/main/java/org/fao/geonet/api/records/attachments/FilesystemStore.java +++ b/core/src/main/java/org/fao/geonet/api/records/attachments/FilesystemStore.java @@ -232,6 +232,7 @@ private Path getPath(ServiceContext context, int metadataId, MetadataResourceVis public String delResources(ServiceContext context, int metadataId) throws Exception { Path metadataDir = Lib.resource.getMetadataDir(getDataDirectory(context), metadataId); try { + Log.info(Geonet.RESOURCES, String.format("Deleting all files from metadataId '%d'", metadataId)); IO.deleteFileOrDirectory(metadataDir, true); return String.format("Metadata '%s' directory removed.", metadataId); } catch (Exception e) { 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 cc39c8d2d78..de258b3a711 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 @@ -391,6 +391,7 @@ public String delResources(final ServiceContext context, final int metadataId) t folderKey = getMetadataDir(context, metadataId); final Folder folder = cmisUtils.getFolderCache(folderKey, true); + Log.info(Geonet.RESOURCES, String.format("Deleting the folder of '%s' and the files within the folder", folderKey)); folder.deleteTree(true, UnfileObject.DELETE, true); cmisUtils.invalidateFolderCache(folderKey); @@ -508,7 +509,9 @@ public MetadataResourceContainer getResourceContainerDescription(final ServiceCo @Override public void copyResources(ServiceContext context, String sourceUuid, String targetUuid, MetadataResourceVisibility metadataResourceVisibility, boolean sourceApproved, boolean targetApproved) throws Exception { final int sourceMetadataId = canEdit(context, sourceUuid, metadataResourceVisibility, sourceApproved); + final int targetMetadataId = canEdit(context, sourceUuid, metadataResourceVisibility, targetApproved); final String sourceResourceTypeDir = getMetadataDir(context, sourceMetadataId) + cmisConfiguration.getFolderDelimiter() + metadataResourceVisibility.toString(); + final String targetResourceTypeDir = getMetadataDir(context, targetMetadataId) + cmisConfiguration.getFolderDelimiter() + metadataResourceVisibility.toString(); try { Folder sourceParentFolder = cmisUtils.getFolderCache(sourceResourceTypeDir, true); @@ -522,6 +525,8 @@ public void copyResources(ServiceContext context, String sourceUuid, String targ for (Map.Entry sourceEntry : sourceDocumentMap.entrySet()) { Document sourceDocument = sourceEntry.getValue(); + + Log.info(Geonet.RESOURCES, String.format("Copying %s to %s" , sourceResourceTypeDir+cmisConfiguration.getFolderDelimiter()+sourceDocument.getName(), targetResourceTypeDir)); // Get cmis properties from the source document Map sourceProperties = getProperties(sourceDocument); putResource(context, targetUuid, sourceDocument.getName(), sourceDocument.getContentStream().getStream(), null, metadataResourceVisibility, targetApproved, sourceProperties); 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 ac9f80d243d..067809526d1 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 @@ -243,6 +243,7 @@ public String delResources(final ServiceContext context, final int metadataId) t ListContainerOptions opts = new ListContainerOptions(); opts.prefix(getMetadataDir(context, metadataId) + jCloudConfiguration.getFolderDelimiter()).recursive(); + Log.info(Geonet.RESOURCES, String.format("Deleting all files from metadataId '%s'", metadataId)); // Page through the data String marker = null; do { diff --git a/datastorages/s3/src/main/java/org/fao/geonet/api/records/attachments/S3Store.java b/datastorages/s3/src/main/java/org/fao/geonet/api/records/attachments/S3Store.java index aa59182c9b6..27df07a4532 100644 --- a/datastorages/s3/src/main/java/org/fao/geonet/api/records/attachments/S3Store.java +++ b/datastorages/s3/src/main/java/org/fao/geonet/api/records/attachments/S3Store.java @@ -34,11 +34,13 @@ import com.amazonaws.services.s3.model.S3ObjectSummary; import jeeves.server.context.ServiceContext; import org.fao.geonet.api.exception.ResourceNotFoundException; +import org.fao.geonet.constants.Geonet; import org.fao.geonet.domain.MetadataResource; import org.fao.geonet.domain.MetadataResourceContainer; import org.fao.geonet.domain.MetadataResourceVisibility; import org.fao.geonet.kernel.setting.SettingManager; import org.fao.geonet.resources.S3Credentials; +import org.fao.geonet.utils.Log; import org.springframework.beans.factory.annotation.Autowired; import java.io.File; @@ -186,6 +188,8 @@ public String delResources(final ServiceContext context, final int metadataId) t try { final ListObjectsV2Result objects = s3.getClient().listObjectsV2( s3.getBucket(), getMetadataDir(metadataId)); + + Log.info(Geonet.RESOURCES, String.format("Deleting all files from metadataId '%s'", metadataId)); for (S3ObjectSummary object: objects.getObjectSummaries()) { s3.getClient().deleteObject(s3.getBucket(), object.getKey()); } diff --git a/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java b/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java index c3f6cf7704c..ce418b4062f 100644 --- a/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java +++ b/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java @@ -87,6 +87,7 @@ public AbstractMetadata replaceMetadataWithDraft(AbstractMetadata md) { * @return */ public AbstractMetadata replaceMetadataWithDraft(AbstractMetadata md, AbstractMetadata draft) { + Log.info(Geonet.DATA_MANAGER, String.format("Replacing metadata approved record (%d) with draft record (%d)", md.getId(), draft.getId())); Log.trace(Geonet.DATA_MANAGER, "Found approved record with id " + md.getId()); Log.trace(Geonet.DATA_MANAGER, "Found draft with id " + draft.getId()); // Reassign metadata validations @@ -131,6 +132,7 @@ public AbstractMetadata replaceMetadataWithDraft(AbstractMetadata md, AbstractMe } // Reassign file uploads + Log.info(Geonet.DATA_MANAGER, String.format("Copying draft record '%d' resources to approved record '%d'", draft.getId(), md.getId())); draftMetadataUtils.replaceFiles(draft, md); metadataFileUploadRepository.deleteAll(MetadataFileUploadSpecs.hasMetadataId(md.getId()));