Skip to content

Commit

Permalink
fix: Pending contributions are marked as deleted when they need to be…
Browse files Browse the repository at this point in the history
…canceled - MEED-7461 - Meeds-io/meeds#2379 (#1732)

Ensure the cancellation process for pending contributions.
  • Loading branch information
AzmiTouil authored Sep 11, 2024
1 parent af03711 commit 827fe7a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,24 @@ public int countRealizationsInPeriod(String earnerIdentityId, long ruleId, Date
}
}

public Long findLastReadlizationByRuleIdAndEarnerIdAndReceiverAndObjectId(long ruleId,
String earnerId,
String receiverId,
String objectId,
String objectType) {
public Long findLastRealizationByRuleIdAndEarnerIdAndReceiverAndObjectId(long ruleId,
String earnerId,
String receiverId,
String objectId,
String objectType) {
TypedQuery<Long> query =
getEntityManager().createNamedQuery("RealizationEntity.findReadlizationsByRuleIdAndEarnerIdAndReceiverAndObjectId",
Long.class);
getEntityManager().createNamedQuery("RealizationEntity.findRealizationsByRuleIdAndEarnerIdAndReceiverAndObjectId",
Long.class);
query.setParameter(RULE_ID_PARAM_NAME, ruleId)
.setParameter(EARNER_ID_PARAM_NAME, earnerId)
.setParameter(RECEIVER_ID_PARAM_NAME, receiverId)
.setParameter(OBJECT_ID_PARAM_NAME, objectId)
.setParameter(OBJECT_TYPE_PARAM_NAME, objectType)
.setParameter(STATUS_PARAM_NAME, RealizationStatus.ACCEPTED);
.setParameter(STATUS_PARAM_NAME, List.of(RealizationStatus.ACCEPTED, RealizationStatus.PENDING));
query.setMaxResults(1);

List<Long> resultList = query.getResultList();
return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
return CollectionUtils.isEmpty(resultList) ? null : resultList.getFirst();
}

public List<Long> getRealizationsByObjectIdAndObjectType(String objectId, String objectType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@
+ " AND a.status = :status"
)
@NamedQuery(
name = "RealizationEntity.findReadlizationsByRuleIdAndEarnerIdAndReceiverAndObjectId",
query = "SELECT g.id FROM RealizationEntity g" +
" WHERE g.ruleEntity.id = :ruleId" +
" AND g.earnerId = :earnerId" +
" AND g.receiver = :receiverId" +
" AND g.objectId = :objectId" +
" AND g.objectType = :objectType" +
" AND g.status = :status" +
" ORDER BY g.id DESC"
name = "RealizationEntity.findRealizationsByRuleIdAndEarnerIdAndReceiverAndObjectId",
query = "SELECT g.id FROM RealizationEntity g"
+ " WHERE g.ruleEntity.id = :ruleId"
+ " AND g.earnerId = :earnerId"
+ " AND g.receiver = :receiverId"
+ " AND g.objectId = :objectId"
+ " AND g.objectType = :objectType"
+ " AND g.status IN (:status)"
+ " ORDER BY g.id DESC"
)
@NamedQuery(
name = "RealizationEntity.getRealizationsByObjectIdAndObjectType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public List<RealizationDTO> cancelRealizations(String event,
return Collections.emptyList();
}
return rules.stream()
.map(rule -> realizationStorage.findLastReadlizationByRuleIdAndEarnerIdAndReceiverAndObjectId(rule.getId(),
.map(rule -> realizationStorage.findLastRealizationByRuleIdAndEarnerIdAndReceiverAndObjectId(rule.getId(),
earnerIdentityId,
receiverIdentityId,
objectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ public Map<Long, Long> getScoresByIdentityIdsAndBetweenDates(List<String> earner
return gamificationHistoryDAO.getScoreByIdentityIdsAndBetweenDates(earnersId, fromDate, toDate);
}

public RealizationDTO findLastReadlizationByRuleIdAndEarnerIdAndReceiverAndObjectId(long ruleId,
String earnerId,
String receiverId,
String objectId,
String objectType) {
Long id = gamificationHistoryDAO.findLastReadlizationByRuleIdAndEarnerIdAndReceiverAndObjectId(ruleId,
earnerId,
receiverId,
objectId,
objectType);
public RealizationDTO findLastRealizationByRuleIdAndEarnerIdAndReceiverAndObjectId(long ruleId,
String earnerId,
String receiverId,
String objectId,
String objectType) {
Long id = gamificationHistoryDAO.findLastRealizationByRuleIdAndEarnerIdAndReceiverAndObjectId(ruleId,
earnerId,
receiverId,
objectId,
objectType);
return id == null || id == 0 ? null : getRealizationById(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testGetLeaderboard() {
public void testFindActionHistoryByActionTitleAndEarnerIdAndReceiverAndObjectId() {
ProgramEntity domainEntity = newDomain();
RealizationEntity realizationEntity = newRealizationEntity("rule", domainEntity.getId());
assertNotNull(realizationDAO.findLastReadlizationByRuleIdAndEarnerIdAndReceiverAndObjectId(realizationEntity.getRuleEntity()
assertNotNull(realizationDAO.findLastRealizationByRuleIdAndEarnerIdAndReceiverAndObjectId(realizationEntity.getRuleEntity()
.getId(),
TEST_USER_EARNER,
TEST_USER_EARNER,
Expand Down

0 comments on commit 827fe7a

Please sign in to comment.