RM-4619 - convert the folder nodes before setting identifier

This commit is contained in:
Ana Bozianu
2017-02-27 12:41:39 +02:00
parent 53a8c755bb
commit 764b13d473
4 changed files with 70 additions and 17 deletions

View File

@@ -137,7 +137,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
final NodeRef child = childAssocRef.getChildRef();
if (nodeService.exists(child))
{
QName childType = nodeService.getType(child);
QName childType = convertNodeToFileplanComponent(child, nodeService.getType(child), nodeService.getType(childAssocRef.getParentRef()));
// We only care about "folder" or sub-types that are not hidden.
// Some modules use hidden files to store information (see RM-3283)
@@ -205,4 +205,37 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
}
});
}
/**
* Converted the child node to a fileplan component
* The conversion is needed here to be able to generate the identifier
* If there is no conversion rule for the created type nothing happens and the current type is returned
*
* @param child ref to the new child
* @param childType the type of the new child
* @param parentType the type of the parent node
* @return the new type of the child node
*/
protected QName convertNodeToFileplanComponent(final NodeRef child, final QName childType, final QName parentType)
{
if(childType.equals(ContentModel.TYPE_FOLDER))
{
if(parentType.equals(TYPE_FILE_PLAN))
{
nodeService.setType(child, TYPE_RECORD_CATEGORY);
return TYPE_RECORD_CATEGORY;
}
if(parentType.equals(TYPE_RECORD_CATEGORY))
{
nodeService.setType(child, TYPE_RECORD_FOLDER);
return TYPE_RECORD_FOLDER;
}
if(parentType.equals(TYPE_UNFILED_RECORD_CONTAINER) || parentType.equals(TYPE_UNFILED_RECORD_FOLDER))
{
nodeService.setType(child, TYPE_UNFILED_RECORD_FOLDER);
return TYPE_UNFILED_RECORD_FOLDER;
}
}
return childType;
}
}

View File

@@ -76,6 +76,15 @@ public class UnfiledRecordContainerType extends BaseBehaviourBean
@Behaviour(kind = BehaviourKind.ASSOCIATION)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
// 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 folder subtypes to store information (see RM-3283).
QName childType = nodeService.getType(childAssocRef.getChildRef());
if (childType.equals(ContentModel.TYPE_FOLDER))
{
nodeService.setType(childAssocRef.getChildRef(), TYPE_UNFILED_RECORD_FOLDER);
}
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}

View File

@@ -55,6 +55,15 @@ public class UnfiledRecordFolderType extends BaseBehaviourBean
@Behaviour(kind = BehaviourKind.ASSOCIATION)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
// 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 folder subtypes to store information (see RM-3283).
QName childType = nodeService.getType(childAssocRef.getChildRef());
if (childType.equals(ContentModel.TYPE_FOLDER))
{
nodeService.setType(childAssocRef.getChildRef(), TYPE_UNFILED_RECORD_FOLDER);
}
// check the created child is of an accepted type
validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}

View File

@@ -37,6 +37,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -51,16 +52,18 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
private @InjectMocks RecordsManagementContainerType recordManagementContainerType;
/**
* Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN
* Having the Unfilled Record container and a non RM folder subtype node
* When adding a child association between the folder and the container
* Then the new folder should not be altered
*
* Outlook creates a hidden folder subtype to store attachments and we don't want to change the type of those folders
*/
@Test
public void testAddHiddenFolderToRMContainer()
public void testAddNonRMFolderSubtypeToRMContainer()
{
/* Having a RM container and a folder with ASPECT_HIDDEN applied */
/* Having a RM container and a non RM folder subtype node */
NodeRef rmContainer = generateRMContainer();
NodeRef rmFolder = generateFolderNode(true);
NodeRef rmFolder = generateNonRmFolderSubtypeNode();
/*
* When adding a child association between the folder and the container
@@ -86,22 +89,21 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
}
/**
* Generates a folder node
* @param hasHiddenAspect does the folder node have the aspect ASPECT_HIDDEN
* Generates a folder subtype node
* @return reference to the created folder
*/
private NodeRef generateFolderNode(boolean hasHiddenAspect)
private NodeRef generateNonRmFolderSubtypeNode()
{
NodeRef rmFolder = generateNodeRef();
when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false);
when(mockedNodeService.getType(rmFolder)).thenReturn(ContentModel.TYPE_FOLDER);
when(mockedNodeService.exists(rmFolder)).thenReturn(true);
when(mockedNodeService.hasAspect(rmFolder, ContentModel.ASPECT_HIDDEN)).thenReturn(hasHiddenAspect);
when(mockedNodeService.hasAspect(rmFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false);
return rmFolder;
NodeRef folder = generateNodeRef();
QName folderSubtype = QName.createQName("test", "folderSubtype");
when(mockedDictionaryService.isSubClass(folderSubtype, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(folderSubtype, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false);
when(mockedNodeService.getType(folder)).thenReturn(folderSubtype);
when(mockedNodeService.exists(folder)).thenReturn(true);
when(mockedNodeService.hasAspect(folder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false);
return folder;
}
/**
* Generates a folder node
* @return reference to the created folder