Merge branch 'feature/RM-4619_AutoConvertFoldersToRMType' into 'master'

Feature/rm 4619 auto convert folders to rm type

See merge request !33
This commit is contained in:
Ana Bozianu
2017-02-07 14:49:20 +00:00
8 changed files with 118 additions and 89 deletions

View File

@@ -32,7 +32,6 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
@@ -146,7 +145,6 @@ public interface TestData
{ UNFILED_RECORD_FOLDER_TYPE }, { UNFILED_RECORD_FOLDER_TYPE },
{ HOLD_TYPE }, { HOLD_TYPE },
{ TRANSFER_TYPE }, { TRANSFER_TYPE },
{ FOLDER_TYPE },
{ CONTENT_TYPE } { CONTENT_TYPE }
}; };
} }

View File

@@ -30,6 +30,7 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -213,6 +214,14 @@ public class FilePlanType extends BaseBehaviourBean
@Override @Override
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{ {
// We need to automatically cast the created folder to category if it is a plain folder
// This occurs if the RM folder has been created via IMap, WebDav, etc. Don't check subtypes.
// Some modules use hidden files to store information (see RM-3283)
if (nodeService.getType(childAssocRef.getChildRef()).equals(ContentModel.TYPE_FOLDER))
{
nodeService.setType(childAssocRef.getChildRef(), TYPE_RECORD_CATEGORY);
}
// check the created child is of an accepted type // check the created child is of an accepted type
validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
} }

View File

@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService; import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService;
@@ -111,13 +112,22 @@ public class RecordCategoryType extends BaseBehaviourBean
) )
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{ {
NodeRef nodeRef = childAssocRef.getChildRef(); QName childType = nodeService.getType(childAssocRef.getChildRef());
NodeRef parentRef = childAssocRef.getParentRef();
validateNewChildAssociation(parentRef, nodeRef, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); // We need to automatically cast the created folder to record folder if it is a plain folder
// This occurs if the RM folder has been created via IMap, WebDav, etc. Don't check subtypes.
// Some modules use hidden folders to store information (see RM-3283).
if (childType.equals(ContentModel.TYPE_FOLDER))
{
nodeService.setType(childAssocRef.getChildRef(), TYPE_RECORD_FOLDER);
}
validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
if (bNew) if (bNew)
{ {
// setup the record folder // setup the record folder
recordFolderService.setupRecordFolder(nodeRef); recordFolderService.setupRecordFolder(childAssocRef.getChildRef());
} }
} }
@@ -132,9 +142,9 @@ public class RecordCategoryType extends BaseBehaviourBean
policy = "alf:onCreateChildAssociation", policy = "alf:onCreateChildAssociation",
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
) )
public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, final boolean bNew)
{ {
final NodeRef recordCategory = childAssocRef.getChildRef(); final NodeRef child = childAssocRef.getChildRef();
behaviourFilter.disableBehaviour(); behaviourFilter.disableBehaviour();
try try
@@ -145,7 +155,7 @@ public class RecordCategoryType extends BaseBehaviourBean
public Void doWork() public Void doWork()
{ {
// setup vital record definition // setup vital record definition
vitalRecordService.setupVitalRecordDefinition(recordCategory); vitalRecordService.setupVitalRecordDefinition(child);
return null; return null;
} }

View File

@@ -27,7 +27,6 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type; package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -44,7 +43,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.I18NUtil;
/** /**
* rma:recordsManagementContainer behaviour bean. * rma:recordsManagementContainer behaviour bean.
@@ -152,32 +150,6 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
} }
else else
{ {
// We need to automatically cast the created folder to RM type if it is a plain folder
// This occurs if the RM folder has been created via IMap, WebDav, etc
if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT))
{
// Throw exception if the type is not cm:folder
if (!ContentModel.TYPE_FOLDER.equals(childType))
{
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CANNOT_CAST_TO_RM_TYPE));
}
// check the type of the parent to determine what 'kind' of artifact to create
NodeRef parent = childAssocRef.getParentRef();
QName parentType = nodeService.getType(parent);
if (dictionaryService.isSubClass(parentType, TYPE_FILE_PLAN))
{
// create a rma:recordCategoty since we are in the root of the file plan
nodeService.setType(child, TYPE_RECORD_CATEGORY);
}
else
{
// create a rma:recordFolder and initialise record folder
nodeService.setType(child, TYPE_RECORD_FOLDER);
recordFolderService.setupRecordFolder(child);
}
}
// Catch all to generate the rm id (assuming it doesn't already have one!) // Catch all to generate the rm id (assuming it doesn't already have one!)
setIdenifierProperty(child); setIdenifierProperty(child);
} }

View File

@@ -0,0 +1,84 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.model.FileInfo;
import org.springframework.extensions.webscripts.GUID;
/**
* Unit test for RM-4619
*
* When creating regular folders through clients that are not RM aware
* the folders must be converted to the appropriate RM container
*
* @author Ana Bozianu
* @since 2.6
*/
public class RM4619Test extends BaseRMTestCase
{
/**
* Given the RM site is created
* When we create a regular folder in the fileplan
* Then the folder is immediately converted to a record category
*/
public void testConvertFolderToCategory() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER);
assertEquals(info.getType(), TYPE_RECORD_CATEGORY);
return null;
}
}, ADMIN_USER);
}
/**
* Given an existing category
* When we create a regular folder in the category
* Then the folder is immediately converted to a record folder
*/
public void testConvertFolderToRecordFolder() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER);
assertEquals(info.getType(), TYPE_RECORD_FOLDER);
return null;
}
}, ADMIN_USER);
}
}

View File

@@ -27,11 +27,13 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type; package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.Arrays; import java.util.Arrays;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;

View File

@@ -27,6 +27,7 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type; package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock; import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;

View File

@@ -26,13 +26,11 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.model.rma.type; package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
@@ -52,33 +50,10 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
/** test object */ /** test object */
private @InjectMocks RecordsManagementContainerType recordManagementContainerType; private @InjectMocks RecordsManagementContainerType recordManagementContainerType;
/**
* Having the Unfilled Record container and a folder
* When adding a child association between the folder and the container
* Then the folder type shouldn't be renamed
*/
@Test
public void testAddFolderToRMContainer()
{
/* Having a RM container and a folder */
NodeRef rmContainer = generateRMContainer();
NodeRef rmFolder = generateFolderNode(false);
/*
* When adding a child association between the folder and the container
*/
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
/* Then the node type should not be changed to TYPE_RECORD_FOLDER */
verify(mockedNodeService).setType(rmFolder, TYPE_RECORD_FOLDER);
verify(mockedRecordFolderService).setupRecordFolder(rmFolder);
}
/** /**
* Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN * Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN
* When adding a child association between the folder and the container * When adding a child association between the folder and the container
* Then the folder type shouldn't be renamed * Then the new folder should not be altered
*/ */
@Test @Test
public void testAddHiddenFolderToRMContainer() public void testAddHiddenFolderToRMContainer()
@@ -93,31 +68,9 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder); ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true); recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
/* Then the node type should not be changed to TYPE_RECORD_FOLDER */ /* The type should not be changed and no aspects should be added */
verify(mockedNodeService, never()).setType(rmFolder, TYPE_RECORD_FOLDER); verify(mockedNodeService, never()).setType(any(), any());
verify(mockedRecordFolderService, never()).setupRecordFolder(rmFolder); verify(mockedNodeService, never()).addAspect(any(), any(), any());
}
/**
* Trying to create a RM folder and its sub-types via SFDC, IMap, WebDav, etc
* Check that exception is thrown on creating child associations
*/
@Test
public void testRM3450()
{
NodeRef rmContainer = generateRMContainer();
NodeRef nonRmFolder = generateNonRmFolderNode();
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, TestModel.NOT_RM_FOLDER_TYPE, nonRmFolder);
try
{
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
fail("Expected to throw exception on create child association.");
}
catch (Throwable e)
{
assertTrue(e instanceof AlfrescoRuntimeException);
}
} }
/** /**