Search in sources :

Example 1 with Participation

use of com.viadee.sonarQuest.entities.Participation in project sonarQuest by viadee.

the class TaskController method addParticipation.

@RequestMapping(value = "/{taskId}/addParticipation/{questId}/{developerId}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public TaskDto addParticipation(@PathVariable(value = "taskId") final Long taskId, @PathVariable(value = "questId") final Long questId, @PathVariable(value = "developerId") final Long developerId) {
    Task task = this.taskRepository.findOne(taskId);
    final Participation participation = participationService.findParticipationByQuestIdAndDeveloperId(questId, developerId);
    if (task != null && participation != null) {
        task.setParticipation(participation);
        task.setStatus(TaskStates.PROCESSED);
        task = this.taskRepository.save(task);
    }
    return toTaskDto(task);
}
Also used : Participation(com.viadee.sonarQuest.entities.Participation) SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) Task(com.viadee.sonarQuest.entities.Task) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Participation

use of com.viadee.sonarQuest.entities.Participation in project sonarQuest by viadee.

the class ParticipationController method createParticipation.

@CrossOrigin
@RequestMapping(value = "/{questid}/{developerid}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public Participation createParticipation(@PathVariable(value = "questid") Long questid, @PathVariable(value = "developerid") Long developerid) {
    Quest foundQuest = questRepository.findOne(questid);
    Developer foundDeveloper = developerRepository.findOne(developerid);
    Participation foundParticipation = participationRepository.findByQuestAndDeveloper(foundQuest, foundDeveloper);
    Participation participation = null;
    if ((foundQuest != null) && (foundDeveloper != null) && (foundParticipation == null)) {
        participation = new Participation(foundQuest, foundDeveloper);
        participation = participationRepository.save(participation);
    }
    return participation;
}
Also used : Participation(com.viadee.sonarQuest.entities.Participation) Developer(com.viadee.sonarQuest.entities.Developer) Quest(com.viadee.sonarQuest.entities.Quest)

Example 3 with Participation

use of com.viadee.sonarQuest.entities.Participation in project sonarQuest by viadee.

the class GratificationService method rewardDeveloperForSolvingTask.

@Override
public void rewardDeveloperForSolvingTask(final Task task) {
    final Participation participation = task.getParticipation();
    if (participation != null) {
        Developer developer = participation.getDeveloper();
        final Developer developer1 = developer;
        final Developer rewardedDeveloper = developer1;
        rewardedDeveloper.addXp(task.getXp());
        rewardedDeveloper.addGold(task.getGold());
        developer = rewardedDeveloper;
        developer = addSkillReward(developer, task);
        developer.setLevel(levelService.getLevelByDeveloperXp(developer.getXp()));
        developerRepository.save(developer);
    }
}
Also used : Participation(com.viadee.sonarQuest.entities.Participation) Developer(com.viadee.sonarQuest.entities.Developer)

Example 4 with Participation

use of com.viadee.sonarQuest.entities.Participation in project sonarQuest by viadee.

the class ParticipationService method findParticipationByQuestIdAndDeveloperId.

public Participation findParticipationByQuestIdAndDeveloperId(Long questId, Long developerId) {
    Quest foundQuest = questRepository.findOne(questId);
    Developer foundDeveloper = developerRepository.findOne(developerId);
    Participation foundParticipation = null;
    if ((foundQuest != null) && (foundDeveloper != null)) {
        foundParticipation = participationRepository.findByQuestAndDeveloper(foundQuest, foundDeveloper);
    }
    return foundParticipation;
}
Also used : Participation(com.viadee.sonarQuest.entities.Participation) Developer(com.viadee.sonarQuest.entities.Developer) Quest(com.viadee.sonarQuest.entities.Quest)

Example 5 with Participation

use of com.viadee.sonarQuest.entities.Participation in project sonarQuest by viadee.

the class SonarQuestApplicationIT method developersCanParticipateInQuestsAndIssues.

/**
 * Walk through the participation on the backend with a developer perspective.
 * This test assumes a spring environment including a simulated sonar server and
 * database access.
 */
// There is hardly any data to fetch - this should be quick, altough there are
@Test(timeout = 1000)
public // write operations included
void developersCanParticipateInQuestsAndIssues() {
    // Join in on a quest.
    // Add Participation sonarHero123, Quest1
    participationController.createParticipation((long) 1, (long) 1);
    final Quest epicQuest = questRepository.findOne((long) 1);
    final List<Participation> participations = epicQuest.getParticipations();
    assertEquals("createParticipation does not work (Quest)", "Quest1", participations.get(0).getQuest().getTitle());
    assertEquals("createParticipation does not work (Developer)", "sonarHero123", participations.get(0).getDeveloper().getUsername());
    // Get to work on issue 1
    Task issue1 = taskRepository.findOne((long) 1);
    assertNull("addParticipationToTask does not work (Quest)", issue1.getParticipation());
    taskController.addParticipation((long) 1, (long) 1, (long) 1);
    issue1 = taskRepository.findOne((long) 1);
    assertEquals("addParticipation does not work (Quest)", "Quest1", issue1.getParticipation().getQuest().getTitle());
    assertEquals("addParticipation does not work (Developer)", "sonarHero123", issue1.getParticipation().getDeveloper().getUsername());
    assertEquals("addParticipation does not work (Status)", TaskStates.PROCESSED, issue1.getStatus());
    // no effect expected
    adventureService.updateAdventures();
}
Also used : Participation(com.viadee.sonarQuest.entities.Participation) Task(com.viadee.sonarQuest.entities.Task) Quest(com.viadee.sonarQuest.entities.Quest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Participation (com.viadee.sonarQuest.entities.Participation)6 Developer (com.viadee.sonarQuest.entities.Developer)4 Quest (com.viadee.sonarQuest.entities.Quest)4 Task (com.viadee.sonarQuest.entities.Task)2 Test (org.junit.Test)2 SpecialTask (com.viadee.sonarQuest.entities.SpecialTask)1 World (com.viadee.sonarQuest.entities.World)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1