brigning down group tpes

This commit is contained in:
Filip Izydorczyk 2021-01-19 10:44:35 +01:00
parent 06fb41b5dd
commit 6a4ea45900
7 changed files with 99 additions and 15 deletions

View File

@ -5,13 +5,19 @@ package com.plannaplan.types;
*/
public enum GroupType {
LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"),CONSERVATORY("Konwersatorium"), PRATICE("Praktyka");
LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"), CONSERVATORY("Konwersatorium"),
PRATICE("Praktyka");
public final String type;
private GroupType(String type) {
this.type = type;
}
/**
* @param type as string
* @return Enum converted from provided string
*/
public final static GroupType getType(String type) {
for (GroupType d : values()) {
if (d.type.equals(type)) {
@ -20,4 +26,14 @@ public enum GroupType {
}
return null;
}
/**
* @param type group type to check
* @return general convertion to bring down tours to two generals LECTURE and
* CLASS. To class are included: CLASS, LAB, SEMINAR, CONSERVATORY,
* PRATICE.
*/
public final static GroupType isLectureOrClass(GroupType type) {
return type == GroupType.LECTURE ? GroupType.LECTURE : GroupType.CLASS;
}
}

View File

@ -0,0 +1,68 @@
package com.plannaplan.types;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class GroupTypeTest {
@Test
public void shouldBeLecture() {
assertTrue(GroupType.isLectureOrClass(GroupType.LECTURE) == GroupType.LECTURE);
}
@Test
public void shouldBeClass1() {
assertTrue(GroupType.isLectureOrClass(GroupType.CLASS) == GroupType.CLASS);
}
@Test
public void shouldBeClass2() {
assertTrue(GroupType.isLectureOrClass(GroupType.CONSERVATORY) == GroupType.CLASS);
}
@Test
public void shouldBeClass3() {
assertTrue(GroupType.isLectureOrClass(GroupType.LAB) == GroupType.CLASS);
}
@Test
public void shouldBeClass4() {
assertTrue(GroupType.isLectureOrClass(GroupType.PRATICE) == GroupType.CLASS);
}
@Test
public void shouldBeClass5() {
assertTrue(GroupType.isLectureOrClass(GroupType.SEMINAR) == GroupType.CLASS);
}
@Test
public void shouldCastFromString1() {
assertTrue(GroupType.getType("Ćwiczenia") == GroupType.CLASS);
}
@Test
public void shouldCastFromString2() {
assertTrue(GroupType.getType("Wykład") == GroupType.LECTURE);
}
@Test
public void shouldCastFromString3() {
assertTrue(GroupType.getType("Laboratorium") == GroupType.LAB);
}
@Test
public void shouldCastFromString4() {
assertTrue(GroupType.getType("Seminarium") == GroupType.SEMINAR);
}
@Test
public void shouldCastFromString5() {
assertTrue(GroupType.getType("Konwersatorium") == GroupType.CONSERVATORY);
}
@Test
public void shouldCastFromString6() {
assertTrue(GroupType.getType("Praktyka") == GroupType.PRATICE);
}
}

View File

@ -68,7 +68,7 @@ public class CoursesController {
final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups());
course.getGroups().stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
classes.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
} else {
lectures.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));

View File

@ -57,10 +57,10 @@ public class AssignmentResponseMappers {
}
}
if (courseGroups.size() == 2) {
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
.get();
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
.get();
final Groups lecture = courseGroups.stream()
.filter(o -> GroupType.isLectureOrClass(o.getType()) == GroupType.LECTURE).findFirst().get();
final Groups classes = courseGroups.stream()
.filter(o -> GroupType.isLectureOrClass(o.getType()) == GroupType.CLASS).findFirst().get();
if (ammounts != null) {
response.add(new AssignmentResponse(course, lecture, classes, ammounts));

View File

@ -83,7 +83,7 @@ public class GroupsMappers {
List<GroupDefaultResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
if (taken != null) {
classes.add(new GroupDefaultResponse(group, taken.get(group.getId())));
} else {
@ -122,7 +122,7 @@ public class GroupsMappers {
List<GroupWithCapacityResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
if (taken != null) {
classes.add(new GroupWithCapacityResponse(group, taken.get(group.getId())));
} else {

View File

@ -50,8 +50,8 @@ public class AssignmentResponse {
* @param group class/lecture entity
*/
public AssignmentResponse(Course course, Groups group) {
this(course, group.getType() == GroupType.LECTURE ? group : null,
group.getType() == GroupType.CLASS ? group : null);
this(course, GroupType.isLectureOrClass(group.getType()) == GroupType.LECTURE ? group : null,
GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null);
}
/**
@ -61,8 +61,8 @@ public class AssignmentResponse {
* places
*/
public AssignmentResponse(Course course, Groups group, HashMap<Long, Integer> ammounts) {
this(course, group.getType() == GroupType.LECTURE ? group : null,
group.getType() == GroupType.CLASS ? group : null, ammounts);
this(course, GroupType.isLectureOrClass(group.getType()) == GroupType.LECTURE ? group : null,
GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null, ammounts);
}
/**

View File

@ -30,7 +30,7 @@ public class CoursesWithGroupsResponse extends CoursesResponse {
public CoursesWithGroupsResponse(Course course) {
super(course);
course.getGroups().stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) {
this.classes.add(new GroupWithCapacityResponse(group));
} else {
this.lectures.add(new GroupWithCapacityResponse(group));