updated javadoc for experience tracking

added/changed some javadoc for mod mail
some small interface changes
changed a few methods to actually use the exists mechanic, instead of checking for null values
added some templates instead of hard coded strings
fixed some bugs related to mod mail
This commit is contained in:
Sheldan
2020-06-13 00:51:50 +02:00
parent e76351ddc1
commit 19a7d09576
111 changed files with 1238 additions and 162 deletions

View File

@@ -16,6 +16,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to add a role to the roles for which experience has been disabled.
*/
@Component
public class DisableExpForRole extends AbstractConditionableCommand {

View File

@@ -18,6 +18,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to disable the experience gain for a specific member
*/
@Component
public class DisableExpGain extends AbstractConditionableCommand {

View File

@@ -16,6 +16,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to remove a role from the list of roles for which experience is disabled
*/
@Component
public class EnableExpForRole extends AbstractConditionableCommand {

View File

@@ -18,6 +18,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command to enable experience again for a member
*/
@Component
public class EnableExpGain extends AbstractConditionableCommand {

View File

@@ -16,6 +16,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to change the experience multiplier on the server.
*/
@Component
@Slf4j
public class ExpScale extends AbstractConditionableCommand {

View File

@@ -24,6 +24,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Shows the experience gain information of the top 10 users in the server, or if a page number is provided as a parameter, only the members which are on this page.
*/
@Component
@Slf4j
public class LeaderBoardCommand extends AbstractConditionableCommand {

View File

@@ -22,6 +22,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Creates an embed containing the roles for which the experience gain has been disabled.
*/
@Component
public class ListDisabledExperienceRoles extends AbstractConditionableCommand {

View File

@@ -24,6 +24,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to show an embed containing information about the experience amount, level and message count of a ember on a server
*/
@Component
public class Rank extends AbstractConditionableCommand {

View File

@@ -20,6 +20,9 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to define which commands are to be awarded at which level
*/
@Component
@Slf4j
public class SetExpRole extends AbstractConditionableCommand {

View File

@@ -17,6 +17,12 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to synchronize the actual awarded roles which what is defined to be awarded in the database.
* This also calculates the appropriate role for each user and then awards the role, while removing the previously awarded role.
* The synchronization is usually a longer process, and there is a status message to see how far this progress is.
*
*/
@Component
@Slf4j
public class SyncRoles extends AbstractConditionableCommand {

View File

@@ -16,6 +16,10 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Command used to remove a role from the roles to be awarded at certain levels. If there are users with this role currently, their role
* will be recalculated, and this will be shown with an status update message.
*/
@Component
public class UnSetExpRole extends AbstractConditionableCommand {

View File

@@ -26,7 +26,8 @@ public class ExperienceConfig {
private Double expMultiplier;
/**
* The defaul maxLevel from the properties file. This configuration applies globally, as the amount of levels does not depend on the server.
* The default maxLevel from the properties file. This configuration applies globally, as the amount of levels does not depend on the server.
* This is only used once, when creating the {@link dev.sheldan.abstracto.experience.models.database.AExperienceLevel} once
*/
private Integer maxLvl;
}

View File

@@ -8,7 +8,11 @@ import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Bean used to define the default values for the required configuration in the experience module.
* This {@link dev.sheldan.abstracto.core.models.database.ADefaultConfig} is used, when a config key in a module is set to the default value
* This service only creates a value if no one is previously there.
*/
@Component
public class ExperienceDefaultConfigListener {

View File

@@ -24,7 +24,7 @@ public class ExperienceLevelLoader {
@EventListener
public void handleContextRefreshEvent(ContextRefreshedEvent ctxStartEvt) {
Integer maxLevel = experienceConfig.getMaxLvl();
log.info("Setting up experience level configuration.");
log.info("Creating experience levels up to level {}", maxLevel);
experienceLevelService.createLevelsUntil(maxLevel);
}
}

View File

@@ -13,7 +13,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Converter used to conver from {@link LeaderBoard} to a list of {@link LeaderBoardEntryModel}
* Converter used to convert from {@link LeaderBoard} to a list of {@link LeaderBoardEntryModel}
*/
@Component
public class LeaderBoardModelConverter {
@@ -23,10 +23,10 @@ public class LeaderBoardModelConverter {
/**
* Converts the complete {@link LeaderBoard} into a list of {@link LeaderBoardEntryModel} which contain additional
* information available for rendering the leaderboard ({@link Member} reference)
* information available for rendering the leader board ({@link Member} reference and more)
* @param leaderBoard The {@link LeaderBoard} object to be converted
* @return The list of {@link LeaderBoardEntryModel} which contain the fully fledged information provided to the
* leaderboard template
* leader board template
*/
public List<LeaderBoardEntryModel> fromLeaderBoard(LeaderBoard leaderBoard) {
List<LeaderBoardEntryModel> models = new ArrayList<>();

View File

@@ -8,6 +8,9 @@ import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Repository to manage the access to the table managed by {@link ADisabledExpRole}
*/
@Repository
public interface DisabledExpRoleRepository extends JpaRepository<ADisabledExpRole, Long> {
boolean existsByRole(ARole role);

View File

@@ -39,6 +39,8 @@ public interface UserExperienceRepository extends JpaRepository<AUserExperience
/**
* This returns the {@link LeaderBoardEntryResult} object containing the information about the rank of a user in a server.
* This query selects all the experience entries and returns the one associated with the provided user.
* We need to select all of them, in order to find the rank of the member in the server
* @param id The {@link dev.sheldan.abstracto.core.models.database.AUserInAServer} id to search for
* @return the {@link LeaderBoardEntryResult} of this {@link dev.sheldan.abstracto.core.models.database.AUserInAServer}
* containing rank and experience information
@@ -50,6 +52,6 @@ public interface UserExperienceRepository extends JpaRepository<AUserExperience
") " +
"SELECT rank.id as \"id\", rank.experience as \"experience\", rank.message_count as \"messageCount\", rank.level_id as \"level\", rank.row_number as \"rank\" " +
"FROM user_experience_ranked rank " +
"where rank.id = :userInServerId", nativeQuery = true)
"WHERE rank.id = :userInServerId", nativeQuery = true)
LeaderBoardEntryResult getRankOfUserInServer(@Param("userInServerId") Long id);
}

View File

@@ -103,7 +103,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
/**
* Calculates the level of the given {@link AUserExperience} accoring to the given {@link AExperienceLevel} list
* Calculates the level of the given {@link AUserExperience} according to the given {@link AExperienceLevel} list
* @param experience The {@link AUserExperience} to calculate the level for
* @param levels The list of {@link AExperienceLevel} representing the level configuration, this must include the initial level 0
* * This level will be taken as the initial value, and if no other level qualifies, this will be taken.
@@ -243,6 +243,12 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
executeActionOnUserExperiencesWithFeedBack(aUserExperiences, channel, (AUserExperience experience) -> updateUserRole(experience, roles));
}
/**
* Executes the given {@link Consumer} on each of the experiences and provides feedback in the given AChannel in the form of a status message
* @param experiences The list of {@link AUserExperience} to be working on
* @param channel The {@link AChannel} used to provide feedback to the user
* @param toExecute The {@link Consumer} which should be executed on each element of the passed list
*/
@Override
public void executeActionOnUserExperiencesWithFeedBack(List<AUserExperience> experiences, AChannel channel, Consumer<AUserExperience> toExecute) {
MessageToSend status = getUserSyncStatusUpdateModel(0, experiences.size());
@@ -308,7 +314,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
}
page--;
int pageSize = 10;
List<AUserExperience> experiences = userExperienceManagementService.findLeaderboardUsersPaginated(server, page * pageSize, (page + 1) * pageSize);
List<AUserExperience> experiences = userExperienceManagementService.findLeaderBoardUsersPaginated(server, page * pageSize, (page + 1) * pageSize);
List<LeaderBoardEntry> entries = new ArrayList<>();
for (int i = 0; i < experiences.size(); i++) {
AUserExperience userExperience = experiences.get(i);

View File

@@ -14,6 +14,11 @@ public class ExperienceLevelServiceBean implements ExperienceLevelService {
@Autowired
private ExperienceLevelManagementService experienceLevelManagementService;
/**
* Creates experience level if it does not yet exist.
* @param level The level to create
* @param experienceNeeded The total amount of experience needed to reach the given level
*/
private void createExperienceLevel(Integer level, Long experienceNeeded) {
if(!experienceLevelManagementService.levelExists(level)) {
log.trace("Creating new experience level {} with experience needed {}.", level, experienceNeeded);
@@ -41,6 +46,7 @@ public class ExperienceLevelServiceBean implements ExperienceLevelService {
* @param level The level to calculate the experience amount for
* @return The needed experience to reach this level, if the user already has the level below the passed one
*/
@Override
public Long calculateExperienceForLevel(Integer level) {
if(level < 0) {
throw new IllegalArgumentException("Level should not be less to 0.");

View File

@@ -19,7 +19,7 @@ public class ExperienceRoleManagementServiceBean implements ExperienceRoleManage
private ExperienceRoleRepository experienceRoleRepository;
/**
* Removes all assignments of roles for the given level
* Removes *all* assignments of roles for the given level
* @param level The level to remove the roles for
* @param server The server in which this should happen
*/
@@ -45,6 +45,12 @@ public class ExperienceRoleManagementServiceBean implements ExperienceRoleManage
return experienceRoleRepository.findByRoleServer(server);
}
/**
* Creates a new role if nothing is found, and if its found the experience role will be set to the given level.
* @param level The {@link AExperienceLevel} to set the role for
* @param role The {@link ARole} to set to
* @return The created/updated {@link AExperienceRole}
*/
@Override
public AExperienceRole setLevelToRole(AExperienceLevel level, ARole role) {
AExperienceRole byRoleServerAndRole = experienceRoleRepository.findByRole(role);

View File

@@ -30,6 +30,11 @@ public class UserExperienceManagementServiceBean implements UserExperienceManage
return byId.orElseGet(() -> createUserInServer(aUserInAServer));
}
/**
* Initializes the {@link AUserExperience} with default values the following: 0 experience, 0 messages and experience gain enabled
* @param aUserInAServer The {@link AUserInAServer} to create the {@link AUserExperience} object for.
* @return The created/changed {@link AUserExperience} object
*/
@Override
public AUserExperience createUserInServer(AUserInAServer aUserInAServer) {
AExperienceLevel startingLevel = experienceLevelManagementService.getLevel(0).orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find level %s", 0)));
@@ -81,7 +86,7 @@ public class UserExperienceManagementServiceBean implements UserExperienceManage
}
@Override
public List<AUserExperience> findLeaderboardUsersPaginated(AServer aServer, Integer start, Integer end) {
public List<AUserExperience> findLeaderBoardUsersPaginated(AServer aServer, Integer start, Integer end) {
return repository.findTop10ByUser_ServerReferenceOrderByExperienceDesc(aServer, PageRequest.of(start, end));
}