mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
[Fix/MNT-24209] logging for download restapi (#3065)
* [fix/MNT-24209] Adding loggers in ACS download restApi * [fix/MNT-24209] Adding loggers in ACS download restApi * [fix/MNT-24209] Adding loggers in ACS download restApi * Update ZipDownloadExporter.java * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI * Revert "Update ZipDownloadExporter.java" This reverts commit2d97b34959
. * resolved Pre commit error * resolved Pre commit error * Bump io.swagger:swagger-parser from 1.0.71 to 1.0.72 (#3044) Bumps [io.swagger:swagger-parser](https://github.com/swagger-api/swagger-parser) from 1.0.71 to 1.0.72. - [Release notes](https://github.com/swagger-api/swagger-parser/releases) - [Commits](https://github.com/swagger-api/swagger-parser/compare/v1.0.71...v1.0.72) --- updated-dependencies: - dependency-name: io.swagger:swagger-parser dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * [maven-release-plugin][skip ci] prepare release 25.1.0.4 * [maven-release-plugin][skip ci] prepare for next development iteration * Update the SiteMembership Class * Update the SiteMembership Class * Update the SiteMembership Class * Revert "Update the SiteMembership Class" This reverts commit15045f9612
. * Update the SiteMembership Class * Update the SiteMembership Class * Update the license i SiteMembership * Revert "Update the license i SiteMembership" This reverts commitee8f3bec18
. * Update the license SiteMembership * Fix Precommit * Fix Precommit * Fix Precommit * Update the SiteMembership * [maven-release-plugin][skip ci] prepare release 25.1.0.5 * [maven-release-plugin][skip ci] prepare for next development iteration * Revert "Bump dependency.log4j.version from 2.23.1 to 2.24.2 (#3051)" This reverts commit748be1f4a0
. * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI * resolved Pre commit error * resolved Pre commit error * reformatting ZipDownloadExporter file * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI * [fix/MNT-24209-logging-for-download-restapi] Adding loggers in downloads RestAPI --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: mohit-singh4 <mohit.singh@contractors.hyland.com> Co-authored-by: MohinishSah <88024811+MohinishSah@users.noreply.github.com> Co-authored-by: Mohinish Sah <Mohinish.Sah@contractors.onbase.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: alfresco-build <8039454+alfresco-build@users.noreply.github.com> Co-authored-by: varapathijanakiram <172787912+varapathijanakiram@users.noreply.github.com> Co-authored-by: vjanakiram <varapathi.janakiram@hyland.com> Co-authored-by: rrajoria <88024787+rrajoria@users.noreply.github.com> Co-authored-by: Cezary Witkowski <cezary.witkowski@hyland.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -37,6 +37,12 @@ import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
@@ -51,12 +57,6 @@ import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Handler for exporting node content to a ZIP file
|
||||
@@ -93,18 +93,31 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param zipFile File
|
||||
* @param checkOutCheckInService CheckOutCheckInService
|
||||
* @param nodeService NodeService
|
||||
* @param transactionHelper RetryingTransactionHelper
|
||||
* @param updateService DownloadStatusUpdateService
|
||||
* @param downloadStorage DownloadStorage
|
||||
* @param dictionaryService DictionaryService
|
||||
* @param downloadNodeRef NodeRef
|
||||
* @param total long
|
||||
* @param totalFileCount long
|
||||
* @param zipFile
|
||||
* File
|
||||
* @param checkOutCheckInService
|
||||
* CheckOutCheckInService
|
||||
* @param nodeService
|
||||
* NodeService
|
||||
* @param transactionHelper
|
||||
* RetryingTransactionHelper
|
||||
* @param updateService
|
||||
* DownloadStatusUpdateService
|
||||
* @param downloadStorage
|
||||
* DownloadStorage
|
||||
* @param dictionaryService
|
||||
* DictionaryService
|
||||
* @param downloadNodeRef
|
||||
* NodeRef
|
||||
* @param total
|
||||
* long
|
||||
* @param totalFileCount
|
||||
* long
|
||||
*/
|
||||
public ZipDownloadExporter(File zipFile, CheckOutCheckInService checkOutCheckInService, NodeService nodeService, RetryingTransactionHelper transactionHelper, DownloadStatusUpdateService updateService, DownloadStorage downloadStorage, DictionaryService dictionaryService, NodeRef downloadNodeRef, long total, long totalFileCount)
|
||||
public ZipDownloadExporter(File zipFile, CheckOutCheckInService checkOutCheckInService, NodeService nodeService,
|
||||
RetryingTransactionHelper transactionHelper, DownloadStatusUpdateService updateService,
|
||||
DownloadStorage downloadStorage, DictionaryService dictionaryService,
|
||||
NodeRef downloadNodeRef, long total, long totalFileCount)
|
||||
{
|
||||
super(checkOutCheckInService, nodeService);
|
||||
try
|
||||
@@ -130,7 +143,7 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
{
|
||||
zipStream = new ZipArchiveOutputStream(outputStream);
|
||||
// NOTE: This encoding allows us to workaround bug...
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
|
||||
zipStream.setEncoding("UTF-8");
|
||||
zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
|
||||
zipStream.setUseLanguageEncodingFlag(true);
|
||||
@@ -140,9 +153,9 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
@Override
|
||||
public void startNode(NodeRef nodeRef)
|
||||
{
|
||||
this.currentName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||
this.zipTimestampCreated = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED);
|
||||
this.zipTimestampModified = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
|
||||
this.currentName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||
this.zipTimestampCreated = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED);
|
||||
this.zipTimestampModified = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
|
||||
path.push(new Pair<String, NodeRef>(currentName, nodeRef));
|
||||
if (dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
@@ -169,6 +182,8 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
// if the content stream to output is empty, then just return content descriptor as is
|
||||
if (content == null)
|
||||
{
|
||||
log.info("Archiving content has been removed or modified for the specified NodeReference: " + nodeRef
|
||||
+ ", and the size of the content is " + contentData.getSize());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -176,10 +191,11 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Archiving content for nodeRef: "+nodeRef+" with contentURL: "+contentData.getContentUrl());
|
||||
log.debug("Archiving content for nodeRef: " + nodeRef + " with contentURL: "
|
||||
+ contentData.getContentUrl());
|
||||
}
|
||||
// ALF-2016
|
||||
ZipArchiveEntry zipEntry=new ZipArchiveEntry(getPath());
|
||||
ZipArchiveEntry zipEntry = new ZipArchiveEntry(getPath());
|
||||
zipEntry.setTime(zipTimestampCreated.getTime());
|
||||
zipEntry.setCreationTime(FileTime.fromMillis(zipTimestampCreated.getTime()));
|
||||
zipEntry.setLastModifiedTime(FileTime.fromMillis(zipTimestampModified.getTime()));
|
||||
@@ -243,15 +259,16 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
/**
|
||||
* Copy input stream to output stream
|
||||
*
|
||||
* @param output output stream
|
||||
* @param in input stream
|
||||
* @param output
|
||||
* output stream
|
||||
* @param in
|
||||
* input stream
|
||||
* @throws IOException
|
||||
*/
|
||||
private void copyStream(OutputStream output, InputStream in)
|
||||
throws IOException
|
||||
private void copyStream(OutputStream output, InputStream in) throws IOException
|
||||
{
|
||||
byte[] buffer = new byte[2048 * 10];
|
||||
int read = in.read(buffer, 0, 2048 *10);
|
||||
int read = in.read(buffer, 0, 2048 * 10);
|
||||
int i = 0;
|
||||
while (read != -1)
|
||||
{
|
||||
@@ -259,20 +276,19 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
done = done + read;
|
||||
|
||||
// ALF-16289 - only update the status every 10MB
|
||||
if (i++%500 == 0)
|
||||
if (i++ % 500 == 0)
|
||||
{
|
||||
updateStatus();
|
||||
checkCancelled();
|
||||
}
|
||||
|
||||
read = in.read(buffer, 0, 2048 *10);
|
||||
read = in.read(buffer, 0, 2048 * 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCancelled()
|
||||
{
|
||||
boolean downloadCancelled = transactionHelper.doInTransaction(new RetryingTransactionCallback<Boolean>()
|
||||
{
|
||||
boolean downloadCancelled = transactionHelper.doInTransaction(new RetryingTransactionCallback<Boolean>() {
|
||||
@Override
|
||||
public Boolean execute() throws Throwable
|
||||
{
|
||||
@@ -280,7 +296,7 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
}
|
||||
}, true, true);
|
||||
|
||||
if ( downloadCancelled == true)
|
||||
if (downloadCancelled == true)
|
||||
{
|
||||
log.debug("Download cancelled");
|
||||
throw new DownloadCancelledException();
|
||||
@@ -289,8 +305,7 @@ public class ZipDownloadExporter extends BaseExporter
|
||||
|
||||
private void updateStatus()
|
||||
{
|
||||
transactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
transactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() {
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
|
Reference in New Issue
Block a user