Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix: Set constant
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu committed Apr 17, 2024
1 parent 57cc57a commit 40d4126
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
@Component
public class DelegationConnectorImpl implements DelegationConnector {

public static final String INSTITUTIONS = "institutions";
public static final String DELEGATIONS = "Delegations";
private final DelegationRepository repository;
private final DelegationEntityMapper delegationMapper;
private final DelegationInstitutionMapper delegationInstitutionMapper;
Expand Down Expand Up @@ -100,19 +102,19 @@ public List<Delegation> find(String from, String to, String productId, String se

if (Objects.nonNull(taxCode)) {
MatchOperation matchTaxCodeOperation = getMatchTaxCodeOperation(taxCode);
aggregation = Aggregation.newAggregation(matchOperation, lookup.as("institutions"), matchTaxCodeOperation, skip, limit);
aggregation = Aggregation.newAggregation(matchOperation, lookup.as(INSTITUTIONS), matchTaxCodeOperation, skip, limit);
}
else {
if (!order.equals(Order.NONE)) {
SortOperation sortOperation = new SortOperation(Sort.by(sortDirection, DelegationEntity.Fields.institutionFromName.name()));
aggregation = Aggregation.newAggregation(matchOperation, sortOperation, lookup.as("institutions"), skip, limit);
aggregation = Aggregation.newAggregation(matchOperation, sortOperation, lookup.as(INSTITUTIONS), skip, limit);
}
else {
aggregation = Aggregation.newAggregation(matchOperation, lookup.as("institutions"), skip, limit);
aggregation = Aggregation.newAggregation(matchOperation, lookup.as(INSTITUTIONS), skip, limit);
}
}

List<DelegationInstitution> result = mongoTemplate.aggregate(aggregation, "Delegations", DelegationInstitution.class).getMappedResults();
List<DelegationInstitution> result = mongoTemplate.aggregate(aggregation, DELEGATIONS, DelegationInstitution.class).getMappedResults();
return result.stream()
.map(Objects.nonNull(from) ?
delegationInstitutionMapper::convertToDelegationBroker :
Expand All @@ -132,7 +134,7 @@ public List<Delegation> find(String from, String to, String productId, String se
}

private static GraphLookupOperation.GraphLookupOperationBuilder createInstitutionGraphLookupOperationBuilder(String from) {
return Aggregation.graphLookup("Institution")
return Aggregation.graphLookup(INSTITUTIONS)
.startWith(Objects.nonNull(from) ? "to" : "from")
.connectFrom(Objects.nonNull(from) ? "to" : "from")
.connectTo("_id");
Expand Down

0 comments on commit 40d4126

Please sign in to comment.