From a3574f7f2bb7e820febf6b9b9f1b71c8cdfd3e61 Mon Sep 17 00:00:00 2001 From: Ramona Popa Date: Fri, 10 Jan 2020 09:23:06 +0000 Subject: [PATCH] RM-7098: [Upgrade] Add to Hold and Remove from hold audit events are not properly migrated --- .../patch/rm-patch-v32-context.xml | 2 +- .../patch/rm-patch-v33-context.xml | 19 ++++ .../query/rm-common-SqlMap.xml | 23 +++++ .../org_alfresco_module_rm/version.properties | 2 +- .../v33/RMv33HoldAuditEntryValuesPatch.java | 74 ++++++++++++++ .../query/RecordsManagementQueryDAO.java | 14 ++- .../query/RecordsManagementQueryDAOImpl.java | 24 ++++- ...Mv33HoldAuditEntryValuesPatchUnitTest.java | 98 +++++++++++++++++++ 8 files changed, 251 insertions(+), 5 deletions(-) create mode 100644 rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v33-context.xml create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatch.java create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml index 93d1f5580f..ddf1e762cb 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml @@ -19,7 +19,7 @@ - diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v33-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v33-context.xml new file mode 100644 index 0000000000..2ceccd64c1 --- /dev/null +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v33-context.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml index 766842f0a8..f537ba54d6 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml @@ -83,5 +83,28 @@ and alfn.id between ? and ? + + + + + + update alf_prop_string_value + set string_value = #{stringValue}, + string_end_lower = #{stringEndLower}, + string_crc = #{stringCrc} + where id = #{id} + diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties index c5306db76e..6830ad62fe 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties @@ -1,3 +1,3 @@ # RM Schema number -version.rm.schema=3201 +version.rm.schema=3300 diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatch.java new file mode 100644 index 0000000000..03e2f64c87 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatch.java @@ -0,0 +1,74 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2020 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.module.org_alfresco_module_rm.patch.v33; + +import org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch; +import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO; +import org.alfresco.repo.domain.propval.PropertyStringValueEntity; + +/** + * Patch to update values for addToHold and removeFromHold event types + *

+ * See: https://issues.alfresco.com/jira/browse/RM-7098 + * + * @author Ramona Popa + * @since 3.3 + */ +public class RMv33HoldAuditEntryValuesPatch extends AbstractModulePatch +{ + + /** + * Services + */ + private RecordsManagementQueryDAO recordsManagementQueryDAO; + + public void setRecordsManagementQueryDAO(RecordsManagementQueryDAO recordsManagementQueryDAO) + { + this.recordsManagementQueryDAO = recordsManagementQueryDAO; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal() + * + * Updates the property string value entities for addToHold and removeFromHold audit event types + */ + @Override + public void applyInternal() + { + updatePropertyStringValueEntity("addToHold", "Add To Hold"); + updatePropertyStringValueEntity("removeFromHold", "Remove From Hold"); + + } + + private void updatePropertyStringValueEntity(String fromStringValue, String toStringValue) + { + PropertyStringValueEntity addToAuditPropertyStringValueEntity = recordsManagementQueryDAO.getPropertyStringValueEntity(fromStringValue); + addToAuditPropertyStringValueEntity.setValue(toStringValue); + recordsManagementQueryDAO.updatePropertyStringValueEntity(addToAuditPropertyStringValueEntity); + } + +} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java index 3507da8c7f..6484cc74fe 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java @@ -30,8 +30,8 @@ package org.alfresco.module.org_alfresco_module_rm.query; import java.util.List; import java.util.Set; +import org.alfresco.repo.domain.propval.PropertyStringValueEntity; import org.alfresco.service.cmr.repository.NodeRef; -import java.util.Collection; import org.alfresco.service.namespace.QName; @@ -80,4 +80,16 @@ public interface RecordsManagementQueryDAO * @return Set a set of nodes that reference the given content url */ Set getNodeRefsWhichReferenceContentUrl(String contentUrl); + + /** + * Get the property string value entity with the specified string value + * @return PropertyStringValueEntity the property string value entity with the specified string value + */ + PropertyStringValueEntity getPropertyStringValueEntity(String stringValue); + + /** + * Update the property string value entity + * @return int the number of rows updated + */ + int updatePropertyStringValueEntity(PropertyStringValueEntity propertyStringValueEntity); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java index 40875e1f19..ae54278481 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java @@ -29,9 +29,8 @@ package org.alfresco.module.org_alfresco_module_rm.query; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -40,6 +39,7 @@ import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.repo.domain.contentdata.ContentUrlEntity; import org.alfresco.repo.domain.node.NodeDAO; +import org.alfresco.repo.domain.propval.PropertyStringValueEntity; import org.alfresco.repo.domain.qname.QNameDAO; import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.version.Version2Model; @@ -73,6 +73,8 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO, private static final String SELECT_NODE_IDS_WHICH_REFERENCE_CONTENT_URL = "select_NodeIdsWhichReferenceContentUrl"; private static final String SCHEDULED_FOLDERS = "alfresco.query.rm.select_RecordFoldersWithSchedules"; private static final String SCHEDULED_FOLDERS_COUNT = "alfresco.query.rm.select_RecordFoldersWithSchedulesCount"; + private static final String GET_PROP_STRING_VALUE = "alfresco.query.rm.select_PropertyStringValue"; + private static final String UPDATE_PROP_STRING_VALUE = "alfresco.query.rm.update_PropertyStringValue"; /** * SQL session template @@ -284,4 +286,22 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO, return results; } + /** + * @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getPropertyStringValueEntity(String stringValue) + */ + public PropertyStringValueEntity getPropertyStringValueEntity(String stringValue){ + + PropertyStringValueEntity propertyStringValueEntity = new PropertyStringValueEntity(); + propertyStringValueEntity.setValue(stringValue); + + return template.selectOne(GET_PROP_STRING_VALUE, propertyStringValueEntity); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#updatePropertyStringValueEntity(PropertyStringValueEntity propertyStringValueEntity) + */ + public int updatePropertyStringValueEntity(PropertyStringValueEntity propertyStringValueEntity) + { + return template.update(UPDATE_PROP_STRING_VALUE, propertyStringValueEntity); + } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java new file mode 100644 index 0000000000..c742f78726 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java @@ -0,0 +1,98 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2020 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.module.org_alfresco_module_rm.patch.v33; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.times; +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; + +/** + * RM V3.3 Hold audit entries values patch unit test + * + * @author Ramona Popa + * @since 3.3 + */ +public class RMv33HoldAuditEntryValuesPatchUnitTest +{ + @Mock + private RecordsManagementQueryDAO mockedRecordsManagementQueryDAO; + + @InjectMocks + private RMv33HoldAuditEntryValuesPatch patch; + + + @Before + public void setUp() + { + MockitoAnnotations.initMocks(this); + } + + /** + * addtohold and removeFromHold audit entries values are updated after the patch is executed + */ + @Test + public void holdAuditEntriesAreUpdatedAfterUpgrade() + { + PropertyStringValueEntity addToHoldPropertyStringValueEntity = new PropertyStringValueEntity(); + addToHoldPropertyStringValueEntity.setValue("addToHold"); + when(mockedRecordsManagementQueryDAO.getPropertyStringValueEntity("addToHold")).thenReturn(addToHoldPropertyStringValueEntity); + when(mockedRecordsManagementQueryDAO.updatePropertyStringValueEntity(addToHoldPropertyStringValueEntity)).thenReturn(1); + + PropertyStringValueEntity removeFromHoldPropertyStringValueEntity = new PropertyStringValueEntity(); + removeFromHoldPropertyStringValueEntity.setValue("removeFromHold"); + when(mockedRecordsManagementQueryDAO.getPropertyStringValueEntity("removeFromHold")).thenReturn(removeFromHoldPropertyStringValueEntity); + when(mockedRecordsManagementQueryDAO.updatePropertyStringValueEntity(removeFromHoldPropertyStringValueEntity)).thenReturn(1); + + patch.applyInternal(); + + verify(mockedRecordsManagementQueryDAO, times(1)).getPropertyStringValueEntity("addToHold"); + verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(addToHoldPropertyStringValueEntity); + verify(mockedRecordsManagementQueryDAO, times(1)).getPropertyStringValueEntity("removeFromHold"); + verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(removeFromHoldPropertyStringValueEntity); + + assertEquals("Add To Hold", addToHoldPropertyStringValueEntity.getStringValue()); + 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.getStringEndLower()); + assertEquals(Long.valueOf(2_967_613_012L), removeFromHoldPropertyStringValueEntity.getStringCrc()); + } + +} + +