@Test public void onEcmFileMoved_ifSourceFolderIsNotArkcaseFolder_And_TargetFolderIsArkcaseFolder_uploadFile() throws Exception { 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); String mimeType = "mime/type"; String fileType = "other"; String category = "Document"; auditPropertyEntityAdapter.setUserId(fileMovedEvent.getUserId()); ArgumentCaptor<Authentication> actualAuthentication = ArgumentCaptor.forClass(Authentication.class); when(acmFolderDao.findByCmisFolderId(fileMovedEvent.getSourceParentNodeId())).thenThrow(new NoResultException()); when(acmFolderDao.findByCmisFolderId(fileMovedEvent.getTargetParentNodeId())).thenReturn(targetParentFolder); when(acmFolderService.findContainerByFolderId(targetParentFolder.getId())).thenReturn(container); when(acmFolderService.getCmisRepositoryId(targetParentFolder)).thenReturn(targetParentFolder.getCmisRepositoryId()); when(ecmFileService.findObjectById(targetParentFolder.getCmisRepositoryId(), fileMovedEvent.getNodeId())).thenReturn(cmisDocument); when(cmisDocument.getContentStreamMimeType()).thenReturn(mimeType); when(cmisDocument.getContentStream()).thenReturn(contentStream); when(contentStream.getStream()).thenReturn(inputStream); when(ecmFileService.upload( eq(fileMovedEvent.getNodeName()), eq(fileType), eq(category), eq(inputStream), eq(mimeType), eq(fileMovedEvent.getNodeName()), actualAuthentication.capture(), eq(targetParentFolder.getCmisFolderId()), eq(container.getContainerObjectType()), eq(container.getContainerObjectId()), eq(targetParentFolder.getCmisRepositoryId()), eq(cmisDocument))).thenReturn(new EcmFile()); unit.onEcmFileMoved(fileMovedEvent); Authentication foundAuthentication = actualAuthentication.getValue(); assertEquals(fileMovedEvent.getUserId(), foundAuthentication.getName()); }
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);  }