Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info logs to make transaction of working copy merge more traceable #8178

Merged
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));
ianwallen marked this conversation as resolved.
Show resolved Hide resolved
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
Loading