mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 03:45:57 +00:00
[AB-xx] improving scheduling interface
moving renaming module to int removing duplicated starboard feature validator sonar fixes
This commit is contained in:
@@ -18,6 +18,7 @@ public interface StarboardPostReactionRepository extends JpaRepository<Starboard
|
||||
"FROM starboard_post_reaction r \n" +
|
||||
"INNER JOIN starboard_post p ON p.id = r.post_id\n" +
|
||||
"WHERE p.server_id = :serverId\n" +
|
||||
" AND p.ignored = false\n" +
|
||||
"GROUP BY r.reactor_user_in_server_id \n" +
|
||||
"ORDER BY starCount DESC \n" +
|
||||
"LIMIT :count", nativeQuery = true)
|
||||
@@ -34,6 +35,7 @@ public interface StarboardPostReactionRepository extends JpaRepository<Starboard
|
||||
"FROM starboard_post_reaction r \n" +
|
||||
"INNER JOIN starboard_post p ON p.id = r.post_id\n" +
|
||||
"WHERE p.server_id = :serverId\n" +
|
||||
" AND p.ignored = false\n" +
|
||||
"GROUP BY p.author_user_in_server_id \n" +
|
||||
"ORDER BY starCount DESC \n" +
|
||||
"LIMIT :count", nativeQuery = true)
|
||||
|
||||
@@ -23,6 +23,7 @@ public interface StarboardPostRepository extends JpaRepository<StarboardPost, Lo
|
||||
" INNER JOIN starboard_post_reaction r ON p.id = r.post_id\n" +
|
||||
" INNER JOIN user_in_server usi ON usi.user_in_server_id = p.author_user_in_server_id\n" +
|
||||
" WHERE p.server_id = :serverId\n" +
|
||||
" AND p.ignored = false\n" +
|
||||
" AND usi.user_id = :userId\n" +
|
||||
" GROUP BY p.id \n" +
|
||||
" ORDER BY starCount DESC \n" +
|
||||
@@ -31,8 +32,10 @@ public interface StarboardPostRepository extends JpaRepository<StarboardPost, Lo
|
||||
|
||||
@Query(value = "SELECT COUNT(*) AS starCount\n" +
|
||||
"FROM starboard_post_reaction r \n" +
|
||||
" INNER JOIN starboard_post p ON p.id = r.post_id \n" +
|
||||
" INNER JOIN user_in_server usi ON usi.user_in_server_id = r.reactor_user_in_server_id \n" +
|
||||
" WHERE usi.user_id = :userId \n" +
|
||||
" AND p.ignored = false\n" +
|
||||
" AND r.server_id = :serverId", nativeQuery = true)
|
||||
Long getGivenStarsOfUserInServer(Long serverId, Long userId);
|
||||
|
||||
@@ -42,6 +45,7 @@ public interface StarboardPostRepository extends JpaRepository<StarboardPost, Lo
|
||||
" INNER JOIN user_in_server usi ON usi.user_in_server_id = p.author_user_in_server_id \n" +
|
||||
" WHERE p.author_user_in_server_id = usi.user_in_server_id \n" +
|
||||
" AND usi.user_id = :userId \n" +
|
||||
" AND p.ignored = false\n" +
|
||||
" AND r.server_id = :serverId", nativeQuery = true)
|
||||
Long getReceivedStarsOfUserInServer(Long serverId, Long userId);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.core.service.GuildService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
@@ -21,7 +22,6 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -94,9 +95,10 @@ public class RemindServiceBean implements ReminderService {
|
||||
}
|
||||
}, remindIn.toNanos(), TimeUnit.NANOSECONDS);
|
||||
} else {
|
||||
JobDataMap parameters = new JobDataMap();
|
||||
parameters.putAsString("reminderId", reminder.getId());
|
||||
String triggerKey = schedulerService.executeJobWithParametersOnce("reminderJob", "utility", parameters, Date.from(reminder.getTargetDate()));
|
||||
HashMap<Object, Object> parameters = new HashMap<>();
|
||||
parameters.put("reminderId", reminder.getId());
|
||||
JobParameters jobParameters = JobParameters.builder().parameters(parameters).build();
|
||||
String triggerKey = schedulerService.executeJobWithParametersOnce("reminderJob", "utility", jobParameters, Date.from(reminder.getTargetDate()));
|
||||
log.info("Starting scheduled job with trigger {} to execute reminder. {}", triggerKey, reminder.getId());
|
||||
reminder.setJobTriggerKey(triggerKey);
|
||||
reminderManagementService.saveReminder(reminder);
|
||||
|
||||
@@ -49,6 +49,11 @@ public class StarboardPostManagementServiceBean implements StarboardPostManageme
|
||||
return post;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StarboardPost createStarboardPost(StarboardPost post) {
|
||||
return repository.save(post);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStarboardPostMessageId(StarboardPost post, Long messageId) {
|
||||
post.setStarboardMessageId(messageId);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class StarboardPostReactorManagementServiceBean implements StarboardPostR
|
||||
private StarStatsUserConverter converter;
|
||||
|
||||
@Override
|
||||
public void addReactor(StarboardPost post, AUserInAServer user) {
|
||||
public StarboardPostReaction addReactor(StarboardPost post, AUserInAServer user) {
|
||||
StarboardPostReaction reactor = StarboardPostReaction
|
||||
.builder()
|
||||
.starboardPost(post)
|
||||
@@ -34,6 +34,7 @@ public class StarboardPostReactorManagementServiceBean implements StarboardPostR
|
||||
.build();
|
||||
log.info("Persisting the reactor {} for starboard post {} in server {}.", user.getUserReference().getId(), post.getId(), user.getServerReference().getId());
|
||||
repository.save(reactor);
|
||||
return reactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package dev.sheldan.abstracto.utility.validator;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.models.FeatureValidationResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.FeatureValidatorService;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||
import dev.sheldan.abstracto.utility.StarboardFeatureValidator;
|
||||
import dev.sheldan.abstracto.utility.config.features.StarboardFeature;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StarboardFeatureValidatorService implements StarboardFeatureValidator {
|
||||
|
||||
@Autowired
|
||||
private FeatureValidatorService featureValidatorService;
|
||||
|
||||
@Autowired
|
||||
private DefaultConfigManagementService defaultConfigManagementService;
|
||||
|
||||
@Override
|
||||
public void featureIsSetup(FeatureConfig featureConfig, AServer server, FeatureValidationResult validationResult) {
|
||||
int levelAmount = defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LEVELS_CONFIG_KEY).getLongValue().intValue();
|
||||
log.info("Validating starboard feature for server {}.", server.getId());
|
||||
for(int i = 1; i <= levelAmount; i++) {
|
||||
featureValidatorService.checkSystemConfig(StarboardFeature.STAR_LVL_CONFIG_PREFIX + i, server, validationResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user