mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-6873 code review changes
This commit is contained in:
@@ -192,30 +192,25 @@ public class FrozenAspect extends BaseBehaviourBean
|
||||
)
|
||||
public void onRemoveAspect(final NodeRef nodeRef, QName aspectTypeQName)
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
|
||||
if (nodeService.exists(nodeRef) &&
|
||||
(isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT)))
|
||||
{
|
||||
if (nodeService.exists(nodeRef) &&
|
||||
(isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT)))
|
||||
// get the owning folder
|
||||
NodeRef owningFolder = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||
|
||||
// check that the aspect has been added
|
||||
if (nodeService.hasAspect(owningFolder, ASPECT_HELD_CHILDREN))
|
||||
{
|
||||
// get the owning folder
|
||||
NodeRef owningFolder = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||
|
||||
// check that the aspect has been added
|
||||
if (nodeService.hasAspect(owningFolder, ASPECT_HELD_CHILDREN))
|
||||
// decrement current count
|
||||
int currentCount = (Integer) nodeService.getProperty(owningFolder, PROP_HELD_CHILDREN_COUNT);
|
||||
if (currentCount > 0)
|
||||
{
|
||||
// decrement current count
|
||||
int currentCount = (Integer)nodeService.getProperty(owningFolder, PROP_HELD_CHILDREN_COUNT);
|
||||
if (currentCount > 0)
|
||||
{
|
||||
nodeService.setProperty(owningFolder, PROP_HELD_CHILDREN_COUNT, currentCount - 1 );
|
||||
}
|
||||
}
|
||||
nodeService.setProperty(owningFolder, PROP_HELD_CHILDREN_COUNT, currentCount - 1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -109,7 +109,6 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
||||
{
|
||||
private NodeRef hold;
|
||||
private NodeRef hold2;
|
||||
Integer before;
|
||||
|
||||
public void given()
|
||||
{
|
||||
@@ -121,7 +120,6 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
||||
|
||||
public void when()
|
||||
{
|
||||
before = (Integer) nodeService.getProperty(dmFolder, PROP_HELD_CHILDREN_COUNT);
|
||||
holdService.removeFromHold(hold, dmDocument);
|
||||
}
|
||||
|
||||
@@ -139,7 +137,7 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
||||
* When I try to remove the active content to the hold without permission
|
||||
* Then an access denied exception is thrown
|
||||
*/
|
||||
public void testRemoveDocumentFromHoldFailsWithoutPermission()
|
||||
public void testRemoveDocumentFromHoldFailsWithoutFilingPermission()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AccessDeniedException.class)
|
||||
{
|
||||
@@ -157,7 +155,7 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
||||
(RunAsWork<Void>) () -> {
|
||||
holdService.removeFromHold(hold, dmDocument);
|
||||
return null;
|
||||
}, recordsManagerName );
|
||||
}, recordsManagerName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -53,16 +53,16 @@ import org.springframework.context.ApplicationContext;
|
||||
public class FrozenAspectUnitTest
|
||||
{
|
||||
@Mock
|
||||
private NodeService nodeService;
|
||||
private NodeService mockNodeService;
|
||||
|
||||
@Mock
|
||||
private ApplicationContext applicationContext;
|
||||
private ApplicationContext mockApplicationContext;
|
||||
|
||||
@Mock
|
||||
private ChildAssociationRef childAssociationRef;
|
||||
private ChildAssociationRef mockChildAssociationRef;
|
||||
|
||||
@Mock
|
||||
private DictionaryService dictionaryService;
|
||||
private DictionaryService mockDictionaryService;
|
||||
|
||||
@InjectMocks
|
||||
private FrozenAspect frozenAspect;
|
||||
@@ -75,13 +75,11 @@ public class FrozenAspectUnitTest
|
||||
public void setUp()
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(nodeService.exists(record)).thenReturn(true);
|
||||
when(nodeService.exists(content)).thenReturn(true);
|
||||
when(nodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
||||
when(nodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
||||
when(applicationContext.getBean("dbNodeService")).thenReturn(nodeService);
|
||||
when(nodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
||||
when(nodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
||||
when(mockNodeService.exists(record)).thenReturn(true);
|
||||
when(mockNodeService.exists(content)).thenReturn(true);
|
||||
when(mockNodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
||||
when(mockNodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
||||
when(mockApplicationContext.getBean("dbNodeService")).thenReturn(mockNodeService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,11 +88,11 @@ public class FrozenAspectUnitTest
|
||||
@Test
|
||||
public void testRemoveAspectForRecords()
|
||||
{
|
||||
when(nodeService.hasAspect(record, ASPECT_RECORD)).thenReturn(true);
|
||||
when(nodeService.getPrimaryParent(record)).thenReturn(childAssociationRef);
|
||||
when(childAssociationRef.getParentRef()).thenReturn(folder);
|
||||
when(mockNodeService.hasAspect(record, ASPECT_RECORD)).thenReturn(true);
|
||||
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockChildAssociationRef);
|
||||
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
|
||||
frozenAspect.onRemoveAspect(record, null);
|
||||
verify(nodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||
verify(mockNodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,12 +101,12 @@ public class FrozenAspectUnitTest
|
||||
@Test
|
||||
public void testRemoveAspectForContent()
|
||||
{
|
||||
when(nodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||
when(nodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT);
|
||||
when(nodeService.getPrimaryParent(content)).thenReturn(childAssociationRef);
|
||||
when(childAssociationRef.getParentRef()).thenReturn(folder);
|
||||
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT);
|
||||
when(mockNodeService.getPrimaryParent(content)).thenReturn(mockChildAssociationRef);
|
||||
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
|
||||
frozenAspect.onRemoveAspect(content, null);
|
||||
verify(nodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||
verify(mockNodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,10 +115,10 @@ public class FrozenAspectUnitTest
|
||||
@Test
|
||||
public void testRemoveAspectForContentDoesntUpdateForOtherTypes()
|
||||
{
|
||||
when(nodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||
when(nodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
|
||||
when(dictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
|
||||
when(mockDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||
frozenAspect.onRemoveAspect(content, null);
|
||||
verify(nodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||
verify(mockNodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user