Commit 8cd5c5f7 authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-608 | update roles endpoint

parent 592714a0
......@@ -8,6 +8,14 @@ public enum ClassifierCode {
GOV,
BUSINESS;
public boolean isEhak(){
return this == EHAK;
}
public boolean isNotEhak(){
return !isEhak();
}
public static List<ClassifierCode> getRoleClassifiers(){
return Arrays.asList(GOV, EHAK, BUSINESS);
};
......
......@@ -15,11 +15,16 @@ import java.util.stream.Collectors;
public class ClassifierService {
private ClassifierServiceCache classifierServiceCache;
private ElementService elementService;
public List<ClassifierResponse> getRoles(Language lang) {
return classifierServiceCache.findByCodeIn(ClassifierCode.getRoleClassifiers()).stream()
List<ClassifierResponse> classifiers = classifierServiceCache.findByCodeIn(ClassifierCode.getRoleClassifiers()).stream()
.map(c -> mapSimple(c, lang))
.collect(Collectors.toList());
classifiers.stream()
.filter(classifier -> classifier.getCode().isNotEhak())
.forEach(classifier -> classifier.setElements(elementService.findAll(classifier.getCode(), lang)));
return classifiers;
}
public ClassifierResponse mapSimple(Classifier clf, Language lang) {
......
......@@ -4,6 +4,8 @@ import ee.stat.dashboard.model.classifier.ClassifierCode;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Setter
@Getter
public class ClassifierResponse {
......@@ -11,4 +13,5 @@ public class ClassifierResponse {
private Long id;
private ClassifierCode code;
private String name;
private List<ElementResponse> elements;
}
......@@ -13,7 +13,9 @@ import java.util.List;
import static ee.stat.dashboard.AssertUtil.LIST_OF_CLASSIFIERS;
import static ee.stat.dashboard.AssertUtil.NR_OF_ROLE_CLASSIFIERS;
import static ee.stat.dashboard.AssertUtil.list_size;
import static ee.stat.dashboard.AssertUtil.nth;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class ClassifierControllerTest extends CommonRestTest {
......@@ -24,9 +26,19 @@ public class ClassifierControllerTest extends CommonRestTest {
public void findAll() {
List<ClassifierResponse> elements = getRoles();
list_size(elements, NR_OF_ROLE_CLASSIFIERS);
assertEquals(ClassifierCode.BUSINESS, elements.get(0).getCode());
assertEquals(ClassifierCode.EHAK, elements.get(1).getCode());
assertEquals(ClassifierCode.GOV, elements.get(2).getCode());
clfWElements(nth(elements, 0), ClassifierCode.BUSINESS, 9);
clfNoElements(nth(elements, 1));
clfWElements(nth(elements, 2), ClassifierCode.GOV, 12);
}
private void clfNoElements(ClassifierResponse ehak) {
assertEquals(ClassifierCode.EHAK, ehak.getCode());
assertNull(ehak.getElements());
}
private void clfWElements(ClassifierResponse clf, ClassifierCode code, int size) {
assertEquals(code, clf.getCode());
list_size(clf.getElements(), size);
}
private List<ClassifierResponse> getRoles() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment