@Test public void onEcmFileMoved_ifSourceFolderIsArkcaseFolder_And_TargetFolderIsArkcaseFolder_moveFile() throws Exception { AcmFolder sourceParentFolder = new AcmFolder(); sourceParentFolder.setId(400L); sourceParentFolder.setCmisFolderId("sourceParentFolderNodeId"); sourceParentFolder.setCmisRepositoryId("alfresco"); AcmFolder targetParentFolder = new AcmFolder(); targetParentFolder.setId(500L); targetParentFolder.setCmisFolderId("targetParentFolderNodeId"); targetParentFolder.setCmisRepositoryId("alfresco"); AcmContainer container = new AcmContainer(); container.setId(600L); container.setContainerObjectType("containerObjectType"); container.setContainerObjectId(700L); EcmFile file = new EcmFile(); file.setFileId(200L); file.setFolder(sourceParentFolder); auditPropertyEntityAdapter.setUserId(fileMovedEvent.getUserId()); when(acmFolderDao.findByCmisFolderId(fileMovedEvent.getSourceParentNodeId())).thenReturn(sourceParentFolder); when(acmFolderDao.findByCmisFolderId(fileMovedEvent.getTargetParentNodeId())).thenReturn(targetParentFolder); when(ecmFileDao.findByCmisFileIdAndFolderId(fileMovedEvent.getNodeId(), sourceParentFolder.getId())).thenReturn(file); assertEquals(file.getFolder().getCmisFolderId(), fileMovedEvent.getSourceParentNodeId()); EcmFile returnFile = file; returnFile.setContainer(container); returnFile.setFolder(targetParentFolder); when(ecmFileService.moveFileInArkcase(file, targetParentFolder, fileMovedEvent.getTargetParentNodeType())).thenReturn(returnFile); unit.onEcmFileMoved(fileMovedEvent); verify(acmFolderDao, times(2)).findByCmisFolderId(anyString()); verify(ecmFileDao, times(1)).findByCmisFileIdAndFolderId(anyString(), anyLong()); }
public void onEcmFileMoved(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder sourceParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getSourceParentNodeId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getTargetParentNodeId()); if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFile(ecmEvent, sourceParentFolder, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFile(ecmEvent, sourceParentFolder); } else if (sourceParentFolder == null && targetParentFolder != null) { try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFolder(ecmEvent, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFolder(ecmEvent); } else if (sourceParentFolder == null && targetParentFolder != null) { AcmFolder created = null; try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); created = getFolderService().createFolder(targetParentFolder, ecmEvent.getNodeId(), ecmEvent.getNodeName()); } catch (AcmUserActionFailedException | AcmFolderException e) { log.debug("Can't create new folder with node id [{}]", ecmEvent.getNodeId()); } try { getFolderService().recordMetadataOfExistingFolderChildren(created, ecmEvent.getUserId()); } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Can not create folder children for folder with id: {} and name: {} ", created.getId(), created.getName()); } log.debug("Finished creating new folder with node id {}, ArkCase id {}", created.getCmisFolderId(), created.getId()); } } }
EcmFileFolderMovedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileMoved(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder sourceParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getSourceParentNodeId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getTargetParentNodeId()); if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFile(ecmEvent, sourceParentFolder, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFile(ecmEvent, sourceParentFolder); } else if (sourceParentFolder == null && targetParentFolder != null) { try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFolder(ecmEvent, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFolder(ecmEvent); } else if (sourceParentFolder == null && targetParentFolder != null) { AcmFolder created = null; try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); created = getFolderService().createFolder(targetParentFolder, ecmEvent.getNodeId(), ecmEvent.getNodeName()); } catch (AcmUserActionFailedException | AcmFolderException e) { log.debug("Can't create new folder with node id [{}]", ecmEvent.getNodeId()); } try { getFolderService().recordMetadataOfExistingFolderChildren(created, ecmEvent.getUserId()); } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Can not create folder children for folder with id: {} and name: {} ", created.getId(), created.getName()); } log.debug("Finished creating new folder with node id {}, ArkCase id {}", created.getCmisFolderId(), created.getId()); } } } }
EcmFileFolderMovedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileMoved(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder sourceParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getSourceParentNodeId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getTargetParentNodeId()); if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFile(ecmEvent, sourceParentFolder, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFile(ecmEvent, sourceParentFolder); } else if (sourceParentFolder == null && targetParentFolder != null) { try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFolder(ecmEvent, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFolder(ecmEvent); } else if (sourceParentFolder == null && targetParentFolder != null) { AcmFolder created = null; try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); created = getFolderService().createFolder(targetParentFolder, ecmEvent.getNodeId(), ecmEvent.getNodeName()); } catch (AcmUserActionFailedException | AcmFolderException e) { log.debug("Can't create new folder with node id [{}]", ecmEvent.getNodeId()); } try { getFolderService().recordMetadataOfExistingFolderChildren(created, ecmEvent.getUserId()); } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Can not create folder children for folder with id: {} and name: {} ", created.getId(), created.getName()); } log.debug("Finished creating new folder with node id {}, ArkCase id {}", created.getCmisFolderId(), created.getId()); } } }  }
EcmFileFolderMovedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileMoved(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder sourceParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getSourceParentNodeId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getTargetParentNodeId()); if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFile(ecmEvent, sourceParentFolder, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFile(ecmEvent, sourceParentFolder); } else if (sourceParentFolder == null && targetParentFolder != null) { try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFolder(ecmEvent, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFolder(ecmEvent); } else if (sourceParentFolder == null && targetParentFolder != null) { AcmFolder created = null; try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); created = getFolderService().createFolder(targetParentFolder, ecmEvent.getNodeId(), ecmEvent.getNodeName()); } catch (AcmUserActionFailedException | AcmFolderException e) { log.debug("Can't create new folder with node id [{}]", ecmEvent.getNodeId()); } try { getFolderService().recordMetadataOfExistingFolderChildren(created, ecmEvent.getUserId()); } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Can not create folder children for folder with id: {} and name: {} ", created.getId(), created.getName()); } log.debug("Finished creating new folder with node id {}, ArkCase id {}", created.getCmisFolderId(), created.getId()); } } }  void onEcmFileMoved(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileService getFileService(); void setFileService(EcmFileService fileService); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils); }
EcmFileFolderMovedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileMoved(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder sourceParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getSourceParentNodeId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getTargetParentNodeId()); if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFile(ecmEvent, sourceParentFolder, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFile(ecmEvent, sourceParentFolder); } else if (sourceParentFolder == null && targetParentFolder != null) { try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { if (sourceParentFolder != null && targetParentFolder != null) { moveFolder(ecmEvent, targetParentFolder); } else if (sourceParentFolder != null && targetParentFolder == null) { deleteFolder(ecmEvent); } else if (sourceParentFolder == null && targetParentFolder != null) { AcmFolder created = null; try { String message = String.format(MOVED_INTO_MESSAGE, ecmEvent.getNodeType()); getFolderService().removeLockAndSendMessage(targetParentFolder.getId(), message); created = getFolderService().createFolder(targetParentFolder, ecmEvent.getNodeId(), ecmEvent.getNodeName()); } catch (AcmUserActionFailedException | AcmFolderException e) { log.debug("Can't create new folder with node id [{}]", ecmEvent.getNodeId()); } try { getFolderService().recordMetadataOfExistingFolderChildren(created, ecmEvent.getUserId()); } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Can not create folder children for folder with id: {} and name: {} ", created.getId(), created.getName()); } log.debug("Finished creating new folder with node id {}, ArkCase id {}", created.getCmisFolderId(), created.getId()); } } }  void onEcmFileMoved(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileService getFileService(); void setFileService(EcmFileService fileService); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils);  }