[ACS-9572] Show proper message for duplicate unzipping (#3356)

This commit is contained in:
SatyamSah5
2025-05-20 15:15:42 +05:30
committed by GitHub
parent db74a6e7f2
commit a86fa21880
6 changed files with 1994 additions and 1866 deletions

View File

@@ -80,6 +80,11 @@ function runAction(p_params)
{
result.fileExist = true;
}
if (error.indexOf("FolderExistsException") != -1)
{
result.fileExist = true;
result.type = "folder";
}
}
results.push(result);

View File

@@ -58,6 +58,7 @@ import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FolderExistsException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -73,6 +74,7 @@ import org.alfresco.util.TempFileProvider;
*
* @author gavinc
*/
@SuppressWarnings("PMD.PreserveStackTrace")
public class ImporterActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "import";
@@ -366,7 +368,11 @@ public class ImporterActionExecuter extends ActionExecuterAbstractBase
catch (FileExistsException e)
{
// TODO: add failed file info to status message?
throw new AlfrescoRuntimeException("Failed to process ZIP file.", e);
if (e.getType().equalsIgnoreCase("folder"))
{
throw new FolderExistsException(root, file.getName());
}
throw e;
}
}
}

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -23,41 +23,55 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.model;
import org.alfresco.api.AlfrescoPublicApi;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Common exception thrown when an operation fails because of a name clash.
*
* @author Derek Hulley
*/
@AlfrescoPublicApi
public class FileExistsException extends AlfrescoRuntimeException
{
private static final String MESSAGE_ID = "file_folder_service.file_exists_message";
private static final long serialVersionUID = -4133713912784624118L;
private NodeRef parentNodeRef;
private String name;
public FileExistsException(NodeRef parentNodeRef, String name)
{
super(MESSAGE_ID, new Object[] { name });
this.parentNodeRef = parentNodeRef;
this.name = name;
}
public NodeRef getParentNodeRef()
{
return parentNodeRef;
}
public String getName()
{
return name;
}
}
package org.alfresco.service.cmr.model;
import org.alfresco.api.AlfrescoPublicApi;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Common exception thrown when an operation fails because of a name clash.
*
* @author Derek Hulley
*/
@AlfrescoPublicApi
public class FileExistsException extends AlfrescoRuntimeException
{
private static final String MESSAGE_ID = "file_folder_service.file_exists_message";
private static final long serialVersionUID = -4133713912784624118L;
private NodeRef parentNodeRef;
private String name;
private String type;
public FileExistsException(NodeRef parentNodeRef, String name)
{
super(MESSAGE_ID, new Object[]{name});
this.parentNodeRef = parentNodeRef;
this.name = name;
}
public FileExistsException(NodeRef parentNodeRef, String name, String type)
{
super(MESSAGE_ID, new Object[]{name});
this.parentNodeRef = parentNodeRef;
this.name = name;
this.type = type;
}
public NodeRef getParentNodeRef()
{
return parentNodeRef;
}
public String getName()
{
return name;
}
public String getType()
{
return type;
}
}

View File

@@ -0,0 +1,62 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.model;
import org.alfresco.api.AlfrescoPublicApi;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Common exception thrown when an operation fails because of a name clash of folder.
*
*/
@AlfrescoPublicApi
public class FolderExistsException extends AlfrescoRuntimeException
{
private static final String MESSAGE_ID = "file_folder_service.file_exists_message";
private static final long serialVersionUID = -4133713912784624118L;
private NodeRef parentNodeRef;
private String name;
public FolderExistsException(NodeRef parentNodeRef, String name)
{
super(MESSAGE_ID, new Object[]{name});
this.parentNodeRef = parentNodeRef;
this.name = name;
}
public NodeRef getParentNodeRef()
{
return parentNodeRef;
}
public String getName()
{
return name;
}
}

View File

@@ -48,6 +48,7 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.model.FolderExistsException;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -62,7 +63,7 @@ import org.alfresco.util.test.junitrules.ApplicationContextInit;
*
* @author abalmus
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@SuppressWarnings("PMD.UnitTestsShouldIncludeAssert")
public class ImporterActionExecuterTest
{
// Rule to initialise the default Alfresco spring configuration
@@ -340,6 +341,49 @@ public class ImporterActionExecuterTest
});
}
@Test
public void testDuplicateUnzipping() throws IOException
{
final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getRetryingTransactionHelper();
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable
{
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
// create test data
NodeRef zipFileNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT).getChildRef();
NodeRef targetFolderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_FOLDER).getChildRef();
putContent(zipFileNodeRef, "import-archive-test/accentCharTestZip.zip");
Action action = createAction(zipFileNodeRef, "ImporterActionExecuterTestActionDefinition", targetFolderNodeRef);
try
{
importerActionExecuter.setUncompressedBytesLimit("100000");
importerActionExecuter.execute(action, zipFileNodeRef);
// unzip again to duplicate node
importerActionExecuter.execute(action, zipFileNodeRef);
}
catch (FolderExistsException e)
{
assertTrue(e.getMessage().contains("File or folder accentCharTestZip already exists"));
}
finally
{
// clean test data
nodeService.deleteNode(targetFolderNodeRef);
nodeService.deleteNode(zipFileNodeRef);
}
return null;
}
});
}
private void putContent(NodeRef zipFileNodeRef, String resource)
{
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource(resource);