Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 2805/convert skills data structure #2810

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,33 @@ public class MemberSkill {
@Schema(description = "the last used date of the skill")
private LocalDate lastuseddate;

@Column(name="interested")
@TypeDef(type = DataType.BOOLEAN)
@Schema(description = "the member interest")
private boolean interested;

public MemberSkill() {
}

// Used in tests
public MemberSkill(UUID memberid, UUID skillid) {
this.memberid = memberid;
this.skillid = skillid;
}

// Used in tests
public MemberSkill(UUID id, UUID memberid, UUID skillid) {
this.id = id;
this.memberid = memberid;
this.skillid = skillid;
}

public MemberSkill(UUID memberid, UUID skillid, String skilllevel, LocalDate lastuseddate) {
public MemberSkill(UUID memberid, UUID skillid, String skilllevel, LocalDate lastuseddate, boolean interested) {
this.memberid = memberid;
this.skillid = skillid;
this.skilllevel = skilllevel;
this.lastuseddate = lastuseddate;
this.interested = interested;
}

@Override
Expand All @@ -84,12 +92,13 @@ public boolean equals(Object o) {
Objects.equals(memberid, that.memberid) &&
Objects.equals(skillid, that.skillid) &&
Objects.equals(skilllevel, that.skilllevel) &&
Objects.equals(lastuseddate, that.lastuseddate);
Objects.equals(lastuseddate, that.lastuseddate) &&
Objects.equals(interested, that.interested);
}

@Override
public int hashCode() {
return Objects.hash(id, memberid, skillid, skilllevel, lastuseddate);
return Objects.hash(id, memberid, skillid, skilllevel, lastuseddate, interested);
}

@Override
Expand All @@ -100,6 +109,7 @@ public String toString() {
", skillid=" + skillid + '\'' +
", skilllevel=" + skilllevel + '\'' +
", lastuseddate=" + lastuseddate +
", interested=" + interested +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public MemberSkillController(MemberSkillServices memberSkillServices) {
@Post
public HttpResponse<MemberSkill> createAMemberSkill(@Body @Valid @NotNull MemberSkillCreateDTO memberSkill, HttpRequest<?> request) {
MemberSkill createdMemberSkill = memberSkillsService.save(
new MemberSkill(memberSkill.getMemberid(), memberSkill.getSkillid(), memberSkill.getSkilllevel(), memberSkill.getLastuseddate())
new MemberSkill(memberSkill.getMemberid(),
memberSkill.getSkillid(),
memberSkill.getSkilllevel(),
memberSkill.getLastuseddate(),
memberSkill.isInterested())
);
return HttpResponse.created(createdMemberSkill)
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), createdMemberSkill.getId()))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class MemberSkillCreateDTO {
private String skilllevel;

@Schema(description = "the last used date of the skill")

private LocalDate lastuseddate;

@Schema(description = "the member interest")
private boolean interested;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import com.objectcomputing.checkins.exceptions.BadArgException;

public enum SkillLevel {
INTERESTED(1),
NOVICE(2),
INTERMEDIATE(3),
ADVANCED(4),
EXPERT(5);

public static final String INTERESTED_LEVEL = "1";
public static final String NOVICE_LEVEL = "2";
public static final String INTERMEDIATE_LEVEL = "3";
public static final String ADVANCED_LEVEL = "4";
public static final String EXPERT_LEVEL = "5";
NONE(0),
NOVICE(1),
PRACTITIONER(2),
EXPERT(3);

public static final String NONE_LEVEL = "0";
public static final String NOVICE_LEVEL = "1";
public static final String PRACTITIONER_LEVEL = "2";
public static final String EXPERT_LEVEL = "3";

private final int value;

Expand All @@ -26,16 +24,14 @@ public int getValue() {
}

public static SkillLevel convertFromString(String level) {
final String levelLc = level != null ? level.toLowerCase() : "3";
final String levelLc = level != null ? level.toLowerCase() : PRACTITIONER_LEVEL;
switch (levelLc) {
case INTERESTED_LEVEL:
return SkillLevel.INTERESTED;
case NONE_LEVEL:
return SkillLevel.NONE;
case NOVICE_LEVEL:
return SkillLevel.NOVICE;
case INTERMEDIATE_LEVEL:
return SkillLevel.INTERMEDIATE;
case ADVANCED_LEVEL:
return SkillLevel.ADVANCED;
case PRACTITIONER_LEVEL:
return SkillLevel.PRACTITIONER;
case EXPERT_LEVEL:
return SkillLevel.EXPERT;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE member_skills ADD COLUMN interested boolean;

-- If the original skilllevel was 'interested', set the new column value to true
UPDATE member_skills SET interested = true WHERE skilllevel = '1';

-- Transition old skill levels to the new range
UPDATE member_skills SET skilllevel = '0' WHERE skilllevel = '1';
UPDATE member_skills SET skilllevel = '1' WHERE skilllevel = '2';
UPDATE member_skills SET skilllevel = '2' WHERE skilllevel = '3' OR
skilllevel = '4';
UPDATE member_skills SET skilllevel = '3' WHERE skilllevel = '5';
5 changes: 5 additions & 0 deletions server/src/main/resources/db/dev/R__Load_testing_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,11 @@ INSERT INTO member_skills -- Revolver Ocelot, Java
VALUES
('d27b679c-3aa8-4c4d-b08e-4eda63cea23f', '105f2968-a182-45a3-892c-eeff76383fe0', '06c03df3-85fe-4fc3-979e-9f1f6ba74a03', '5', '2022-08-01');

INSERT INTO member_skills -- Faux Freddy, CSS
(id, memberid, skillid, skilllevel, lastuseddate)
VALUES
('fabd11fa-2268-4e72-a2ad-e13aaaaaaa5b', '2dee821c-de32-4d9c-9ecb-f73e5903d17a', '6b56f0aa-09aa-4b09-bb81-03481af7e49f', '1', '2018-06-01');

INSERT INTO kudos
(id, message, senderid, teamid, datecreated, dateapproved, publiclyvisible)
VALUES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
public interface MemberSkillFixture extends RepositoryFixture{

default MemberSkill createMemberSkill(MemberProfile memberProfile, Skill skill, String skillLevel, LocalDate lastUsedDate) {
return getMemberSkillRepository().save(new MemberSkill(memberProfile.getId(), skill.getId(), skillLevel, lastUsedDate));
return getMemberSkillRepository().save(new MemberSkill(memberProfile.getId(), skill.getId(), skillLevel, lastUsedDate, true));
}

default MemberSkill createMemberSkill(MemberProfile memberProfile, Skill skill, String skillLevel, LocalDate lastUsedDate, boolean interested) {
return getMemberSkillRepository().save(new MemberSkill(memberProfile.getId(), skill.getId(), skillLevel, lastUsedDate, interested));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MemberSkillServiceImplTest extends TestContainersSuite
void testRead() {
Skill skill = createSkill("Skill1", false, "First", false);
MemberProfile member = createADefaultMemberProfile();
MemberSkill memberSkill = createMemberSkill(member, skill, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill memberSkill = createMemberSkill(member, skill, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
assertEquals(memberSkill, memberSkillsServices.read(memberSkill.getId()));
}

Expand Down Expand Up @@ -86,8 +86,8 @@ void testSaveNullMemberSkill() {
void testSaveMemberSkillAlreadyExistingSkill() {
Skill skill = createSkill("Skill1", false, "First", false);
MemberProfile member = createADefaultMemberProfile();
MemberSkill savedSkill = createMemberSkill(member, skill, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill memberSkill = new MemberSkill(member.getId(), skill.getId(), SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill savedSkill = createMemberSkill(member, skill, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill memberSkill = new MemberSkill(member.getId(), skill.getId(), SkillLevel.PRACTITIONER_LEVEL, LocalDate.now(), true);
AlreadyExistsException exception = assertThrows(AlreadyExistsException.class, () -> memberSkillsServices.save(memberSkill));
assertEquals(String.format("Member %s already has this skill %s",
memberSkill.getMemberid(), memberSkill.getSkillid()), exception.getMessage());
Expand Down Expand Up @@ -117,8 +117,8 @@ void testFindByFieldsNullParams() {
Skill skill2 = createSkill("Skill2", false, "Second", false);
Skill skill3 = createSkill("Skill3", false, "Third", false);
MemberProfile member1 = createADefaultMemberProfile();
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member1, skill2, SkillLevel.ADVANCED_LEVEL, LocalDate.now());
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member1, skill2, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms3 = createMemberSkill(member1, skill3, SkillLevel.NOVICE_LEVEL, LocalDate.now());

Set<MemberSkill> memberSkillSet = Set.of(ms1, ms2, ms3);
Expand All @@ -132,8 +132,8 @@ void testFindByFieldsMemberId() {
Skill skill3 = createSkill("Skill3", false, "Third", false);
MemberProfile member1 = createADefaultMemberProfile();
MemberProfile member2 = createASecondDefaultMemberProfile();
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.ADVANCED_LEVEL, LocalDate.now());
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms3 = createMemberSkill(member1, skill3, SkillLevel.NOVICE_LEVEL, LocalDate.now());

List<MemberSkill> memberSkillSet = List.of(ms1, ms2, ms3);
Expand All @@ -150,8 +150,8 @@ void testFindByFieldsSkillId() {
Skill skill3 = createSkill("Skill3", false, "Third", false);
MemberProfile member1 = createADefaultMemberProfile();
MemberProfile member2 = createASecondDefaultMemberProfile();
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.ADVANCED_LEVEL, LocalDate.now());
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms3 = createMemberSkill(member1, skill3, SkillLevel.NOVICE_LEVEL, LocalDate.now());

List<MemberSkill> memberSkillSet = List.of(ms1, ms2, ms3);
Expand All @@ -169,8 +169,8 @@ void testFindByFieldsAll() {
Skill skill3 = createSkill("Skill3", false, "Third", false);
MemberProfile member1 = createADefaultMemberProfile();
MemberProfile member2 = createASecondDefaultMemberProfile();
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.ADVANCED_LEVEL, LocalDate.now());
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms3 = createMemberSkill(member1, skill3, SkillLevel.NOVICE_LEVEL, LocalDate.now());

List<MemberSkill> memberSkillSet = List.of(ms1, ms2, ms3);
Expand All @@ -190,8 +190,8 @@ void testReadAll() {
Skill skill3 = createSkill("Skill3", false, "Third", false);
MemberProfile member1 = createADefaultMemberProfile();
MemberProfile member2 = createASecondDefaultMemberProfile();
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.INTERMEDIATE_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.ADVANCED_LEVEL, LocalDate.now());
MemberSkill ms1 = createMemberSkill(member1, skill1, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms2 = createMemberSkill(member2, skill2, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());
MemberSkill ms3 = createMemberSkill(member1, skill3, SkillLevel.NOVICE_LEVEL, LocalDate.now());

Set<MemberSkill> memberSkillSet = Set.of(ms1, ms2, ms3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ void testValidRequestNonEmptyResponse() {

final MemberProfile memberProfile = createADefaultMemberProfile();
final Skill skill = createADefaultSkill();
final MemberSkill memberSkill = createMemberSkill(memberProfile, skill, SkillLevel.ADVANCED_LEVEL, LocalDate.now());
final MemberSkill memberSkill = createMemberSkill(memberProfile, skill, SkillLevel.PRACTITIONER_LEVEL, LocalDate.now());

final SkillsReportRequestDTO skillsReportRequestDTO = new SkillsReportRequestDTO();
final List<SkillLevelDTO> skillLevelDTOList = new ArrayList<>();
final SkillLevelDTO skillLevelDTO = new SkillLevelDTO();
skillLevelDTO.setId(skill.getId());
skillLevelDTO.setLevel(SkillLevel.INTERMEDIATE);
skillLevelDTO.setLevel(SkillLevel.PRACTITIONER);
skillLevelDTOList.add(skillLevelDTO);
skillsReportRequestDTO.setSkills(skillLevelDTOList);

Expand Down Expand Up @@ -84,7 +84,7 @@ void testValidRequestEmptyResponse() {

final MemberProfile memberProfile = createADefaultMemberProfile();
final Skill skill = createADefaultSkill();
createMemberSkill(memberProfile, skill, SkillLevel.INTERMEDIATE_LEVEL, null);
createMemberSkill(memberProfile, skill, SkillLevel.PRACTITIONER_LEVEL, null);

final SkillsReportRequestDTO skillsReportRequestDTO = new SkillsReportRequestDTO();
final List<SkillLevelDTO> skillLevelDTOList = new ArrayList<>();
Expand Down Expand Up @@ -116,7 +116,7 @@ void testInvalidRequestSkillNotExist() {
final SkillLevelDTO skillLevelDTO = new SkillLevelDTO();
final UUID skillId = UUID.randomUUID();
skillLevelDTO.setId(skillId);
skillLevelDTO.setLevel(SkillLevel.ADVANCED);
skillLevelDTO.setLevel(SkillLevel.PRACTITIONER);
skillLevelDTOList.add(skillLevelDTO);
skillsReportRequestDTO.setSkills(skillLevelDTOList);

Expand Down
Loading
Loading