mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACS-7587 Fix PMD issues
This commit is contained in:
@@ -33,7 +33,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.alfresco.utility.model.TestModel;
|
import org.alfresco.utility.model.TestModel;
|
||||||
|
|
||||||
@@ -83,9 +82,13 @@ public class HoldBulkStatus extends TestModel
|
|||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
if (this == o)
|
if (this == o)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if (o == null || getClass() != o.getClass())
|
if (o == null || getClass() != o.getClass())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
HoldBulkStatus that = (HoldBulkStatus) o;
|
HoldBulkStatus that = (HoldBulkStatus) o;
|
||||||
return processedItems == that.processedItems && errorsCount == that.errorsCount && totalItems == that.totalItems
|
return processedItems == that.processedItems && errorsCount == that.errorsCount && totalItems == that.totalItems
|
||||||
&& Objects.equals(bulkStatusId, that.bulkStatusId) && Objects.equals(startTime,
|
&& Objects.equals(bulkStatusId, that.bulkStatusId) && Objects.equals(startTime,
|
||||||
|
@@ -193,11 +193,12 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
|
|||||||
users.add(userAddHoldPermission);
|
users.add(userAddHoldPermission);
|
||||||
|
|
||||||
STEP("Add content from the site to the hold using the bulk API.");
|
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()))
|
.query(getContentFromFolderAndAllSubfoldersQuery(rootFolder.getNodeRefWithoutVersion()))
|
||||||
.op(HoldBulkOperationType.ADD).build();
|
.op(HoldBulkOperationType.ADD).build();
|
||||||
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
|
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(userAddHoldPermission)
|
||||||
.startBulkProcess(contentFromFolderAndSubfoldersBulkOp, hold3.getId());
|
.startBulkProcess(bulkOperation, hold3.getId());
|
||||||
|
|
||||||
// Verify the status code
|
// Verify the status code
|
||||||
assertStatusCode(ACCEPTED);
|
assertStatusCode(ACCEPTED);
|
||||||
@@ -278,23 +279,24 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
|
|||||||
@Test
|
@Test
|
||||||
public void testBulkProcessWithUserWithoutWritePermissionOnTheContent()
|
public void testBulkProcessWithUserWithoutWritePermissionOnTheContent()
|
||||||
{
|
{
|
||||||
UserModel userWithoutWritePermissionOnTheContent = roleService.createUserWithSiteRoleRMRoleAndPermission(
|
// User without write permission on the content
|
||||||
|
UserModel userWithoutPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(
|
||||||
testSite, UserRole.SiteConsumer,
|
testSite, UserRole.SiteConsumer,
|
||||||
hold.getId(), UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
|
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.");
|
STEP("Add content from the site to the hold using the bulk API.");
|
||||||
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(
|
HoldBulkOperationEntry bulkOperationEntry = getRestAPIFactory().getHoldsAPI(
|
||||||
userWithoutWritePermissionOnTheContent).startBulkProcess(holdBulkOperation, hold.getId());
|
userWithoutPermission).startBulkProcess(holdBulkOperation, hold.getId());
|
||||||
|
|
||||||
STEP("Verify the response.");
|
STEP("Verify the response.");
|
||||||
assertStatusCode(ACCEPTED);
|
assertStatusCode(ACCEPTED);
|
||||||
|
|
||||||
await().atMost(20, TimeUnit.SECONDS).until(() ->
|
await().atMost(20, TimeUnit.SECONDS).until(() ->
|
||||||
getRestAPIFactory().getHoldsAPI(userWithoutWritePermissionOnTheContent)
|
getRestAPIFactory().getHoldsAPI(userWithoutPermission)
|
||||||
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()).getStatus() == Status.DONE);
|
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId()).getStatus() == Status.DONE);
|
||||||
|
|
||||||
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userWithoutWritePermissionOnTheContent)
|
HoldBulkStatus holdBulkStatus = getRestAPIFactory().getHoldsAPI(userWithoutPermission)
|
||||||
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId());
|
.getBulkStatus(hold.getId(), bulkOperationEntry.getBulkStatusId());
|
||||||
assertBulkProcessStatus(holdBulkStatus, NUMBER_OF_FILES, NUMBER_OF_FILES, ACCESS_DENIED_ERROR_MESSAGE);
|
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
|
* Then the user receives bad request error
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getBulkStatusesForInvalidOperation()
|
public void testGetBulkStatusesForInvalidOperation()
|
||||||
{
|
{
|
||||||
STEP("Start bulk process for non existent hold");
|
STEP("Start bulk process for non existent hold");
|
||||||
|
|
||||||
@@ -409,7 +411,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
|
|||||||
* Then the user receives not found error
|
* Then the user receives not found error
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getBulkStatusForNonExistentHold()
|
public void testGetBulkStatusForNonExistentHold()
|
||||||
{
|
{
|
||||||
STEP("Start bulk process for non existent hold");
|
STEP("Start bulk process for non existent hold");
|
||||||
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatus("nonExistentHoldId", "nonExistenBulkStatusId");
|
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatus("nonExistentHoldId", "nonExistenBulkStatusId");
|
||||||
@@ -425,7 +427,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
|
|||||||
* Then the user receives not found error
|
* Then the user receives not found error
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getBulkStatusForNonExistentBulkStatus()
|
public void testGetBulkStatusForNonExistentBulkStatus()
|
||||||
{
|
{
|
||||||
STEP("Start bulk process for non bulk status");
|
STEP("Start bulk process for non bulk status");
|
||||||
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatus(hold.getId(), "nonExistenBulkStatusId");
|
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatus(hold.getId(), "nonExistenBulkStatusId");
|
||||||
@@ -441,7 +443,7 @@ public class AddToHoldsBulkV1Tests extends BaseRMRestTest
|
|||||||
* Then the user receives not found error
|
* Then the user receives not found error
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getBulkStatusesForNonExistentHold()
|
public void testGetBulkStatusesForNonExistentHold()
|
||||||
{
|
{
|
||||||
STEP("Start bulk process for non existent hold");
|
STEP("Start bulk process for non existent hold");
|
||||||
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatuses("nonExistentHoldId");
|
getRestAPIFactory().getHoldsAPI(getAdminUser()).getBulkStatuses("nonExistentHoldId");
|
||||||
|
@@ -49,7 +49,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
*/
|
*/
|
||||||
public abstract class BulkBaseService<T> implements 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 ServiceRegistry serviceRegistry;
|
||||||
protected SearchService searchService;
|
protected SearchService searchService;
|
||||||
@@ -103,7 +103,7 @@ public abstract class BulkBaseService<T> implements InitializingBean
|
|||||||
threadCount,
|
threadCount,
|
||||||
itemsPerTransaction,
|
itemsPerTransaction,
|
||||||
bulkStatusUpdater,
|
bulkStatusUpdater,
|
||||||
logger,
|
LOG,
|
||||||
loggingIntervalMs);
|
loggingIntervalMs);
|
||||||
|
|
||||||
runAsyncBatchProcessor(batchProcessor, batchProcessWorker, bulkStatusUpdater);
|
runAsyncBatchProcessor(batchProcessor, batchProcessWorker, bulkStatusUpdater);
|
||||||
@@ -119,19 +119,19 @@ public abstract class BulkBaseService<T> implements InitializingBean
|
|||||||
Runnable backgroundLogic = () -> {
|
Runnable backgroundLogic = () -> {
|
||||||
try
|
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);
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
@@ -47,11 +47,13 @@ public class DefaultHoldBulkMonitor extends AbstractLifecycleBean implements Hol
|
|||||||
protected SimpleCache<String, HoldBulkStatus> holdProgressCache;
|
protected SimpleCache<String, HoldBulkStatus> holdProgressCache;
|
||||||
protected SimpleCache<String, List<HoldBulkProcessDetails>> holdProcessRegistry;
|
protected SimpleCache<String, List<HoldBulkProcessDetails>> holdProcessRegistry;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void updateBulkStatus(HoldBulkStatus holdBulkStatus)
|
public void updateBulkStatus(HoldBulkStatus holdBulkStatus)
|
||||||
{
|
{
|
||||||
holdProgressCache.put(holdBulkStatus.bulkStatusId(), holdBulkStatus);
|
holdProgressCache.put(holdBulkStatus.bulkStatusId(), holdBulkStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void registerProcess(NodeRef holdRef, String processId)
|
public void registerProcess(NodeRef holdRef, String processId)
|
||||||
{
|
{
|
||||||
List<HoldBulkProcessDetails> processIds = Optional.ofNullable(holdProcessRegistry.get(holdRef.getId()))
|
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);
|
holdProcessRegistry.put(holdRef.getId(), processIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public HoldBulkStatus getBulkStatus(String bulkStatusId)
|
public HoldBulkStatus getBulkStatus(String bulkStatusId)
|
||||||
{
|
{
|
||||||
return holdProgressCache.get(bulkStatusId);
|
return holdProgressCache.get(bulkStatusId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<HoldBulkStatus> getBatchStatusesForHold(String holdId)
|
public List<HoldBulkStatus> getBatchStatusesForHold(String holdId)
|
||||||
{
|
{
|
||||||
return Optional.ofNullable(holdProcessRegistry.get(holdId))
|
return Optional.ofNullable(holdProcessRegistry.get(holdId))
|
||||||
|
@@ -49,6 +49,7 @@ public class HoldBulkStatusUpdater implements BulkStatusUpdater
|
|||||||
batchMonitor.getLastError()));
|
batchMonitor.getLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
if (task != null)
|
if (task != null)
|
||||||
|
@@ -89,14 +89,14 @@ public class DefaultHoldBulkMonitorUnitTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBatchStatusesForHoldReturnsEmptyListWhenNoProcesses()
|
public void testGetBatchStatusesForHoldReturnsEmptyListWhenNoProcesses()
|
||||||
{
|
{
|
||||||
when(holdProcessRegistry.get("holdId")).thenReturn(null);
|
when(holdProcessRegistry.get("holdId")).thenReturn(null);
|
||||||
assertEquals(Collections.emptyList(), holdBulkMonitor.getBatchStatusesForHold("holdId"));
|
assertEquals(Collections.emptyList(), holdBulkMonitor.getBatchStatusesForHold("holdId"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBatchStatusesForHoldReturnsSortedStatuses()
|
public void testGetBatchStatusesForHoldReturnsSortedStatuses()
|
||||||
{
|
{
|
||||||
HoldBulkStatus status1 = new HoldBulkStatus(null, new Date(1000), new Date(2000), 0L, 0L, 0L, null);
|
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);
|
HoldBulkStatus status2 = new HoldBulkStatus(null, new Date(3000), null, 0L, 0L, 0L, null);
|
||||||
|
Reference in New Issue
Block a user