Skip to content

Commit

Permalink
Merge pull request #1786 from jcomedouteau/shanoir-issue#1783-solr-in…
Browse files Browse the repository at this point in the history
…dex-bug

#1783-Solr update after import + study card
  • Loading branch information
michaelkain authored Aug 2, 2023
2 parents 9352a53 + f9931a1 commit 8f5523e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.shanoir.ng.datasetacquisition.service;

import java.util.Collection;
import java.util.List;

import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition;
Expand Down Expand Up @@ -63,4 +64,6 @@ public interface DatasetAcquisitionService {
void deleteById(Long id) throws EntityNotFoundException, ShanoirException;

boolean existsByStudyCardId(Long studyCardId);

Collection<DatasetAcquisition> createAll(Collection<DatasetAcquisition> acquisitions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.shanoir.ng.datasetacquisition.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -40,6 +41,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;

@Service
public class DatasetAcquisitionServiceImpl implements DatasetAcquisitionService {
Expand Down Expand Up @@ -114,6 +116,15 @@ public Page<DatasetAcquisition> findPage(final Pageable pageable) {
return repository.findPageByStudyCenterOrStudyIdIn(studyCenters, unrestrictedStudies, pageable);
}
}

@Override
public Collection<DatasetAcquisition> createAll(Collection<DatasetAcquisition> acquisitions) {
Iterable<DatasetAcquisition> result = this.repository.saveAll(acquisitions);
for (DatasetAcquisition acquisition: result) {
shanoirEventService.publishEvent(new ShanoirEvent(ShanoirEventType.CREATE_DATASET_ACQUISITION_EVENT, acquisition.getId().toString(), KeycloakUtil.getTokenUserId(), "", ShanoirEvent.SUCCESS));
}
return Lists.newArrayList(result);
}

@Override
public DatasetAcquisition create(DatasetAcquisition entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.shanoir.ng.dataset.service.DatasetService;
import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition;
import org.shanoir.ng.datasetacquisition.repository.DatasetAcquisitionRepository;
import org.shanoir.ng.datasetacquisition.service.DatasetAcquisitionService;
import org.shanoir.ng.datasetfile.DatasetFile;
import org.shanoir.ng.dicom.DicomProcessing;
import org.shanoir.ng.examination.model.Examination;
Expand Down Expand Up @@ -126,6 +127,9 @@ public class ImporterService {

@Autowired
private QualityCardService qualityCardService;

@Autowired
private DatasetAcquisitionService datasetAcquisitionService;

@Autowired
private DicomProcessing dicomProcessing;
Expand Down Expand Up @@ -164,7 +168,7 @@ public void createAllDatasetAcquisition(ImportJob importJob, Long userId) throws
if (qualityResult.hasError()) {
throw new QualityException(examination, qualityResult);
} else { // Then do the import
datasetAcquisitionRepository.saveAll(generatedAcquisitions);
generatedAcquisitions = new HashSet<DatasetAcquisition>(datasetAcquisitionService.createAll(generatedAcquisitions));
try {
persistPatientInPacs(importJob.getPatients(), event);
} catch (Exception e) { // if error in pacs
Expand All @@ -174,7 +178,7 @@ public void createAllDatasetAcquisition(ImportJob importJob, Long userId) throws
}
throw new ShanoirException("Error while saving data in pacs, the import is canceled and acquisitions were not saved");
}
}
}
} else {
throw new ShanoirException("Examination not found: " + importJob.getExaminationId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import java.util.List;

import org.shanoir.ng.shared.exception.RestServiceException;
import org.shanoir.ng.shared.paging.FacetPageable;
import org.shanoir.ng.solr.model.ShanoirSolrDocument;
import org.shanoir.ng.solr.model.ShanoirSolrQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.query.result.FacetFieldEntry;
import org.springframework.data.solr.core.query.result.SolrResultPage;
import org.springframework.security.access.prepost.PreAuthorize;

Expand Down Expand Up @@ -56,4 +54,6 @@ public interface SolrService {

void addAllToIndex(List<ShanoirSolrDocument> documents);

void updateDatasets(List<Long> datasetIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,17 @@ public Page<ShanoirSolrDocument> getByIdIn(List<Long> datasetIds, Pageable pagea
return result;
}

/**
* Updates a list of datasets in Solr.
* @param datasetIds the list of dataset IDs to update
*/
@Override
public void updateDatasets(List<Long> datasetIds) {
if (CollectionUtils.isEmpty(datasetIds)) {
return;
}
this.deleteFromIndex(datasetIds);
this.indexDatasets(datasetIds);;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import org.dcm4che3.data.Tag;
import org.shanoir.ng.dataset.model.Dataset;
import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition;
import org.shanoir.ng.datasetacquisition.service.DatasetAcquisitionService;
import org.shanoir.ng.shared.core.model.IdList;
Expand All @@ -29,6 +30,7 @@
import org.shanoir.ng.shared.exception.MicroServiceCommunicationException;
import org.shanoir.ng.shared.exception.PacsException;
import org.shanoir.ng.shared.exception.RestServiceException;
import org.shanoir.ng.solr.service.SolrService;
import org.shanoir.ng.studycard.dto.DicomTag;
import org.shanoir.ng.studycard.model.StudyCard;
import org.shanoir.ng.studycard.model.StudyCardApply;
Expand Down Expand Up @@ -65,6 +67,9 @@ public class StudyCardApiController implements StudyCardApi {

@Autowired
private CardsProcessingService cardProcessingService;

@Autowired
private SolrService solrService;

@Override
public ResponseEntity<Void> deleteStudyCard(
Expand Down Expand Up @@ -227,6 +232,18 @@ public ResponseEntity<Void> applyStudyCard(
LOG.debug("re-apply studycard n° " + studyCard.getId());
List<DatasetAcquisition> acquisitions = datasetAcquisitionService.findById(studyCardApplyObject.getDatasetAcquisitionIds());
cardProcessingService.applyStudyCard(studyCard, acquisitions);

// Get all updated dataset ids
List<Long> datasetIds = new ArrayList<Long>();
for (DatasetAcquisition acquisition : acquisitions) {
for (Dataset ds : acquisition.getDatasets()) {
datasetIds.add(ds.getId());
}
}

// Update solr metadata
solrService.updateDatasets(datasetIds);

return new ResponseEntity<Void>(HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void createAllDatasetAcquisition() throws Exception {

// THEN datasets are created
// Check what we save at the end
verify(datasetAcquisitionRepository).saveAll(any());
verify(datasetAcquisitionService).createAll(any());
//verify(datasetAcquisitionService).create(datasetAcq);
verify(dicomPersisterService).persistAllForSerie(any());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.shanoir.ng.shared.exception.EntityNotFoundException;
import org.shanoir.ng.shared.exception.MicroServiceCommunicationException;
import org.shanoir.ng.shared.validation.FindByRepository;
import org.shanoir.ng.solr.service.SolrService;
import org.shanoir.ng.studycard.controler.StudyCardApiController;
import org.shanoir.ng.studycard.model.StudyCard;
import org.shanoir.ng.studycard.service.CardsProcessingService;
Expand Down Expand Up @@ -96,6 +97,9 @@ public class StudyCardApiControllerTest {

@MockBean
private DicomSRImporterService dicomSRImporterService;

@MockBean
private SolrService solrService;

@Before
public void setup() throws EntityNotFoundException, MicroServiceCommunicationException {
Expand Down

0 comments on commit 8f5523e

Please sign in to comment.