WorkspaceServiceImpl implements WorkspaceService { @Override @Transactional(readOnly = false) public Process copyProcessVersions(Integer processId, List<String> pmvVersions, Integer newFolderId, String userName, boolean isPublic) throws Exception { Folder newFolder = folderRepo.findUniqueByID(newFolderId); User newUser = userRepo.findByUsername(userName); Process process = processRepo.findUniqueByID(processId); Process newProcess = process.clone(); ProcessBranch branch = process.getProcessBranches().get(0); ProcessBranch newBranch = branch.clone(); List<ProcessModelVersion> newPMVList = this.createNewPMVs(process.getId(), pmvVersions, branch, newBranch); if (newPMVList.isEmpty()) { throw new Exception("No process model versions were found for processId=" + process.getId() + "and versions=" + pmvVersions.toString()); } newBranch.setProcess(newProcess); newBranch.setProcessModelVersions(newPMVList); newBranch.setCurrentProcessModelVersion(newPMVList.get(newPMVList.size()-1)); newProcess.getProcessBranches().clear(); newProcess.setProcessBranches(Arrays.asList(new ProcessBranch[] {newBranch})); newProcess.setUser(newUser); newProcess.setFolder(newFolder); Set<GroupProcess> groupProcesses = newProcess.getGroupProcesses(); groupProcesses.clear(); groupProcesses.add(new GroupProcess(newProcess, newUser.getGroup(), true, true, true)); if (isPublic) { Group publicGroup = groupRepo.findPublicGroup(); if (publicGroup == null) { LOGGER.warn("No public group present in repository"); } else { groupProcesses.add(new GroupProcess(newProcess, publicGroup, true, true, false)); } } newProcess.setGroupProcesses(groupProcesses); processRepo.save(newProcess); for (ProcessModelVersion pmv : newPMVList) { pmvRepo.save(pmv); } return newProcess; } @Inject  WorkspaceServiceImpl(final WorkspaceRepository workspaceRepository,
                                final UserRepository userRepository,
                                final ProcessRepository processRepository,
                                final ProcessModelVersionRepository pmvRepository,
                                final LogRepository logRepository,
                                final FolderRepository folderRepository,
                                final GroupRepository groupRepository,
                                final GroupFolderRepository groupFolderRepository,
                                final GroupProcessRepository groupProcessRepository,
                                final GroupLogRepository groupLogRepository,
                                final EventLogFileService eventLogFileService); @Override Folder getFolder(Integer folderId); @Override List<GroupFolder> getGroupFolders(Integer folderId); @Override List<GroupProcess> getGroupProcesses(Integer processId); @Override List<GroupLog> getGroupLogs(Integer logId); @Override List<GroupProcess> getGroupProcesses(String userId, Integer folderId); @Override Page<Process> getProcesses(String userId, Integer folderId, Pageable pageable); @Override Page<Log> getLogs(String userId, Integer folderId, Pageable pageable); @Override @Transactional(readOnly = false) void createFolder(String userId, String folderName, Integer parentFolderId, Boolean isGEDMatrixReady); @Override boolean isGEDReadyFolder(Integer folderId); @Override void updateFolder(Integer folderId, String folderName, Boolean isGEDMatrixReady, User user); @Override @Transactional(readOnly = false) void deleteFolder(Integer folderId, User user); @Override List<FolderTreeNode> getWorkspaceFolderTree(String userId); @Override List<Folder> getBreadcrumbs(Integer folderId); @Override List<GroupFolder> getSubFolders(String userRowGuid, Integer folderId); @Override @Transactional(readOnly = false) String saveFolderPermissions(Integer folderId, String groupRowGuid, boolean hasRead, boolean hasWrite, boolean hasOwnership); @Override @Transactional(readOnly = false) String removeFolderPermissions(Integer folderId, String groupRowGuid); @Override @Transactional(readOnly = false) String removeProcessPermissions(Integer processId, String groupRowGuid); @Override @Transactional(readOnly = false) String removeLogPermissions(Integer logId, String groupRowGuid); @Override @Transactional(readOnly = false) String saveProcessPermissions(Integer processId, String groupRowGuid, boolean hasRead, boolean hasWrite, boolean hasOwnership); @Override @Transactional(readOnly = false) String saveLogPermissions(Integer logId, String groupRowGuid, boolean hasRead, boolean hasWrite, boolean hasOwnership); @Override @Transactional(readOnly = false) void addProcessToFolder(Integer processId, Integer folderId); @Override @Transactional(readOnly = false) void createPublicStatusForUsers(final Process process); @Override @Transactional(readOnly = false) void removePublicStatusForUsers(final Process process); @Override @Transactional(readOnly = false) Log copyLog(Integer logId, Integer newFolderId, String userName, boolean isPublic); @Override @Transactional(readOnly = false) Log moveLog(Integer logId, Integer newFolderId); @Override @Transactional(readOnly = false) Process copyProcessVersions(Integer processId, List<String> pmvVersions, Integer newFolderId, String userName, boolean isPublic); @Override @Transactional(readOnly = false) Process copyProcess(Integer processId, Integer newFolderId, String userName, boolean isPublic); @Override @Transactional(readOnly = false) Process moveProcess(Integer processId, Integer newFolderId); @Override Folder copyFolder(Integer folderId, Integer sourceFolderId, Integer targetFolderId); @Override Folder moveFolder(Integer folderId, Integer newParentFolderId);  }
@Test public void testCopyProcessVersions() throws Exception { Group group = createGroup(123, Group.Type.GROUP); Role role = createRole(createSet(createPermission())); User user = createUser("userName1", group, createSet(group), createSet(role)); NativeType nativeType = createNativeType(); Native nativeDoc = createNative(nativeType, TestData.XPDL); Workspace wp = createWorkspace(user); Folder targetFolder = createFolder("targetFolder", null, wp); Folder sourceFolder = createFolder("sourceFolder", null, wp); Process process = createProcess(user, nativeType, sourceFolder); ProcessBranch branch = createBranch(process); ProcessModelVersion pmv1 = createPMV(branch, nativeDoc, createVersion("1.0")); ProcessModelVersion pmv2 = createPMV(branch, nativeDoc, createVersion("1.1")); ProcessModelVersion pmv3 = createPMV(branch, nativeDoc, createVersion("1.2")); branch.getProcessModelVersions().addAll(Arrays.asList(new ProcessModelVersion[] {pmv1, pmv2, pmv3})); branch.setCurrentProcessModelVersion(pmv2); process.getProcessBranches().add(branch); Integer processId = process.getId(); Integer targetFolderId = targetFolder.getId(); String userName = user.getUsername(); List<String> pmvVersions = Arrays.asList(new String[] {pmv1.getVersionNumber(), pmv2.getVersionNumber()}); boolean madePublic = false; expect(folderRepo.findUniqueByID(targetFolderId)).andReturn(targetFolder); expect(userRepo.findByUsername(userName)).andReturn(user); expect(processRepo.findUniqueByID(processId)).andReturn(process); expect(processRepo.save((Process)EasyMock.anyObject())).andReturn(null); expect(pmvRepo.save((ProcessModelVersion)EasyMock.anyObject())).andReturn(null).anyTimes(); replayAll(); Process copyProcess = workspaceService.copyProcessVersions(processId, pmvVersions, targetFolderId, userName, madePublic); verifyAll(); Assert.assertEquals(targetFolder, copyProcess.getFolder()); Assert.assertEquals(user, copyProcess.getUser()); Assert.assertEquals(process.getName(), copyProcess.getName()); Assert.assertEquals(1, copyProcess.getProcessBranches().size()); Assert.assertEquals(process.getProcessBranches().get(0).getBranchName(), copyProcess.getProcessBranches().get(0).getBranchName()); Assert.assertEquals(copyProcess, copyProcess.getProcessBranches().get(0).getProcess()); Assert.assertEquals(2, copyProcess.getProcessBranches().get(0).getProcessModelVersions().size()); Assert.assertEquals("1.0", copyProcess.getProcessBranches().get(0).getProcessModelVersions().get(0).getVersionNumber()); Assert.assertEquals("1.1", copyProcess.getProcessBranches().get(0).getProcessModelVersions().get(1).getVersionNumber()); Assert.assertEquals("1.1", copyProcess.getProcessBranches().get(0).getCurrentProcessModelVersion().getVersionNumber()); Assert.assertEquals(pmv1.getNativeDocument().getContent(), copyProcess.getProcessBranches().get(0).getProcessModelVersions().get(0).getNativeDocument().getContent()); Assert.assertEquals(pmv2.getNativeDocument().getContent(), copyProcess.getProcessBranches().get(0).getProcessModelVersions().get(1).getNativeDocument().getContent()); Assert.assertEquals(copyProcess.getProcessBranches().get(0), copyProcess.getProcessBranches().get(0).getProcessModelVersions().get(0).getProcessBranch()); Assert.assertEquals(copyProcess.getProcessBranches().get(0), copyProcess.getProcessBranches().get(0).getProcessModelVersions().get(1).getProcessBranch()); Assert.assertEquals(user.getGroup(), copyProcess.getGroupProcesses().iterator().next().getGroup()); }