@Test public void onEcmFileCreated_createNewArkCaseFile() throws Exception { AcmFolder parentFolder = new AcmFolder(); parentFolder.setId(500L); parentFolder.setCmisRepositoryId("cmisRepositoryId"); AcmContainer container = new AcmContainer(); container.setId(600L); container.setContainerObjectType("containerObjectType"); container.setContainerObjectId(700L); String mimeType = "mime/type"; String fileType = "other"; String category = "Document"; Capture<Authentication> actualAuthentication = Capture.newInstance(); expect(acmFolderDao.findByCmisFolderId(fileCreated.getParentNodeId())).andReturn(parentFolder); expect(ecmFileDao.findByCmisFileIdAndFolderId(fileCreated.getNodeId(), parentFolder.getId())).andThrow(new NoResultException()); expect(acmFolderService.findContainerByFolderId(parentFolder.getId())).andReturn(container); expect(acmFolderService.getCmisRepositoryId(parentFolder)).andReturn(parentFolder.getCmisRepositoryId()); expect(ecmFileService.findObjectById(parentFolder.getCmisRepositoryId(), fileCreated.getNodeId())).andReturn(cmisDocument); expect(cmisDocument.getContentStreamMimeType()).andReturn(mimeType); expect(cmisDocument.getContentStream()).andReturn(contentStream); expect(contentStream.getStream()).andReturn(inputStream); auditPropertyEntityAdapter.setUserId(fileCreated.getUserId()); expect(ecmFileService.upload( eq(fileCreated.getNodeName()), eq(fileType), eq(category), eq(inputStream), eq(mimeType), eq(fileCreated.getNodeName()), capture(actualAuthentication), eq(parentFolder.getCmisFolderId()), eq(container.getContainerObjectType()), eq(container.getContainerObjectId()), eq(parentFolder.getCmisRepositoryId()), eq(cmisDocument))).andReturn(new EcmFile()); when(objectLockService.findLock(anyLong(), anyString())).thenReturn(new AcmObjectLock()); when(messageChannel.send(any(Message.class))).thenReturn(true); replay(mocks); unit.onEcmFileCreated(fileCreated); verify(mocks); Authentication foundAuthentication = actualAuthentication.getValue(); assertEquals(fileCreated.getUserId(), foundAuthentication.getName()); }
public void onEcmFileCreated(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder parentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (parentFolder == null) { log.debug("Parent folder is not in ArkCase, so not creating the new file {}", ecmEvent.getNodeId()); return; } if (getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), parentFolder.getId()) != null) { log.debug("ArkCase already has the file with CMIS id {}", ecmEvent.getNodeId()); return; } AcmContainer container = getFolderAndFilesUtils().lookupArkCaseContainer(parentFolder.getId()); if (container == null) { log.debug("Can't find container for the new file with id {}, exiting.", ecmEvent.getNodeId()); return; } MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, ecmEvent.getUserId()); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); String cmisRepositoryId = getFolderService().getCmisRepositoryId(parentFolder); Document cmisDocument = getFolderAndFilesUtils().lookupCmisDocument(cmisRepositoryId, ecmEvent.getNodeId()); if (cmisDocument == null) { log.error("No document to be loaded - exiting."); return; } try { EcmFile addedToArkCase = getFileService().upload( ecmEvent.getNodeName(), getFolderAndFilesUtils().findFileType(cmisDocument), "Document", cmisDocument.getContentStream().getStream(), cmisDocument.getContentStreamMimeType(), ecmEvent.getNodeName(), new UsernamePasswordAuthenticationToken(ecmEvent.getUserId(), ecmEvent.getUserId()), parentFolder.getCmisFolderId(), container.getContainerObjectType(), container.getContainerObjectId(), parentFolder.getCmisRepositoryId(), cmisDocument); log.info("Added file to ArkCase with CMIS ID [{}] and ArkCase ID [{}]", ecmEvent.getNodeId(), addedToArkCase.getId()); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } }
EcmFileCreatedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCreated(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder parentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (parentFolder == null) { log.debug("Parent folder is not in ArkCase, so not creating the new file {}", ecmEvent.getNodeId()); return; } if (getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), parentFolder.getId()) != null) { log.debug("ArkCase already has the file with CMIS id {}", ecmEvent.getNodeId()); return; } AcmContainer container = getFolderAndFilesUtils().lookupArkCaseContainer(parentFolder.getId()); if (container == null) { log.debug("Can't find container for the new file with id {}, exiting.", ecmEvent.getNodeId()); return; } MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, ecmEvent.getUserId()); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); String cmisRepositoryId = getFolderService().getCmisRepositoryId(parentFolder); Document cmisDocument = getFolderAndFilesUtils().lookupCmisDocument(cmisRepositoryId, ecmEvent.getNodeId()); if (cmisDocument == null) { log.error("No document to be loaded - exiting."); return; } try { EcmFile addedToArkCase = getFileService().upload( ecmEvent.getNodeName(), getFolderAndFilesUtils().findFileType(cmisDocument), "Document", cmisDocument.getContentStream().getStream(), cmisDocument.getContentStreamMimeType(), ecmEvent.getNodeName(), new UsernamePasswordAuthenticationToken(ecmEvent.getUserId(), ecmEvent.getUserId()), parentFolder.getCmisFolderId(), container.getContainerObjectType(), container.getContainerObjectId(), parentFolder.getCmisRepositoryId(), cmisDocument); log.info("Added file to ArkCase with CMIS ID [{}] and ArkCase ID [{}]", ecmEvent.getNodeId(), addedToArkCase.getId()); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } } }
EcmFileCreatedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCreated(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder parentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (parentFolder == null) { log.debug("Parent folder is not in ArkCase, so not creating the new file {}", ecmEvent.getNodeId()); return; } if (getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), parentFolder.getId()) != null) { log.debug("ArkCase already has the file with CMIS id {}", ecmEvent.getNodeId()); return; } AcmContainer container = getFolderAndFilesUtils().lookupArkCaseContainer(parentFolder.getId()); if (container == null) { log.debug("Can't find container for the new file with id {}, exiting.", ecmEvent.getNodeId()); return; } MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, ecmEvent.getUserId()); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); String cmisRepositoryId = getFolderService().getCmisRepositoryId(parentFolder); Document cmisDocument = getFolderAndFilesUtils().lookupCmisDocument(cmisRepositoryId, ecmEvent.getNodeId()); if (cmisDocument == null) { log.error("No document to be loaded - exiting."); return; } try { EcmFile addedToArkCase = getFileService().upload( ecmEvent.getNodeName(), getFolderAndFilesUtils().findFileType(cmisDocument), "Document", cmisDocument.getContentStream().getStream(), cmisDocument.getContentStreamMimeType(), ecmEvent.getNodeName(), new UsernamePasswordAuthenticationToken(ecmEvent.getUserId(), ecmEvent.getUserId()), parentFolder.getCmisFolderId(), container.getContainerObjectType(), container.getContainerObjectId(), parentFolder.getCmisRepositoryId(), cmisDocument); log.info("Added file to ArkCase with CMIS ID [{}] and ArkCase ID [{}]", ecmEvent.getNodeId(), addedToArkCase.getId()); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } }  }
EcmFileCreatedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCreated(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder parentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (parentFolder == null) { log.debug("Parent folder is not in ArkCase, so not creating the new file {}", ecmEvent.getNodeId()); return; } if (getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), parentFolder.getId()) != null) { log.debug("ArkCase already has the file with CMIS id {}", ecmEvent.getNodeId()); return; } AcmContainer container = getFolderAndFilesUtils().lookupArkCaseContainer(parentFolder.getId()); if (container == null) { log.debug("Can't find container for the new file with id {}, exiting.", ecmEvent.getNodeId()); return; } MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, ecmEvent.getUserId()); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); String cmisRepositoryId = getFolderService().getCmisRepositoryId(parentFolder); Document cmisDocument = getFolderAndFilesUtils().lookupCmisDocument(cmisRepositoryId, ecmEvent.getNodeId()); if (cmisDocument == null) { log.error("No document to be loaded - exiting."); return; } try { EcmFile addedToArkCase = getFileService().upload( ecmEvent.getNodeName(), getFolderAndFilesUtils().findFileType(cmisDocument), "Document", cmisDocument.getContentStream().getStream(), cmisDocument.getContentStreamMimeType(), ecmEvent.getNodeName(), new UsernamePasswordAuthenticationToken(ecmEvent.getUserId(), ecmEvent.getUserId()), parentFolder.getCmisFolderId(), container.getContainerObjectType(), container.getContainerObjectId(), parentFolder.getCmisRepositoryId(), cmisDocument); log.info("Added file to ArkCase with CMIS ID [{}] and ArkCase ID [{}]", ecmEvent.getNodeId(), addedToArkCase.getId()); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } }  void onEcmFileCreated(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileService getFileService(); void setFileService(EcmFileService fileService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils); }
EcmFileCreatedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFileCreated(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); AcmFolder parentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getParentNodeId()); if (parentFolder == null) { log.debug("Parent folder is not in ArkCase, so not creating the new file {}", ecmEvent.getNodeId()); return; } if (getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId(), parentFolder.getId()) != null) { log.debug("ArkCase already has the file with CMIS id {}", ecmEvent.getNodeId()); return; } AcmContainer container = getFolderAndFilesUtils().lookupArkCaseContainer(parentFolder.getId()); if (container == null) { log.debug("Can't find container for the new file with id {}, exiting.", ecmEvent.getNodeId()); return; } MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, ecmEvent.getUserId()); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); String cmisRepositoryId = getFolderService().getCmisRepositoryId(parentFolder); Document cmisDocument = getFolderAndFilesUtils().lookupCmisDocument(cmisRepositoryId, ecmEvent.getNodeId()); if (cmisDocument == null) { log.error("No document to be loaded - exiting."); return; } try { EcmFile addedToArkCase = getFileService().upload( ecmEvent.getNodeName(), getFolderAndFilesUtils().findFileType(cmisDocument), "Document", cmisDocument.getContentStream().getStream(), cmisDocument.getContentStreamMimeType(), ecmEvent.getNodeName(), new UsernamePasswordAuthenticationToken(ecmEvent.getUserId(), ecmEvent.getUserId()), parentFolder.getCmisFolderId(), container.getContainerObjectType(), container.getContainerObjectId(), parentFolder.getCmisRepositoryId(), cmisDocument); log.info("Added file to ArkCase with CMIS ID [{}] and ArkCase ID [{}]", ecmEvent.getNodeId(), addedToArkCase.getId()); } catch (AcmCreateObjectFailedException | AcmUserActionFailedException e) { log.error("Could not add file with CMIS ID [{}] to ArkCase: {}", ecmEvent.getNodeId(), e.getMessage(), e); } }  void onEcmFileCreated(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileService getFileService(); void setFileService(EcmFileService fileService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils);  }