@Test public void testSetFolderParticipantsFromParentFolderRemovesExistingParticipantFromFolderAndChildren() { String participantLdapId = "userId"; String participantType = "write"; Long folderId = 1L; Long childFolderId = 2L; AcmFolder parentFolder = new AcmFolder(); List<AcmParticipant> folderParticipants = new ArrayList<>(); AcmParticipant folderParticipant = new AcmParticipant(); folderParticipant.setParticipantLdapId(participantLdapId); folderParticipant.setParticipantType(participantType); folderParticipants.add(folderParticipant); AcmFolder folder = new AcmFolder(); folder.setId(folderId); folder.setParticipants(folderParticipants); folder.setParentFolder(parentFolder); List<AcmParticipant> childFolderParticipants = new ArrayList<>(); AcmParticipant childFolderParticipant = new AcmParticipant(); childFolderParticipant.setParticipantLdapId(participantLdapId); childFolderParticipant.setParticipantType(participantType); childFolderParticipants.add(childFolderParticipant); AcmFolder childFolder = new AcmFolder(); childFolder.setId(childFolderId); childFolder.setParticipants(childFolderParticipants); childFolder.setParentFolder(folder); folder.setChildrenFolders(Arrays.asList(childFolder)); List<AcmParticipant> fileParticipants = new ArrayList<>(); AcmParticipant fileParticipant = new AcmParticipant(); fileParticipant.setParticipantLdapId(participantLdapId); fileParticipant.setParticipantType(participantType); fileParticipants.add(fileParticipant); EcmFile file = new EcmFile(); file.setParticipants(fileParticipants); file.setFolder(parentFolder); expect(mockFileDao.findByFolderId(folder.getId(), FlushModeType.COMMIT)).andReturn(Arrays.asList(file)); expect(mockFileDao.findByFolderId(childFolder.getId(), FlushModeType.COMMIT)).andReturn(new ArrayList<>()); expect(mockFileDao.save(file)).andReturn(file); expect(mockFolderDao.findSubFolders(folderId, FlushModeType.COMMIT)).andReturn(Arrays.asList(childFolder)); EntityManager em = mock(EntityManager.class); expect(mockFolderDao.getEm()).andReturn(em).anyTimes(); em.flush(); expectLastCall(); replayAll(); fileParticipantService.setFolderParticipantsFromParentFolder(folder); verifyAll(); assertEquals(0, folder.getParticipants().size()); assertEquals(0, childFolder.getParticipants().size()); assertEquals(0, file.getParticipants().size()); }
@Transactional(rollbackFor = Exception.class) public void setFolderParticipantsFromParentFolder(AcmFolder folder) { if (folder.getParentFolder() == null) { throw new IllegalStateException("Folder doesn't have parent folder!"); } folder.getParentFolder().getParticipants().forEach(participant -> participant.setReplaceChildrenParticipant(true)); setFolderParticipants(folder, folder.getParentFolder().getParticipants(), folder.getRestricted()); folder.setModified(new Date()); }
EcmFileParticipantService { @Transactional(rollbackFor = Exception.class) public void setFolderParticipantsFromParentFolder(AcmFolder folder) { if (folder.getParentFolder() == null) { throw new IllegalStateException("Folder doesn't have parent folder!"); } folder.getParentFolder().getParticipants().forEach(participant -> participant.setReplaceChildrenParticipant(true)); setFolderParticipants(folder, folder.getParentFolder().getParticipants(), folder.getRestricted()); folder.setModified(new Date()); } }
EcmFileParticipantService { @Transactional(rollbackFor = Exception.class) public void setFolderParticipantsFromParentFolder(AcmFolder folder) { if (folder.getParentFolder() == null) { throw new IllegalStateException("Folder doesn't have parent folder!"); } folder.getParentFolder().getParticipants().forEach(participant -> participant.setReplaceChildrenParticipant(true)); setFolderParticipants(folder, folder.getParentFolder().getParticipants(), folder.getRestricted()); folder.setModified(new Date()); }  }
EcmFileParticipantService { @Transactional(rollbackFor = Exception.class) public void setFolderParticipantsFromParentFolder(AcmFolder folder) { if (folder.getParentFolder() == null) { throw new IllegalStateException("Folder doesn't have parent folder!"); } folder.getParentFolder().getParticipants().forEach(participant -> participant.setReplaceChildrenParticipant(true)); setFolderParticipants(folder, folder.getParentFolder().getParticipants(), folder.getRestricted()); folder.setModified(new Date()); }  @Transactional(rollbackFor = Exception.class) EcmFile setFileParticipantsFromParentFolder(EcmFile file); @Transactional(rollbackFor = Exception.class) void setFolderParticipantsFromParentFolder(AcmFolder folder); List<AcmParticipant> getFolderParticipantsFromParentAssignedObject(String objectType, Long objectId); List<AcmParticipant> getFolderParticipantsFromAssignedObject(List<AcmParticipant> assignedObjectParticipants); @Transactional(rollbackFor = Exception.class) void inheritParticipantsFromAssignedObject(List<AcmParticipant> assignedObjectParticipants,
            List<AcmParticipant> originalAssignedObjectParticipants, AcmContainer acmContainer, boolean restricted); @Transactional(rollbackFor = Exception.class) List<AcmParticipant> setFileParticipants(Long objectId, List<AcmParticipant> participants); @Transactional(rollbackFor = Exception.class) List<AcmParticipant> setFolderParticipants(Long objectId, List<AcmParticipant> participants); EcmFileDao getFileDao(); void setFileDao(EcmFileDao fileDao); AcmParticipantService getParticipantService(); void setParticipantService(AcmParticipantService participantService); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); EcmFileParticipantServiceHelper getFileParticipantServiceHelper(); void setFileParticipantServiceHelper(EcmFileParticipantServiceHelper fileParticipantServiceHelper); AcmFolderDao getFolderDao(); void setFolderDao(AcmFolderDao folderDao); EcmFileConfig getEcmFileConfig(); void setEcmFileConfig(EcmFileConfig ecmFileConfig); }
EcmFileParticipantService { @Transactional(rollbackFor = Exception.class) public void setFolderParticipantsFromParentFolder(AcmFolder folder) { if (folder.getParentFolder() == null) { throw new IllegalStateException("Folder doesn't have parent folder!"); } folder.getParentFolder().getParticipants().forEach(participant -> participant.setReplaceChildrenParticipant(true)); setFolderParticipants(folder, folder.getParentFolder().getParticipants(), folder.getRestricted()); folder.setModified(new Date()); }  @Transactional(rollbackFor = Exception.class) EcmFile setFileParticipantsFromParentFolder(EcmFile file); @Transactional(rollbackFor = Exception.class) void setFolderParticipantsFromParentFolder(AcmFolder folder); List<AcmParticipant> getFolderParticipantsFromParentAssignedObject(String objectType, Long objectId); List<AcmParticipant> getFolderParticipantsFromAssignedObject(List<AcmParticipant> assignedObjectParticipants); @Transactional(rollbackFor = Exception.class) void inheritParticipantsFromAssignedObject(List<AcmParticipant> assignedObjectParticipants,
            List<AcmParticipant> originalAssignedObjectParticipants, AcmContainer acmContainer, boolean restricted); @Transactional(rollbackFor = Exception.class) List<AcmParticipant> setFileParticipants(Long objectId, List<AcmParticipant> participants); @Transactional(rollbackFor = Exception.class) List<AcmParticipant> setFolderParticipants(Long objectId, List<AcmParticipant> participants); EcmFileDao getFileDao(); void setFileDao(EcmFileDao fileDao); AcmParticipantService getParticipantService(); void setParticipantService(AcmParticipantService participantService); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); EcmFileParticipantServiceHelper getFileParticipantServiceHelper(); void setFileParticipantServiceHelper(EcmFileParticipantServiceHelper fileParticipantServiceHelper); AcmFolderDao getFolderDao(); void setFolderDao(AcmFolderDao folderDao); EcmFileConfig getEcmFileConfig(); void setEcmFileConfig(EcmFileConfig ecmFileConfig);  }