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 bd0e710238..981041b69d 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 @@ -18,5 +18,15 @@ - + + + + + + + + + \ No newline at end of file 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 67bd9c2e9c..c5306db76e 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=3200 +version.rm.schema=3201 diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldReportUpdatePatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldReportUpdatePatch.java new file mode 100644 index 0000000000..7b93d2ac5c --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldReportUpdatePatch.java @@ -0,0 +1,134 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.v32; + +import java.io.InputStream; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch; +import org.alfresco.repo.version.VersionModel; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.version.Version; +import org.alfresco.service.cmr.version.VersionService; +import org.alfresco.service.cmr.version.VersionType; + +/** + * Patch to update the template for generating the hold report + * See: https://issues.alfresco.com/jira/browse/RM-7003 + * + * @author Ramona Popa + * @since 3.2 + */ +public class RMv32HoldReportUpdatePatch extends AbstractModulePatch +{ + /** + * Hold report template path + */ + private static final String HOLD_REPORT_TEMPLATE_PATH = "alfresco/module/org_alfresco_module_rm/bootstrap/report/report_rmr_holdReport.html.ftl"; + + /** + * Hold report template config node IDs + */ + private static final NodeRef HOLD_REPORT = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rmr_holdReport"); + + /** + * Node service + */ + private NodeService nodeService; + + /** + * Content service + */ + private ContentService contentService; + + /** + * Version service + */ + private VersionService versionService; + + /** + * @param nodeService node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * @param contentService content service + */ + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + + /** + * @param versionService version service + */ + public void setVersionService(VersionService versionService) + { + this.versionService = versionService; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal() + */ + @Override + public void applyInternal() + { + if (nodeService.exists(HOLD_REPORT)) + { + + // Make sure the template is versionable + if (!nodeService.hasAspect(HOLD_REPORT, ContentModel.ASPECT_VERSIONABLE)) + { + nodeService.addAspect(HOLD_REPORT, ContentModel.ASPECT_VERSIONABLE, null); + + // Create version (before template is updated) + Map versionProperties = new HashMap<>(2); + versionProperties.put(Version.PROP_DESCRIPTION, "Template updated"); + versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR); + versionService.createVersion(HOLD_REPORT, versionProperties); + } + + // Update the content of the template + InputStream is = getClass().getClassLoader().getResourceAsStream(HOLD_REPORT_TEMPLATE_PATH); + ContentWriter writer = contentService.getWriter(HOLD_REPORT, ContentModel.PROP_CONTENT, true); + writer.putContent(is); + + } + } + +} \ No newline at end of file diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldReportUpdatePatchUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldReportUpdatePatchUnitTest.java new file mode 100644 index 0000000000..8306204e5e --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldReportUpdatePatchUnitTest.java @@ -0,0 +1,100 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.v32; + +import static org.mockito.Matchers.anyMap; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.InputStream; + +import org.alfresco.model.ContentModel; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.version.VersionService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * RM V3.2 Hold report update patch unit test + * + * @author Ramona Popa + * @since 3.2 + */ +public class RMv32HoldReportUpdatePatchUnitTest +{ + @Mock + private NodeService mockedNodeService; + + @Mock + private ContentService mockedContentService; + + @Mock + private VersionService mockedVersionService; + + @Mock + private ContentWriter mockedContentWriter; + + @InjectMocks + private RMv32HoldReportUpdatePatch patch; + + private NodeRef hold_report; + + @Before + public void setUp() + { + MockitoAnnotations.initMocks(this); + hold_report = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rmr_holdReport"); + } + + /** + * Test report content is updated after the patch is executed + */ + @Test + public void testReportContentIsUpdatedAfterUpgrade() + { + when(mockedNodeService.exists(hold_report)).thenReturn(true); + when(mockedNodeService.hasAspect(hold_report, ContentModel.ASPECT_VERSIONABLE)).thenReturn(false); + when(mockedContentService.getWriter(hold_report, ContentModel.PROP_CONTENT, true)).thenReturn(mockedContentWriter); + + patch.applyInternal(); + verify(mockedNodeService, times(1)).addAspect(hold_report, ContentModel.ASPECT_VERSIONABLE, null); + verify(mockedVersionService, times(1)).createVersion((NodeRef) anyObject(), anyMap()); + verify(mockedContentWriter, times(1)).putContent((InputStream) anyObject()); + } +} + +