Search in sources :

Example 6 with Developer

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

the class GratificationService method rewardDeveloperForSolvingAdventure.

private void rewardDeveloperForSolvingAdventure(final Developer developer, final Adventure adventure) {
    final Developer rewardedDeveloper = developer;
    rewardedDeveloper.addGold(adventure.getGold());
    rewardedDeveloper.addXp(adventure.getXp());
    rewardedDeveloper.setLevel(levelService.getLevelByDeveloperXp(developer.getXp()));
    developerRepository.save(rewardedDeveloper);
}
Also used : Developer(com.viadee.sonarQuest.entities.Developer)

Example 7 with Developer

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

the class GratificationService method rewardParticipation.

private void rewardParticipation(final Participation participation) {
    final Developer developer = participation.getDeveloper();
    final Quest quest = participation.getQuest();
    developer.addGold(quest.getGold());
    developer.addXp(quest.getXp());
    developer.setLevel(levelService.getLevelByDeveloperXp(developer.getXp()));
    developerRepository.save(developer);
}
Also used : Developer(com.viadee.sonarQuest.entities.Developer) Quest(com.viadee.sonarQuest.entities.Quest)

Example 8 with Developer

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

the class GratificationService method addSkillReward.

private Developer addSkillReward(final Developer developer, final Task task) {
    final Developer rewardedDeveloper = developer;
    final List<Skill> avatarClassSkills = rewardedDeveloper.getAvatarClass().getSkills();
    final List<Skill> artefactSkills = rewardedDeveloper.getArtefacts().stream().map(artefact -> artefact.getSkills()).flatMap(skills -> skills.stream()).collect(Collectors.toList());
    final List<Skill> totalSkills = new ArrayList<>();
    totalSkills.addAll(avatarClassSkills);
    totalSkills.addAll(artefactSkills);
    final Long extraGold = totalSkills.stream().filter(skill -> skill.getType().equals(SkillType.GOLD)).mapToLong(skill -> skill.getValue()).sum();
    final Long extraXP = totalSkills.stream().filter(skill -> skill.getType().equals(SkillType.XP)).mapToLong(skill -> skill.getValue()).sum();
    rewardedDeveloper.addGold(extraGold);
    rewardedDeveloper.addXp(extraXP);
    return rewardedDeveloper;
}
Also used : Developer(com.viadee.sonarQuest.entities.Developer) SkillType(com.viadee.sonarQuest.constants.SkillType) Participation(com.viadee.sonarQuest.entities.Participation) Autowired(org.springframework.beans.factory.annotation.Autowired) DeveloperRepository(com.viadee.sonarQuest.repositories.DeveloperRepository) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Adventure(com.viadee.sonarQuest.entities.Adventure) Skill(com.viadee.sonarQuest.entities.Skill) List(java.util.List) Service(org.springframework.stereotype.Service) Quest(com.viadee.sonarQuest.entities.Quest) Task(com.viadee.sonarQuest.entities.Task) DeveloperGratification(com.viadee.sonarQuest.interfaces.DeveloperGratification) Skill(com.viadee.sonarQuest.entities.Skill) ArrayList(java.util.ArrayList) Developer(com.viadee.sonarQuest.entities.Developer)

Example 9 with Developer

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

the class UserManagementIT method testCreateDeleteDeveloper.

@Test
public void testCreateDeleteDeveloper() {
    // Given
    DeveloperDto developerDto = new DeveloperDto("testusername");
    final long count = developerRepository.count();
    // When
    developerService.createDeveloper(developerDto);
    // Then
    Developer dev = developerRepository.findByUsername("testusername");
    assertNotNull("developer could not be created", dev);
    assertEquals("number of devs is inconsistent", developerRepository.count(), count + 1);
    assertFalse(dev.isDeleted());
    // When
    developerService.deleteDeveloper(dev);
    assertTrue("developer was not deleted", developerRepository.findByUsername("testusername").isDeleted());
    // since deleting is logical deleting and not physical
    assertEquals("number of devs is inconsistent", developerRepository.count(), count + 1);
    assertTrue(dev.isDeleted());
}
Also used : Developer(com.viadee.sonarQuest.entities.Developer) DeveloperDto(com.viadee.sonarQuest.dtos.DeveloperDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Developer

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

the class AdventureServiceTest method testGetAllAdventuresForWorldAndDeveloper.

@Test
public void testGetAllAdventuresForWorldAndDeveloper() {
    // create mock developer
    final Developer mockDeveloper1 = new Developer();
    mockDeveloper1.setUsername("mockUserAdventureServiceTest1");
    // create mock world
    final World mockWorld = new World();
    // create mock Adventure
    final Adventure mockAdventure1 = new Adventure();
    final Adventure mockAdventure2 = new Adventure();
    final Adventure mockAdventure3 = new Adventure();
    mockAdventure1.setTitle("mockAdventure1");
    mockAdventure2.setTitle("mockAdventure2");
    mockAdventure3.setTitle("mockAdventure3");
    mockAdventure1.setWorld(mockWorld);
    mockAdventure2.setWorld(mockWorld);
    mockAdventure3.setWorld(mockWorld);
    // a Adventure has a Developers
    mockAdventure1.addDeveloper(mockDeveloper1);
    mockAdventure2.addDeveloper(mockDeveloper1);
    // init mock repos
    final List<Adventure> adventuresByDeveloperAndWorld = new ArrayList<>();
    adventuresByDeveloperAndWorld.add(mockAdventure1);
    adventuresByDeveloperAndWorld.add(mockAdventure2);
    final List<Adventure> adventuresByWorld = new ArrayList<>();
    adventuresByWorld.add(mockAdventure1);
    adventuresByWorld.add(mockAdventure2);
    adventuresByWorld.add(mockAdventure3);
    final List<Developer> developers = new ArrayList<>();
    developers.add(mockDeveloper1);
    when(adventureRepository.findByDevelopersAndWorld(developers, mockWorld)).thenReturn(adventuresByDeveloperAndWorld);
    when(adventureRepository.findByWorld(mockWorld)).thenReturn(adventuresByWorld);
    // call method to be tested
    final List<Adventure> joinedAdventures = adventureService.getJoinedAdventuresForDeveloperInWorld(mockWorld, mockDeveloper1);
    final List<Adventure> freeAdventures = adventureService.getFreeAdventuresForDeveloperInWorld(mockWorld, mockDeveloper1);
    // verify result
    assertTrue(joinedAdventures.contains(mockAdventure1));
    assertTrue(joinedAdventures.contains(mockAdventure2));
    assertTrue(freeAdventures.contains(mockAdventure3));
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) ArrayList(java.util.ArrayList) Developer(com.viadee.sonarQuest.entities.Developer) World(com.viadee.sonarQuest.entities.World) Test(org.junit.Test)

Aggregations

Developer (com.viadee.sonarQuest.entities.Developer)21 World (com.viadee.sonarQuest.entities.World)7 Adventure (com.viadee.sonarQuest.entities.Adventure)6 Participation (com.viadee.sonarQuest.entities.Participation)5 Quest (com.viadee.sonarQuest.entities.Quest)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DeveloperDto (com.viadee.sonarQuest.dtos.DeveloperDto)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 SkillType (com.viadee.sonarQuest.constants.SkillType)1 Level (com.viadee.sonarQuest.entities.Level)1 Skill (com.viadee.sonarQuest.entities.Skill)1 Task (com.viadee.sonarQuest.entities.Task)1 DeveloperGratification (com.viadee.sonarQuest.interfaces.DeveloperGratification)1 DeveloperRepository (com.viadee.sonarQuest.repositories.DeveloperRepository)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1