Skip to content

Commit

Permalink
Add info logs to make transaction of working copy merge more traceable (
Browse files Browse the repository at this point in the history
geonetwork#8178)

* 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 <[email protected]>

* Update listeners/src/main/java/org/fao/geonet/listener/metadata/draft/DraftUtilities.java

Co-authored-by: Jose García <[email protected]>

* Update datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java

Co-authored-by: Jose García <[email protected]>

* Update datastorages/cmis/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java

Co-authored-by: Jose García <[email protected]>

* 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 <[email protected]>

---------

Co-authored-by: Jose García <[email protected]>
Co-authored-by: Ian <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent 9378975 commit 4c63865
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -522,6 +525,8 @@ public void copyResources(ServiceContext context, String sourceUuid, String targ
for (Map.Entry<String, Document> 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<String, Object> sourceProperties = getProperties(sourceDocument);
putResource(context, targetUuid, sourceDocument.getName(), sourceDocument.getContentStream().getStream(), null, metadataResourceVisibility, targetApproved, sourceProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 4c63865

Please sign in to comment.