Skip to content

Commit

Permalink
Fixes #198
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph-Meyer committed Mar 25, 2019
1 parent 456c443 commit 5a17c14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class ExternalRessourceService {
@Autowired
private RestTemplateService restTemplateService;

@Autowired
private GratificationService gratificationService;

private static final Logger LOGGER = LoggerFactory.getLogger(ExternalRessourceService.class);

private static final String ERROR_NO_CONNECTION = "No connection to backend - please adjust the url to the SonarQube server";
Expand Down Expand Up @@ -94,6 +97,7 @@ public List<StandardTask> generateStandardTasksFromSonarQubeIssuesForWorld(final
standardTasks = sonarQubeIssues.stream().map(sonarQubeIssue -> toTask(sonarQubeIssue, world))
.collect(Collectors.toList());
}
LOGGER.info("Mapping done.");
return standardTasks;
}

Expand All @@ -106,18 +110,22 @@ private StandardTask toTask(final SonarQubeIssue sonarQubeIssue, final World wor
}

private StandardTask loadTask(final SonarQubeIssue sonarQubeIssue, final World world, final Long gold,
final Long xp, final Integer debt, final SonarQuestStatus status) {
StandardTask sonarQubeTask = standardTaskRepository.findByKey(sonarQubeIssue.getKey());
if (sonarQubeTask == null) {
final Long xp, final Integer debt, final SonarQuestStatus newStatus) {
StandardTask savedTask = standardTaskRepository.findByKey(sonarQubeIssue.getKey());
if (savedTask == null) {
// new issue from SonarQube: Create new task
sonarQubeTask = new StandardTask(sonarQubeIssue.getMessage(), status, gold, xp, null, world,
savedTask = new StandardTask(sonarQubeIssue.getMessage(), newStatus, gold, xp, null, world,
sonarQubeIssue.getKey(), sonarQubeIssue.getComponent(), sonarQubeIssue.getSeverity(),
sonarQubeIssue.getType(), debt, sonarQubeIssue.getKey());
} else {
// issue already in SonarQuest database: update the task
sonarQubeTask.setStatus(status);
}
return sonarQubeTask;
else {
final SonarQuestStatus lastStatus = savedTask.getStatus();
if (newStatus == SonarQuestStatus.SOLVED && lastStatus == SonarQuestStatus.OPEN) {
gratificationService.rewardUserForSolvingTask(savedTask);
}
savedTask.setStatus(newStatus);
}
return savedTask;
}

public List<SonarQubeProject> getSonarQubeProjects() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.viadee.sonarquest.entities.Task;
import com.viadee.sonarquest.entities.User;
import com.viadee.sonarquest.interfaces.UserGratification;
import com.viadee.sonarquest.repositories.StandardTaskRepository;

@Service
public class GratificationService implements UserGratification {
Expand All @@ -34,11 +35,15 @@ public class GratificationService implements UserGratification {
@Autowired
private LevelService levelService;

@Autowired
private StandardTaskRepository taskRepo;

private static final Logger LOGGER = LoggerFactory.getLogger(GratificationService.class);

@Override
@Transactional
public synchronized void rewardUserForSolvingTask(final Task task) {
LOGGER.debug("Task ID {} has changed the status from OPEN to SOLVED, rewarding users...", task.getId());
final Participation participation = task.getParticipation();
if (participation != null) {
final User user = participation.getUser();
Expand All @@ -49,6 +54,8 @@ public synchronized void rewardUserForSolvingTask(final Task task) {
addSkillReward(user);
user.setLevel(levelService.getLevelByUserXp(user.getXp()));
userService.save(user);
} else {
LOGGER.info("No SQUser participations found for task {}, so no rewards are paid out", task.getKey());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public class StandardTaskService {
@Autowired
private ExternalRessourceService externalRessourceService;

@Autowired
private GratificationService gratificationService;

@Autowired
private StandardTaskRepository standardTaskRepository;

Expand All @@ -38,6 +35,9 @@ public class StandardTaskService {
@Autowired
private WorldRepository worldRepository;

@Autowired
private GratificationService gratificationService;

@Autowired
private NamedParameterJdbcTemplate template;

Expand All @@ -50,6 +50,7 @@ public void updateStandardTasks(final World world) {
adventureService.updateAdventures();
}

@Transactional
public StandardTask updateStandardTask(final StandardTask task) {
final SonarQuestStatus oldStatus = getLastState(task);
final SonarQuestStatus newStatus = task.getStatus();
Expand All @@ -73,6 +74,7 @@ public void setExternalRessourceService(final ExternalRessourceService externalR
this.externalRessourceService = externalRessourceService;
}

@Transactional
public void save(final StandardTask standardTask) {
final World world = worldRepository.findByProject(standardTask.getWorld().getProject());
final StandardTask st = new StandardTask(
Expand Down

0 comments on commit 5a17c14

Please sign in to comment.