Skip to content

Commit 0e05d25

Browse files
authored
feat: Improve TranslationService API with Object Id of Type String - MEED-9632 - Meeds-io/meeds#3608 (#1954)
This change will enhance `TranslationService` by accepting the `objectId` of type `String` in addition to type `Long`.
1 parent 42519b6 commit 0e05d25

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

services/src/main/java/io/meeds/gamification/plugin/ProgramTranslationPlugin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@ public String getObjectType() {
7272
}
7373

7474
@Override
75-
public boolean hasAccessPermission(long programId, String username) throws ObjectNotFoundException {
76-
return userACL.hasAccessPermission(PROGRAM_OBJECT_TYPE, String.valueOf(programId), username);
75+
public boolean hasAccessPermission(String programId, String username) throws ObjectNotFoundException {
76+
return userACL.hasAccessPermission(PROGRAM_OBJECT_TYPE, programId, username);
7777
}
7878

7979
@Override
80-
public boolean hasEditPermission(long programId, String username) throws ObjectNotFoundException {
81-
return userACL.hasEditPermission(PROGRAM_OBJECT_TYPE, String.valueOf(programId), username);
80+
public boolean hasEditPermission(String programId, String username) throws ObjectNotFoundException {
81+
return userACL.hasEditPermission(PROGRAM_OBJECT_TYPE, programId, username);
8282
}
8383

8484
@Override
85-
public long getAudienceId(long programId) throws ObjectNotFoundException {
85+
public long getAudienceId(String programId) throws ObjectNotFoundException {
8686
long spaceId = getSpaceId(programId);
8787
if (spaceId == 0) {
8888
return 0;
8989
}
90-
Space space = spaceService.getSpaceById(String.valueOf(spaceId));
90+
Space space = spaceService.getSpaceById(spaceId);
9191
if (space == null) {
9292
throw new ObjectNotFoundException(String.format("Space with id %s wasn't found",
9393
spaceId));
@@ -97,8 +97,8 @@ public long getAudienceId(long programId) throws ObjectNotFoundException {
9797
}
9898

9999
@Override
100-
public long getSpaceId(long programId) throws ObjectNotFoundException {
101-
ProgramDTO program = this.programService.getProgramById(programId);
100+
public long getSpaceId(String programId) throws ObjectNotFoundException {
101+
ProgramDTO program = this.programService.getProgramById(Long.parseLong(programId));
102102
if (program == null) {
103103
throw new ObjectNotFoundException(String.format("Program with id %s wasn't found",
104104
programId));

services/src/main/java/io/meeds/gamification/plugin/RuleTranslationPlugin.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ public String getObjectType() {
7272
}
7373

7474
@Override
75-
public boolean hasAccessPermission(long ruleId, String username) throws ObjectNotFoundException {
76-
return userACL.hasAccessPermission(RULE_OBJECT_TYPE, String.valueOf(ruleId), username);
75+
public boolean hasAccessPermission(String ruleId, String username) throws ObjectNotFoundException {
76+
return userACL.hasAccessPermission(RULE_OBJECT_TYPE, ruleId, username);
7777
}
7878

7979
@Override
80-
public boolean hasEditPermission(long ruleId, String username) throws ObjectNotFoundException {
81-
return userACL.hasEditPermission(RULE_OBJECT_TYPE, String.valueOf(ruleId), username);
80+
public boolean hasEditPermission(String ruleId, String username) throws ObjectNotFoundException {
81+
return userACL.hasEditPermission(RULE_OBJECT_TYPE, ruleId, username);
8282
}
8383

8484
@Override
85-
public long getAudienceId(long ruleId) throws ObjectNotFoundException {
85+
public long getAudienceId(String ruleId) throws ObjectNotFoundException {
8686
long spaceId = getSpaceId(ruleId);
8787
if (spaceId == 0) {
8888
return 0;
@@ -97,8 +97,8 @@ public long getAudienceId(long ruleId) throws ObjectNotFoundException {
9797
}
9898

9999
@Override
100-
public long getSpaceId(long ruleId) throws ObjectNotFoundException {
101-
RuleDTO rule = this.ruleService.findRuleById(ruleId);
100+
public long getSpaceId(String ruleId) throws ObjectNotFoundException {
101+
RuleDTO rule = this.ruleService.findRuleById(Long.parseLong(ruleId));
102102
if (rule == null) {
103103
throw new ObjectNotFoundException(String.format("Rule with id %s wasn't found",
104104
ruleId));

services/src/test/java/io/meeds/gamification/mock/SpaceServiceMock.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public Space getSpaceByGroupId(String groupId) {
7373
}
7474
}
7575

76+
public Space getSpaceById(long spaceId) {
77+
return getSpaceById(String.valueOf(spaceId));
78+
}
79+
7680
public Space getSpaceById(String spaceId) {
7781
if (!SPACE_ID_1.equals(spaceId) && !SPACE_ID_2.equals(spaceId)) {
7882
return null;

services/src/test/java/io/meeds/gamification/plugin/ProgramTranslationPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void testManageTranslations() throws IllegalAccessException, ObjectNotFou
108108
TITLE,
109109
adminAclIdentity.getUserId());
110110
assertNotNull(translationField);
111-
assertEquals(programId, translationField.getObjectId());
111+
assertEquals(String.valueOf(programId), translationField.getObjectId());
112112
assertEquals(ProgramTranslationPlugin.PROGRAM_OBJECT_TYPE, translationField.getObjectType());
113113
assertEquals(translationField.getLabels().get(Locale.ENGLISH), LABEL);
114114
}

services/src/test/java/io/meeds/gamification/plugin/RuleTranslationPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void testManageTranslations() throws IllegalAccessException, ObjectNotFou
106106
TITLE,
107107
adminAclIdentity.getUserId());
108108
assertNotNull(translationField);
109-
assertEquals(ruleId, translationField.getObjectId());
109+
assertEquals(String.valueOf(ruleId), translationField.getObjectId());
110110
assertEquals(RuleTranslationPlugin.RULE_OBJECT_TYPE, translationField.getObjectType());
111111
assertEquals(translationField.getLabels().get(Locale.ENGLISH), LABEL);
112112
}

0 commit comments

Comments
 (0)