Skip to content

Commit

Permalink
Revert "[MNT-24137] Audit Issue Internal Server Error fix (#2786)" (#…
Browse files Browse the repository at this point in the history
…3100)

* Revert "[MNT-24137] Audit Issue Internal Server Error fix (#2786)"

This reverts commit cabc38b.

* Pre-commit changes
  • Loading branch information
evasques authored Dec 17, 2024
1 parent b595e41 commit 2652cda
Show file tree
Hide file tree
Showing 10 changed files with 2,680 additions and 2,617 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
import org.alfresco.repo.domain.propval.PropertyStringValueEntity;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
import org.alfresco.repo.domain.propval.PropertyStringValueEntity;

/**
* RM V3.3 Hold audit entries values patch unit test
*
Expand All @@ -55,7 +56,6 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
@InjectMocks
private RMv33HoldAuditEntryValuesPatch patch;


@Before
public void setUp()
{
Expand Down Expand Up @@ -93,15 +93,15 @@ public void holdAuditEntriesAreUpdatedAfterUpgrade()
verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(deleteHoldPropertyStringValueEntity);

assertEquals("Add To Hold", addToHoldPropertyStringValueEntity.getStringValue());
assertEquals("add to hold", addToHoldPropertyStringValueEntity.getStringLower());
assertEquals("add to hold", addToHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(770_786_109L), addToHoldPropertyStringValueEntity.getStringCrc());

assertEquals("Remove From Hold", removeFromHoldPropertyStringValueEntity.getStringValue());
assertEquals("remove from hold", removeFromHoldPropertyStringValueEntity.getStringLower());
assertEquals("remove from hold", removeFromHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(2_967_613_012L), removeFromHoldPropertyStringValueEntity.getStringCrc());

assertEquals("Delete Hold", deleteHoldPropertyStringValueEntity.getStringValue());
assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringLower());
assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(132_640_810L), deleteHoldPropertyStringValueEntity.getStringCrc());
}

Expand All @@ -123,5 +123,3 @@ public void patchRunWithSuccessWhenNoHoldEntries()
verify(mockedRecordsManagementQueryDAO, times(0)).updatePropertyStringValueEntity(any());
}
}


56 changes: 29 additions & 27 deletions remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2024 Alfresco Software Limited
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
Expand Down Expand Up @@ -85,7 +85,7 @@ public class AuditImpl implements Audit

// list of equals filter's auditEntry (via where clause)
private final static Set<String> LIST_AUDIT_ENTRY_EQUALS_QUERY_PROPERTIES = new HashSet<>(
Arrays.asList(new String[] { CREATED_BY_USER, VALUES_KEY, VALUES_VALUE }));
Arrays.asList(new String[]{CREATED_BY_USER, VALUES_KEY, VALUES_VALUE}));

// map of sort parameters for the moment one createdAt
private final static Map<String, String> SORT_PARAMS_TO_NAMES;
Expand Down Expand Up @@ -295,23 +295,29 @@ public CollectionWithPagingInfo<AuditEntry> listAuditEntries(String auditAppId,
}
else
{
if (hasMoreItems) {
if (q != null) {
if (hasMoreItems)
{
if (q != null)
{
// filtering via "where" clause
AuditEntryQueryWalker propertyWalker = new AuditEntryQueryWalker();
QueryHelper.walk(q, propertyWalker);
totalItems = getAuditEntriesCountByAppAndProperties(auditApplication, propertyWalker);
} else {
}
else
{
totalItems = getAuditEntriesCountByApp(auditApplication);
}
} else {
}
else
{
totalItems = totalRetrievedItems;
}
}

entriesAudit = (skipCount >= totalRetrievedItems)
? Collections.emptyList()
: entriesAudit.subList(skipCount, end);
? Collections.emptyList()
: entriesAudit.subList(skipCount, end);
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
}

Expand Down Expand Up @@ -475,8 +481,7 @@ public List<AuditEntry> getQueryResultAuditEntries(AuditService.AuditApplication
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);

// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback()
{
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired()
{
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
Expand Down Expand Up @@ -532,7 +537,7 @@ public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters
params.setApplicationName(auditApplication.getName());
params.setFromId(auditEntryId);
params.setToId(auditEntryId + 1);

List<String> includeParam = new ArrayList<>();
if (parameters != null)
{
Expand All @@ -545,8 +550,7 @@ public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters
final List<AuditEntry> results = new ArrayList<>();

// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback()
{
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired()
{
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
Expand Down Expand Up @@ -710,8 +714,7 @@ private void validateWhereBetween(String auditAppId, Long from, Long to)
@Override
public CollectionWithPagingInfo<AuditEntry> listAuditEntriesByNodeId(String nodeId, Parameters parameters)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception
{
checkEnabled();
Expand Down Expand Up @@ -772,17 +775,15 @@ private List<AuditEntry> getQueryResultAuditEntriesByNodeRef(NodeRef nodeRef, Au
final List<AuditEntry> results = new ArrayList<>();

String auditAppId = "alfresco-access";
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>()
{
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>() {
public String doWork() throws Exception
{
return findAuditAppByIdOr404(auditAppId).getName();
}
}, AuthenticationUtil.getSystemUserName());

// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback()
{
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired()
{
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
Expand All @@ -808,8 +809,7 @@ public boolean handleAuditEntry(Long entryId, String applicationName, String use
Long toTime = propertyWalker.getToTime();
validateWhereBetween(nodeRef.getId(), fromTime, toTime);

AuthenticationUtil.runAs(new RunAsWork<Object>()
{
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() throws Exception
{
// QueryParameters
Expand All @@ -820,7 +820,7 @@ public Object doWork() throws Exception
pathParams.setFromTime(fromTime);
pathParams.setToTime(toTime);
pathParams.setApplicationName(auditApplicationName);
pathParams.addSearchKey("/"+auditAppId+"/transaction/path", nodePath);
pathParams.addSearchKey("/" + auditAppId + "/transaction/path", nodePath);
auditService.auditQuery(callback, pathParams, limit);

AuditQueryParameters copyFromPathParams = new AuditQueryParameters();
Expand All @@ -830,7 +830,7 @@ public Object doWork() throws Exception
copyFromPathParams.setFromTime(fromTime);
copyFromPathParams.setToTime(toTime);
copyFromPathParams.setApplicationName(auditApplicationName);
copyFromPathParams.addSearchKey("/"+auditAppId+"/transaction/copy/from/path", nodePath);
copyFromPathParams.addSearchKey("/" + auditAppId + "/transaction/copy/from/path", nodePath);
auditService.auditQuery(callback, copyFromPathParams, limit);

AuditQueryParameters moveFromPathParams = new AuditQueryParameters();
Expand All @@ -840,7 +840,7 @@ public Object doWork() throws Exception
moveFromPathParams.setFromTime(fromTime);
moveFromPathParams.setToTime(toTime);
moveFromPathParams.setApplicationName(auditApplicationName);
moveFromPathParams.addSearchKey("/"+auditAppId+"/transaction/move/from/path", nodePath);
moveFromPathParams.addSearchKey("/" + auditAppId + "/transaction/move/from/path", nodePath);
auditService.auditQuery(callback, moveFromPathParams, limit);

return null;
Expand All @@ -857,7 +857,7 @@ private class AuditEntriesByNodeIdQueryWalker extends MapBasedQueryWalker

public AuditEntriesByNodeIdQueryWalker()
{
super(new HashSet<>(Arrays.asList(new String[] { CREATED_BY_USER })), null);
super(new HashSet<>(Arrays.asList(new String[]{CREATED_BY_USER})), null);
}

@Override
Expand Down Expand Up @@ -909,14 +909,16 @@ public int getAuditEntriesCountByApp(AuditService.AuditApplication auditApplicat

public int getAuditEntriesCountByAppAndProperties(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker)
{
final String applicationName = auditApplication.getKey().substring(1);

AuditQueryParameters parameters = new AuditQueryParameters();
parameters.setApplicationName(auditApplication.getName());
parameters.setApplicationName(applicationName);
parameters.setFromTime(propertyWalker.getFromTime());
parameters.setToTime(propertyWalker.getToTime());
parameters.setFromId(propertyWalker.getFromId());
parameters.setToId(propertyWalker.getToId());
parameters.setUser(propertyWalker.getCreatedByUser());

return auditService.getAuditEntriesCountByAppAndProperties(parameters);
return auditService.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
}
}
Loading

0 comments on commit 2652cda

Please sign in to comment.