From cabc38b386cbb400a901047e7a101b619107d31b Mon Sep 17 00:00:00 2001 From: SathishK-T <166369440+SathishK-T@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:19:19 +0530 Subject: [PATCH] [MNT-24137] Audit Issue Internal Server Error fix (#2786) * [MNT-24137][ags][tas] Audit Bug Fix * [MNT-24137][ags][tas] Audit Bug Fix * [MNT-24137][ags][tas] Audit Bug Fix * [MNT-24137][ags][tas] Audit Bug Fix * [MNT-24137][ags][tas] Audit Bug Fix * [MNT-24137][ags][tas] Audit Bug Fix * [MNT-24137][ags][tas] Audit Bug Fix --------- Co-authored-by: Sathish Kumar --- ...Mv33HoldAuditEntryValuesPatchUnitTest.java | 6 +- .../org/alfresco/rest/api/impl/AuditImpl.java | 8 +-- .../alfresco/repo/audit/AuditComponent.java | 5 +- .../repo/audit/AuditComponentImpl.java | 10 ++- .../alfresco/repo/audit/AuditServiceImpl.java | 6 +- .../org/alfresco/repo/domain/CrcHelper.java | 63 +++++++++--------- .../alfresco/repo/domain/audit/AuditDAO.java | 5 +- .../domain/audit/ibatis/AuditDAOImpl.java | 4 +- .../propval/PropertyStringValueEntity.java | 64 +++++++++++-------- .../service/cmr/audit/AuditService.java | 5 +- 10 files changed, 92 insertions(+), 84 deletions(-) diff --git a/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java b/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java index 44be8da09db..e89f055e453 100644 --- a/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java +++ b/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java @@ -93,15 +93,15 @@ public void holdAuditEntriesAreUpdatedAfterUpgrade() verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(deleteHoldPropertyStringValueEntity); assertEquals("Add To Hold", addToHoldPropertyStringValueEntity.getStringValue()); - assertEquals("add to hold", addToHoldPropertyStringValueEntity.getStringEndLower()); + assertEquals("add to hold", addToHoldPropertyStringValueEntity.getStringLower()); assertEquals(Long.valueOf(770_786_109L), addToHoldPropertyStringValueEntity.getStringCrc()); assertEquals("Remove From Hold", removeFromHoldPropertyStringValueEntity.getStringValue()); - assertEquals("remove from hold", removeFromHoldPropertyStringValueEntity.getStringEndLower()); + assertEquals("remove from hold", removeFromHoldPropertyStringValueEntity.getStringLower()); assertEquals(Long.valueOf(2_967_613_012L), removeFromHoldPropertyStringValueEntity.getStringCrc()); assertEquals("Delete Hold", deleteHoldPropertyStringValueEntity.getStringValue()); - assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringEndLower()); + assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringLower()); assertEquals(Long.valueOf(132_640_810L), deleteHoldPropertyStringValueEntity.getStringCrc()); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java index cf44a92f9c4..d2259e3c6cf 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * 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 @@ -909,16 +909,14 @@ 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(applicationName); + parameters.setApplicationName(auditApplication.getName()); parameters.setFromTime(propertyWalker.getFromTime()); parameters.setToTime(propertyWalker.getToTime()); parameters.setFromId(propertyWalker.getFromId()); parameters.setToId(propertyWalker.getToId()); parameters.setUser(propertyWalker.getCreatedByUser()); - return auditService.getAuditEntriesCountByAppAndProperties(applicationName, parameters); + return auditService.getAuditEntriesCountByAppAndProperties(parameters); } } diff --git a/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java b/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java index 821c0c47594..29955432a7b 100644 --- a/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java +++ b/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java @@ -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 @@ -276,11 +276,10 @@ default int getAuditEntriesCountByApp(String applicationName) /** * Issue an audit query to retrieve count of records for a given application and properties * - * @param applicationName the name of the application * @param parameters audit parameters provided by the where clause on the ReST API * @return a map containing min/max and the associated value */ - default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) + default int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) { return -1; } diff --git a/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java b/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java index 38fbd5ff690..98479db3af1 100644 --- a/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -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 @@ -956,10 +956,8 @@ public int getAuditEntriesCountByApp(String applicationName) return auditDAO.getAuditEntriesCountByApp(applicationId); } - @Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) + @Override public int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) { - org.alfresco.repo.domain.audit.AuditQueryParameters dbParameters = new org.alfresco.repo.domain.audit.AuditQueryParameters(); - - return auditDAO.getAuditEntriesCountByAppAndProperties(applicationName, parameters); + return auditDAO.getAuditEntriesCountByAppAndProperties(parameters); } -} +} \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java b/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java index 7c92ec8e3f6..4824914e513 100644 --- a/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java @@ -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 @@ -190,8 +190,8 @@ public int getAuditEntriesCountByApp(String applicationName) /** * {@inheritDoc} */ - @Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) + @Override public int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) { - return auditComponent.getAuditEntriesCountByAppAndProperties(applicationName, parameters); + return auditComponent.getAuditEntriesCountByAppAndProperties(parameters); } } \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java b/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java index 8c717898097..d3cdb157b6f 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java +++ b/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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 - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * 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 + * 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 . + * #L% + */ package org.alfresco.repo.domain; @@ -102,21 +102,22 @@ else if (value.length() == 0) { throw new RuntimeException("UTF-8 encoding is not supported"); } - // Get the short value (case-sensitive or not) + // Crc Value will change based on the case-sensitive, So we need to get the short value based on case-sensitive String valueShort = null; - int valueLen = valueLowerCase.length(); + String currentValue = caseSensitive ? value : valueLowerCase; + int valueLen = currentValue.length(); if (valueLen < dataLength) { - valueShort = valueLowerCase; + valueShort = currentValue; } else if (useCharsFromStart) { - valueShort = valueLowerCase.substring(0, dataLength - 1); + valueShort = currentValue.substring(0, dataLength - 1); } else { - valueShort = valueLowerCase.substring(valueLen - dataLength); + valueShort = currentValue.substring(valueLen - dataLength); } return new Pair(valueShort, valueCrc); } -} +} \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java b/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java index f8c61d0a8c1..cac517706ef 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java +++ b/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java @@ -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 @@ -248,11 +248,10 @@ default int getAuditEntriesCountByApp(long applicationId) /** * Issue an audit query to retrieve count of records for a given application and properties * - * @param applicationName name of the application to be queried * @param parameters audit parameters provided by the where clause on the ReST API * @return a map containing min/max and the associated value */ - default int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters) + default int getAuditEntriesCountByAppAndProperties(org.alfresco.service.cmr.audit.AuditQueryParameters parameters) { return -1; } diff --git a/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java b/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java index 89f602dba5a..12468dbf8e0 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java @@ -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 @@ -237,7 +237,7 @@ public int getAuditEntriesCountByApp(long applicationId) } @Override - public int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters) + public int getAuditEntriesCountByAppAndProperties(org.alfresco.service.cmr.audit.AuditQueryParameters parameters) { AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters); diff --git a/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java b/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java index dbc30902980..56e188fbf67 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java +++ b/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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 - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * 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 + * 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 . + * #L% + */ package org.alfresco.repo.domain.propval; import org.alfresco.repo.domain.CrcHelper; @@ -44,6 +44,7 @@ public class PropertyStringValueEntity private String stringValue; private String stringEndLower; private Long stringCrc; + private String stringLower; public PropertyStringValueEntity() { @@ -115,6 +116,9 @@ public void setValue(String value) Pair crcPair = CrcHelper.getStringCrcPair(value, 16, false, true); stringEndLower = crcPair.getFirst(); stringCrc = crcPair.getSecond(); + // Calculate the crc value with case-insensitive + Pair crcPairWithCaseInSensitive = CrcHelper.getStringCrcPair(value, 16, false, false); + stringLower = crcPairWithCaseInSensitive.getFirst(); } public Long getId() @@ -156,4 +160,14 @@ public void setStringCrc(Long stringCrc) { this.stringCrc = stringCrc; } + + public String getStringLower() + { + return stringLower; + } + + public void setStringLower(String stringLower) + { + this.stringLower = stringLower; + } } diff --git a/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java b/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java index 4a7bcd0091c..bbb2f886ac5 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java @@ -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 @@ -256,11 +256,10 @@ default int getAuditEntriesCountByApp(String applicationName) /** * Issue an audit query to retrieve min / max audit record id for a given application and properties * - * @param applicationName the name of the application * @param parameters audit parameters provided by the where clause on the ReST API * @return a map containing min/max and the associated value */ - default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) + default int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) { return -1; }