This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects

Resolve "Fixing Problem with duplicate Entry in Statistics"

Viewing commit ccca99ca
Show latest version
1 file
+ 11
13
Compare changes
  • Side-by-side
  • Inline
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
* {@link at.ac.uibk.gitsearch.domain.Statistics}.
*/
@Service
@SuppressWarnings("PMD.TooManyMethods")
public class StatisticsService {
private final Logger log = LoggerFactory.getLogger(StatisticsService.class);
@@ -85,7 +86,7 @@ public class StatisticsService {
public Optional<StatisticsDTO> findOneByExerciseID(String id) {
log.debug("Request to get Statistics : {}", id);
final List<Statistics> hits = statisticsRepository.findByExerciseID(id);
if (hits.size() == 0) {
if (hits.isEmpty()) {
return Optional.empty();
} else if (hits.size() > 1) {
log.error(
@@ -118,7 +119,7 @@ public class StatisticsService {
@Transactional
public Stream<Statistics> findStatisticsOrphans() {
final Stream<Statistics> streamStatisticsOrphans = statisticsRepository
return statisticsRepository
.streamAll()
.filter(stats -> {
try {
@@ -133,7 +134,6 @@ public class StatisticsService {
}
return false;
});
return streamStatisticsOrphans;
}
public void cleanUpDuplicates() {
@@ -177,16 +177,14 @@ public class StatisticsService {
public Optional<Statistics> getStatistics(String exerciseID) {
List<Statistics> statistics = statisticsRepository.findByExerciseID(exerciseID);
if (statistics.size() == 0) {
if (statistics.isEmpty()) {
return Optional.empty();
}
if (statistics.size() > 0) {
if (statistics.size() > 1) {
log.error(
"There are duplicate statistic entries {}!",
statistics.stream().map(e -> "id " + e.getId() + "/" + e.getExerciseID()).collect(Collectors.joining(", "))
);
}
if (statistics.size() > 1) {
log.error(
"There are duplicate statistic entries {}!",
statistics.stream().map(e -> "id " + e.getId() + "/" + e.getExerciseID()).collect(Collectors.joining(", "))
);
}
return Optional.of(statistics.get(statistics.size() - 1)); // return last
}
@@ -210,8 +208,8 @@ public class StatisticsService {
private void updateStatisticsForExercise(String exerciseID, StatisticsUpdater updater) {
List<Statistics> statistics = statisticsRepository.findByExerciseID(exerciseID);
Statistics entry = null;
if (statistics.size() == 0) {
Statistics entry;
if (statistics.isEmpty()) {
entry = new Statistics();
entry.setExerciseID(exerciseID);
entry.setViews(0);