Skip to content

Commit

Permalink
fix: Fix Export Manual Achievements - MEED-3104 - Meeds-io/MIPs#105 (#…
Browse files Browse the repository at this point in the history
…1400)

Prior to this change, when adding manual realizations, it can't be
exported. This is due to the fact that Event DTO is now an object and no
more a simple field. This change will add a nullability test on event
DTO before accesssing its title to add its as a field in the exported
XLS row.
  • Loading branch information
boubaker authored and exo-swf committed Feb 28, 2024
1 parent 2b2a6a5 commit 4e84a80
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,8 @@ private void appendRealizationRow(Sheet sheet, int rowIndex, CreationHelper help
&& realization.getRuleId() != 0 ? ruleService.findRuleById(realization.getRuleId())
: ruleService.findRuleByTitle(realization.getActionTitle());

String ruleTitle = rule == null ? null : rule.getEvent().getTitle();
String actionLabel = realization.getActionTitle() != null ? realization.getActionTitle() : ruleTitle;
String eventTitle = rule == null || rule.getEvent() == null ? null : rule.getEvent().getTitle();
String actionLabel = realization.getActionTitle() != null ? realization.getActionTitle() : eventTitle;
String programTitle = escapeIllegalCharacterInMessage(realization.getProgramLabel());
int cellIndex = 0;
row.createCell(cellIndex++).setCellValue(helper.createRichTextString(realization.getCreatedDate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.exoplatform.services.security.Identity;
import org.exoplatform.services.security.MembershipEntry;

import io.meeds.gamification.constant.EntityType;
import io.meeds.gamification.constant.IdentityType;
import io.meeds.gamification.constant.Period;
import io.meeds.gamification.constant.RealizationStatus;
Expand Down Expand Up @@ -752,8 +753,14 @@ public void testExportRealizations() throws IllegalAccessException, Exception {
.get(0);
realization2 = realizationService.getRealizationById(realization2.getId(), adminAclIdentity);

RealizationDTO realization3 = realizationService.getRealizationById(newRealizationEntity("Test Manual",
rule.getProgramId(),
true).getId(),
adminAclIdentity);
assertNotNull(realization3);

realizations = realizationDAO.findAll();
assertEquals(realizations.size(), 2);
assertEquals(realizations.size(), 3);

RealizationFilter filter = new RealizationFilter();
filter.setOwned(true);
Expand All @@ -764,7 +771,7 @@ public void testExportRealizations() throws IllegalAccessException, Exception {
assertNotNull(workbook);
Sheet sheet = workbook.getSheetAt(0);
assertNotNull(sheet);
assertEquals(2, sheet.getLastRowNum());
assertEquals(3, sheet.getLastRowNum());
Row header = sheet.getRow(0);
assertNotNull(header);
assertEquals(7, header.getLastCellNum());
Expand Down Expand Up @@ -794,6 +801,18 @@ public void testExportRealizations() throws IllegalAccessException, Exception {
assertEquals(realization2.getActionTitle(), row2.getCell(cellIndex++).getStringCellValue());
assertEquals(realization2.getActionScore(), row2.getCell(cellIndex++).getNumericCellValue(), 0d);
assertEquals(realization2.getStatus(), row2.getCell(cellIndex).getStringCellValue());

Row row3 = sheet.getRow(3);
assertNotNull(row3);
assertEquals(7, row3.getLastCellNum());
cellIndex = 0;
assertEquals(realization3.getCreatedDate(), row3.getCell(cellIndex++).getStringCellValue());
assertEquals(Utils.getUserFullName(realization3.getEarnerId()), row3.getCell(cellIndex++).getStringCellValue());
assertEquals(EntityType.MANUAL.name(), row3.getCell(cellIndex++).getStringCellValue());
assertEquals(realization3.getProgramLabel(), row3.getCell(cellIndex++).getStringCellValue());
assertEquals(realization3.getActionTitle(), row3.getCell(cellIndex++).getStringCellValue());
assertEquals(realization3.getActionScore(), row3.getCell(cellIndex++).getNumericCellValue(), 0d);
assertEquals(realization3.getStatus(), row3.getCell(cellIndex).getStringCellValue());
}

public void testGetRealizationsOnOpenProgram() throws IllegalAccessException, ObjectNotFoundException { // NOSONAR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ protected RuleEntity newManualRule(String name, long domainId) {
rule.setDescription(DESCRIPTION);
rule.setEnabled(true);
rule.setDeleted(false);
rule.setEventEntity(newEvent(name));
rule.setCreatedBy(TEST_USER_EARNER);
rule.setCreatedDate(new Date());
rule.setLastModifiedBy(TEST_USER_EARNER);
Expand Down Expand Up @@ -596,7 +595,11 @@ protected BadgeEntity newBadge(String name, long domainId) {
}

protected RealizationEntity newRealizationEntity(String ruleName, long domainId) {
RuleEntity rule = newRule(ruleName, domainId);
return newRealizationEntity(ruleName, domainId, false);
}

protected RealizationEntity newRealizationEntity(String ruleName, long domainId, boolean manual) {
RuleEntity rule = manual ? newManualRule(ruleName, domainId) : newRule(ruleName, domainId);
RealizationEntity gHistory = new RealizationEntity();
gHistory.setStatus(RealizationStatus.ACCEPTED);
gHistory.setDomain(rule.getDomainEntity().getTitle());
Expand Down

0 comments on commit 4e84a80

Please sign in to comment.