RED-8339: Fixes

This commit is contained in:
Ali Oezyetimoglu 2024-05-27 17:25:39 +02:00
parent ac6b11089b
commit be4769497d
6 changed files with 27 additions and 66 deletions

View File

@ -53,6 +53,7 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
.name("Study_Title")
.componentValues(List.of(ComponentValue.builder()
.value("AAAA Strange Chemical Name And the rest of a title With a dash and some more text")
.originalValue("Strange Chemical Name And the rest of a title With a dash and some more text")
.valueDescription("First found value of type title or else ''")
.componentRuleId("StudyTitle.0.0")
.entityReferences(List.of(EntityReference.builder()

View File

@ -19,4 +19,10 @@ public interface ComponentDocumentRepository extends MongoRepository<ComponentDo
@Query(value = "{ 'componentLogId': ?0, 'componentName': ?1 }")
Optional<ComponentDocument> findComponentDocumentByName(String componentLogId, String componentName);
@Query(value = "{ 'componentLogId': ?0 }")
List<ComponentDocument> findByDossierIdAndFileId(String componentLogId);
@Query(value = "{ 'componentLogId': ?0 }", fields = "{ 'overrideValues': 0 }")
List<ComponentDocument> findWithoutEntriesByDossierIdAndFileId(String componentLogId);
}

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.repository;
import java.util.List;
import java.util.Optional;
import org.springframework.core.convert.TypeDescriptor;
@ -7,10 +8,11 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.document.ComponentDocument;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.document.ComponentLogDocument;
@Repository
public interface ComponentLogDocumentRepository extends MongoRepository<ComponentLogDocument, String>, CustomComponentRepository {
public interface ComponentLogDocumentRepository extends MongoRepository<ComponentLogDocument, String> {
@Query(value = "{ 'id' : ?0 }", fields = "{ 'analysisNumber' : 1 }")
Optional<ComponentLogDocument> findAnalysisNumberById(String id);

View File

@ -1,14 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.repository;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.document.ComponentDocument;
@Repository
public interface CustomComponentRepository {
List<ComponentDocument> findOverrides(String fileId, String dossierId);
}

View File

@ -1,50 +0,0 @@
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.repository;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.replaceRoot;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind;
import java.util.List;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.LookupOperation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Repository;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.document.ComponentDocument;
import lombok.RequiredArgsConstructor;
@Repository
@RequiredArgsConstructor
public class CustomComponentRepositoryImpl implements CustomComponentRepository {
private final MongoTemplate mongoTemplate;
@Override
public List<ComponentDocument> findOverrides(String fileId, String dossierId) {
LookupOperation lookupOperation = LookupOperation.newLookup().from("components").localField("overrideValues").foreignField("_id").as("componentDocs");
AggregationOperation matchOperation = match(Criteria.where("componentLogId").is(dossierId + "/" + fileId));
// AggregationOperation matchOperation = match(Criteria.where("fileId").is(fileId).and("dossierId").is(dossierId));
AggregationOperation unwindOperation = unwind("componentDocs");
AggregationOperation matchNonEmptyOverrides = match(Criteria.where("componentDocs.overrideValues").ne(null));
AggregationOperation replaceRootOperation = replaceRoot("componentDocs");
Aggregation aggregation = newAggregation(matchOperation, lookupOperation, unwindOperation, matchNonEmptyOverrides, replaceRootOperation);
AggregationResults<ComponentDocument> results = mongoTemplate.aggregate(aggregation, "component-logs", ComponentDocument.class);
return results.getMappedResults();
}
}

View File

@ -181,10 +181,26 @@ public class ComponentLogMongoService {
public List<ComponentLogEntry> findOverrides(String dossierId, String fileId) {
return componentLogDocumentRepository.findOverrides(dossierId, fileId)
String componentLogId = mapper.getComponentLogId(dossierId, fileId);
List<ComponentLogEntry> overrides = componentDocumentRepository.findByDossierIdAndFileId(componentLogId)
.stream()
.map(mapper::fromComponentDocument)
.toList();
overrides.forEach(componentLogEntry -> {
var componentValues = componentLogEntry.getComponentValues()
.stream()
.filter(componentLogEntryValue -> !componentLogEntryValue.getValue().equals(componentLogEntryValue.getOriginalValue()))
.toList();
componentLogEntry.setComponentValues(componentValues);
});
return overrides;
// return componentLogDocumentRepository.findOverrides(dossierId, fileId)
// .stream()
// .map(mapper::fromComponentDocument)
// .toList();
}