ACS-7587 Fix PMD issues

This commit is contained in:
Damian Ujma
2024-05-17 15:14:40 +02:00
parent 0de1aca0f6
commit 7b516f24b6
6 changed files with 32 additions and 22 deletions

View File

@@ -33,7 +33,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.alfresco.utility.model.TestModel;
@@ -83,9 +82,13 @@ public class HoldBulkStatus extends TestModel
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
HoldBulkStatus that = (HoldBulkStatus) o;
return processedItems == that.processedItems && errorsCount == that.errorsCount && totalItems == that.totalItems
&& Objects.equals(bulkStatusId, that.bulkStatusId) && Objects.equals(startTime,

View File

@@ -193,11 +193,12 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
users.add(userAddHoldPermission);
STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperation contentFromFolderAndSubfoldersBulkOp = HoldBulkOperation.builder()
// Get content from folder and all subfolders of the root folder
HoldBulkOperation bulkOperation = HoldBulkOperation.builder()
.query(getContentFromFolderAndAllSubfoldersQuery(rootFolder.getNodeRefWithoutVersion()))
.op(HoldBulkOperationType.ADD).build();
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
.startBulkProcess(contentFromFolderAndSubfoldersBulkOp, hold3.getId());
.startBulkProcess(bulkOperation, hold3.getId());
// Verify the status code
assertStatusCode(ACCEPTED);
@@ -278,23 +279,24 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
@Test
public void testBulkProcessWithUserWithoutWritePermissionOnTheContent()
{
UserModel userWithoutWritePermissionOnTheContent = roleService.createUserWithSiteRoleRMRoleAndPermission(
// User without write permission on the content
UserModel userWithoutPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(
testSite, UserRole.SiteConsumer,
hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
users.add(userWithoutWritePermissionOnTheContent);
users.add(userWithoutPermission);
STEP("Add content from the site to the hold using the bulk API.");
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(
userWithoutWritePermissionOnTheContent).startBulkProcess(holdBulkOperation, hold.getId());
userWithoutPermission).startBulkProcess(holdBulkOperation, hold.getId());
STEP("Verify the response.");
assertStatusCode(ACCEPTED);
await().atMost(20, TimeUnit.SECONDS).until(() ->
getRestAPIFactory().getHoldsAPI(userWithoutWritePermissionOnTheContent)
getRestAPIFactory().getHoldsAPI(userWithoutPermission)
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()).getStatus() == Status.DONE);
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userWithoutWritePermissionOnTheContent)
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userWithoutPermission)
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId());
assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, NUMBER_OF_FILES, ACCESS_DENIED_ERROR_MESSAGE);
}
@@ -390,7 +392,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
* Then the user receives bad request error
*/
@Test
public void getBulkStatusesForInvalidOperation()
public void testGetBulkStatusesForInvalidOperation()
{
STEP("Start bulk process for non existent hold");
@@ -409,7 +411,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
* Then the user receives not found error
*/
@Test
public void getBulkStatusForNonExistentHold()
public void testGetBulkStatusForNonExistentHold()
{
STEP("Start bulk process for non existent hold");
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatus("nonExistentHoldId", "nonExistenBulkStatusId");
@@ -425,7 +427,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
* Then the user receives not found error
*/
@Test
public void getBulkStatusForNonExistentBulkStatus()
public void testGetBulkStatusForNonExistentBulkStatus()
{
STEP("Start bulk process for non bulk status");
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatus(hold.getId(), "nonExistenBulkStatusId");
@@ -441,7 +443,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
* Then the user receives not found error
*/
@Test
public void getBulkStatusesForNonExistentHold()
public void testGetBulkStatusesForNonExistentHold()
{
STEP("Start bulk process for non existent hold");
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatuses("nonExistentHoldId");

View File

@@ -49,7 +49,7 @@ import org.springframework.beans.factory.InitializingBean;
*/
public abstract class BulkBaseService<T> implements InitializingBean
{
private static final Log logger = LogFactory.getLog(BulkBaseService.class);
private static final Log LOG = LogFactory.getLog(BulkBaseService.class);
protected ServiceRegistry serviceRegistry;
protected SearchService searchService;
@@ -103,7 +103,7 @@ public abstract class BulkBaseService<T> implements InitializingBean
threadCount,
itemsPerTransaction,
bulkStatusUpdater,
logger,
LOG,
loggingIntervalMs);
runAsyncBatchProcessor(batchProcessor, batchProcessWorker, bulkStatusUpdater);
@@ -119,19 +119,19 @@ public abstract class BulkBaseService<T> implements InitializingBean
Runnable backgroundLogic = () -> {
try
{
if (logger.isDebugEnabled())
if (LOG.isDebugEnabled())
{
logger.debug("Started processing batch with name: " + batchProcessor.getProcessName());
LOG.debug("Started processing batch with name: " + batchProcessor.getProcessName());
}
batchProcessor.processLong(batchProcessWorker, true);
if (logger.isDebugEnabled())
if (LOG.isDebugEnabled())
{
logger.debug("Processing batch with name: " + batchProcessor.getProcessName() + " completed");
LOG.debug("Processing batch with name: " + batchProcessor.getProcessName() + " completed");
}
}
catch (Throwable t)
catch (Exception exception)
{
logger.error("Error processing batch with name: " + batchProcessor.getProcessName(), t);
LOG.error("Error processing batch with name: " + batchProcessor.getProcessName(), exception);
}
finally
{

View File

@@ -47,11 +47,13 @@ public class DefaultHoldBulkMonitor extends AbstractLifecycleBean implements Hol
protected SimpleCache<String, HoldBulkStatus> holdProgressCache;
protected SimpleCache<String, List<HoldBulkProcessDetails>> holdProcessRegistry;
@Override
public void updateBulkStatus(HoldBulkStatus holdBulkStatus)
{
holdProgressCache.put(holdBulkStatus.bulkStatusId(), holdBulkStatus);
}
@Override
public void registerProcess(NodeRef holdRef, String processId)
{
List<HoldBulkProcessDetails> processIds = Optional.ofNullable(holdProcessRegistry.get(holdRef.getId()))
@@ -60,11 +62,13 @@ public class DefaultHoldBulkMonitor extends AbstractLifecycleBean implements Hol
holdProcessRegistry.put(holdRef.getId(), processIds);
}
@Override
public HoldBulkStatus getBulkStatus(String bulkStatusId)
{
return holdProgressCache.get(bulkStatusId);
}
@Override
public List<HoldBulkStatus> getBatchStatusesForHold(String holdId)
{
return Optional.ofNullable(holdProcessRegistry.get(holdId))

View File

@@ -49,6 +49,7 @@ public class HoldBulkStatusUpdater implements BulkStatusUpdater
batchMonitor.getLastError()));
}
@Override
public void update()
{
if (task != null)

View File

@@ -89,14 +89,14 @@ public class DefaultHoldBulkMonitorUnitTest
}
@Test
public void getBatchStatusesForHoldReturnsEmptyListWhenNoProcesses()
public void testGetBatchStatusesForHoldReturnsEmptyListWhenNoProcesses()
{
when(holdProcessRegistry.get("holdId")).thenReturn(null);
assertEquals(Collections.emptyList(), holdBulkMonitor.getBatchStatusesForHold("holdId"));
}
@Test
public void getBatchStatusesForHoldReturnsSortedStatuses()
public void testGetBatchStatusesForHoldReturnsSortedStatuses()
{
HoldBulkStatus status1 = new HoldBulkStatus(null, new Date(1000), new Date(2000), 0L, 0L, 0L, null);
HoldBulkStatus status2 = new HoldBulkStatus(null, new Date(3000), null, 0L, 0L, 0L, null);