AdapterComponentDocRepositoryOrchImpl { protected void saveDocument(DocumentMetadata doc, boolean requestHasReplacementAssociation, String documentUniqueId, RegistryErrorList errorList) { DocumentService docService = getDocumentService(); if (requestHasReplacementAssociation) { long documentid = docRepoHelper.queryRepositoryByPatientId(doc.getPatientId(), doc.getDocumentUniqueId(), doc.getClassCode(), doc.getStatus(), docService); doc.setDocumentid(documentid); } docService.saveDocument(doc); LOG.debug("doc.documentId: {}", doc.getDocumentid()); if (doc.getDocumentid() == null || doc.getDocumentid() < 1) { RegistryError error = docRepoHelper.setRegistryError("store a document.", "storeDocument", DocRepoConstants.XDS_ERROR_CODE_REPOSITORY_ERROR, DocRepoConstants.XDS_REPOSITORY_ERROR + " DocumentUniqueId: " + documentUniqueId); errorList.getRegistryError().add(error); } } AdapterComponentDocRepositoryOrchImpl(); DocumentService getDocumentService(); LargeFileUtils getLargeFileUtils(); UTCDateUtil getDateUtil(); RetrieveDocumentSetResponseType documentRepositoryRetrieveDocumentSet(RetrieveDocumentSetRequestType body); RegistryResponseType registerDocumentSet(RegisterDocumentSetRequestType body); RegistryResponseType documentRepositoryProvideAndRegisterDocumentSet(
        ProvideAndRegisterDocumentSetRequestType body); DocumentMetadata saveExtrinsicObject(ExtrinsicObjectType extrinsicObject, RegistryErrorList errorList,
        Map<String, DataHandler> docMap, boolean hasReplacementRequest);  }
@Test public void testSaveDocument_Success() { final String PATIENT_ID = "ID_1"; final String DOC_UNIQUE_ID = "DOC_ID_1"; final String CLASS_CODE = "CLASS_CODE"; final String STATUS = "STATUS"; final long DOC_ID = 101; DocumentMetadata doc = mock(DocumentMetadata.class); RegistryErrorList errorList = new RegistryErrorList(); List<DocumentMetadata> docList = new ArrayList<>(); AdapterComponentDocRepositoryOrchImpl docRepo = getDocRepoWithMockDocService(); when(doc.getPatientId()).thenReturn(PATIENT_ID); when(doc.getDocumentUniqueId()).thenReturn(DOC_UNIQUE_ID); when(doc.getClassCode()).thenReturn(CLASS_CODE); when(doc.getStatus()).thenReturn(STATUS); when(docService.documentQuery(any(DocumentQueryParams.class))).thenReturn(docList); when(doc.getDocumentid()).thenReturn(DOC_ID); docRepo.saveDocument(doc, true, DOC_UNIQUE_ID, errorList); verify(docService).saveDocument(doc); assertEquals(0, errorList.getRegistryError().size()); }
@Test public void testSaveDocument_Failure() { final String PATIENT_ID = "ID_1"; final String DOC_UNIQUE_ID = "DOC_ID_1"; final String CLASS_CODE = "CLASS_CODE"; final String STATUS = "STATUS"; final long DOC_ID = 0; DocumentMetadata doc = mock(DocumentMetadata.class); RegistryErrorList errorList = new RegistryErrorList(); List<DocumentMetadata> docList = new ArrayList<>(); AdapterComponentDocRepositoryOrchImpl docRepo = getDocRepoWithMockDocService(); when(doc.getPatientId()).thenReturn(PATIENT_ID); when(doc.getDocumentUniqueId()).thenReturn(DOC_UNIQUE_ID); when(doc.getClassCode()).thenReturn(CLASS_CODE); when(doc.getStatus()).thenReturn(STATUS); when(docService.documentQuery(any(DocumentQueryParams.class))).thenReturn(docList); when(doc.getDocumentid()).thenReturn(DOC_ID); docRepo.saveDocument(doc, true, DOC_UNIQUE_ID, errorList); RegistryError error = errorList.getRegistryError().get(0); verify(docService).saveDocument(doc); assertEquals(DocRepoConstants.XDS_REPOSITORY_ERROR + " DocumentUniqueId: " + DOC_UNIQUE_ID, error.getValue()); }