@Test public void onEcmFileCopied_ifTargetFolderIsNotArkcaseFolder_thenNoFurtherAction() { auditPropertyEntityAdapter.setUserId(fileCopiedEvent.getUserId()); when(acmFolderDao.findByCmisFolderId(fileCopiedEvent.getParentNodeId())).thenThrow(new NoResultException()); unit.onEcmFileCopied(fileCopiedEvent); verify(acmFolderDao, times(1)).findByCmisFolderId(anyString()); }
public void onEcmFileCopied(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (targetParentFolder == null) { log.debug("Can't find folder for the copied file with id {}, no further action.", ecmEvent.getNodeId()); return; } if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { EcmFile arkCaseFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), targetParentFolder.getId()); if (targetParentFolder != null && arkCaseFile == null) { List<EcmFile> listFiles = getFileDao().findByCmisFileId(ecmEvent.getSourceOfCopyNodeId()); if (listFiles.isEmpty()) { try { getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.debug("Could not add file with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } else { copyFile(ecmEvent, targetParentFolder, listFiles); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { AcmFolder arkCaseFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId()); if (targetParentFolder != null && arkCaseFolder == null) { AcmFolder created = null; try { String message = String.format(COPY_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()); } else if (targetParentFolder != null && arkCaseFolder != null) { try { List<AcmObject> acmObjects = getFolderService().getFolderChildren(arkCaseFolder.getId()); if (acmObjects.isEmpty()) { getFolderService().recordMetadataOfExistingFolderChildren(arkCaseFolder, ecmEvent.getUserId()); } } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Could not create children in folder with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } } }
EcmFileFolderCopiedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCopied(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (targetParentFolder == null) { log.debug("Can't find folder for the copied file with id {}, no further action.", ecmEvent.getNodeId()); return; } if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { EcmFile arkCaseFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), targetParentFolder.getId()); if (targetParentFolder != null && arkCaseFile == null) { List<EcmFile> listFiles = getFileDao().findByCmisFileId(ecmEvent.getSourceOfCopyNodeId()); if (listFiles.isEmpty()) { try { getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.debug("Could not add file with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } else { copyFile(ecmEvent, targetParentFolder, listFiles); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { AcmFolder arkCaseFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId()); if (targetParentFolder != null && arkCaseFolder == null) { AcmFolder created = null; try { String message = String.format(COPY_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()); } else if (targetParentFolder != null && arkCaseFolder != null) { try { List<AcmObject> acmObjects = getFolderService().getFolderChildren(arkCaseFolder.getId()); if (acmObjects.isEmpty()) { getFolderService().recordMetadataOfExistingFolderChildren(arkCaseFolder, ecmEvent.getUserId()); } } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Could not create children in folder with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } } } }
EcmFileFolderCopiedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCopied(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (targetParentFolder == null) { log.debug("Can't find folder for the copied file with id {}, no further action.", ecmEvent.getNodeId()); return; } if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { EcmFile arkCaseFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), targetParentFolder.getId()); if (targetParentFolder != null && arkCaseFile == null) { List<EcmFile> listFiles = getFileDao().findByCmisFileId(ecmEvent.getSourceOfCopyNodeId()); if (listFiles.isEmpty()) { try { getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.debug("Could not add file with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } else { copyFile(ecmEvent, targetParentFolder, listFiles); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { AcmFolder arkCaseFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId()); if (targetParentFolder != null && arkCaseFolder == null) { AcmFolder created = null; try { String message = String.format(COPY_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()); } else if (targetParentFolder != null && arkCaseFolder != null) { try { List<AcmObject> acmObjects = getFolderService().getFolderChildren(arkCaseFolder.getId()); if (acmObjects.isEmpty()) { getFolderService().recordMetadataOfExistingFolderChildren(arkCaseFolder, ecmEvent.getUserId()); } } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Could not create children in folder with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } } }  }
EcmFileFolderCopiedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCopied(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (targetParentFolder == null) { log.debug("Can't find folder for the copied file with id {}, no further action.", ecmEvent.getNodeId()); return; } if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { EcmFile arkCaseFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), targetParentFolder.getId()); if (targetParentFolder != null && arkCaseFile == null) { List<EcmFile> listFiles = getFileDao().findByCmisFileId(ecmEvent.getSourceOfCopyNodeId()); if (listFiles.isEmpty()) { try { getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.debug("Could not add file with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } else { copyFile(ecmEvent, targetParentFolder, listFiles); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { AcmFolder arkCaseFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId()); if (targetParentFolder != null && arkCaseFolder == null) { AcmFolder created = null; try { String message = String.format(COPY_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()); } else if (targetParentFolder != null && arkCaseFolder != null) { try { List<AcmObject> acmObjects = getFolderService().getFolderChildren(arkCaseFolder.getId()); if (acmObjects.isEmpty()) { getFolderService().recordMetadataOfExistingFolderChildren(arkCaseFolder, ecmEvent.getUserId()); } } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Could not create children in folder with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } } }  void onEcmFileCopied(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileDao getFileDao(); void setFileDao(EcmFileDao fileDao); EcmFileService getFileService(); void setFileService(EcmFileService fileService); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils); }
EcmFileFolderCopiedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCopied(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder targetParentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (targetParentFolder == null) { log.debug("Can't find folder for the copied file with id {}, no further action.", ecmEvent.getNodeId()); return; } if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_DOCUMENT)) { EcmFile arkCaseFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), targetParentFolder.getId()); if (targetParentFolder != null && arkCaseFile == null) { List<EcmFile> listFiles = getFileDao().findByCmisFileId(ecmEvent.getSourceOfCopyNodeId()); if (listFiles.isEmpty()) { try { getFolderAndFilesUtils().uploadFile(ecmEvent, targetParentFolder); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.debug("Could not add file with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } else { copyFile(ecmEvent, targetParentFolder, listFiles); } } } else if (ecmEvent.getNodeType().equals(EcmFileConstants.ECM_SYNC_NODE_TYPE_FOLDER)) { AcmFolder arkCaseFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId()); if (targetParentFolder != null && arkCaseFolder == null) { AcmFolder created = null; try { String message = String.format(COPY_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()); } else if (targetParentFolder != null && arkCaseFolder != null) { try { List<AcmObject> acmObjects = getFolderService().getFolderChildren(arkCaseFolder.getId()); if (acmObjects.isEmpty()) { getFolderService().recordMetadataOfExistingFolderChildren(arkCaseFolder, ecmEvent.getUserId()); } } catch (AcmUserActionFailedException | AcmObjectNotFoundException e) { log.debug("Could not create children in folder with CMIS ID [{}] to ArkCase: [{}]", ecmEvent.getNodeId(), e.getMessage(), e); } } } }  void onEcmFileCopied(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileDao getFileDao(); void setFileDao(EcmFileDao fileDao); EcmFileService getFileService(); void setFileService(EcmFileService fileService); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils);  }