@Test public void onEcmFileCreated_ifContainerNotInArkCase_thenNoFurtherAction() throws Exception { AcmFolder parentFolder = new AcmFolder(); parentFolder.setId(500L); auditPropertyEntityAdapter.setUserId(fileCreated.getUserId()); expect(acmFolderDao.findByCmisFolderId(fileCreated.getParentNodeId())).andReturn(parentFolder); expect(ecmFileDao.findByCmisFileIdAndFolderId(fileCreated.getNodeId(), parentFolder.getId())).andThrow(new NoResultException()); expect(acmFolderService.findContainerByFolderId(parentFolder.getId())).andThrow(new AcmObjectNotFoundException( "objectType", 600L, "test exception")); replay(mocks); unit.onEcmFileCreated(fileCreated); verify(mocks); }
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);  }