Commit 63b90620 authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-609 | hide hidden dashboards

parent 6f9cd630
......@@ -2,6 +2,8 @@ package ee.stat.dashboard.repository.custom;
import ee.stat.dashboard.model.classifier.ClassifierCode;
import ee.stat.dashboard.model.classifier.Element;
import ee.stat.dashboard.model.dashboard.DashboardStatus;
import ee.stat.dashboard.model.dashboard.DashboardUserType;
import ee.stat.dashboard.model.widget.back.enums.Language;
import ee.stat.dashboard.service.element.dto.RoleStrategy;
......@@ -21,7 +23,7 @@ public interface ElementCustomRepository {
List<Element> findAllByClfCode(ClassifierCode code);
List<Element> findAllByClfCodeAndRoleOrderByName(ClassifierCode code, RoleStrategy role, Language language);
List<Element> findAllByClfCodeAndRoleOrderByName(ClassifierCode code, RoleStrategy role, Language language, DashboardStatus status, DashboardUserType userType);
List<Element> findAllByClfCodeAndElCode(ClassifierCode code, String elementCode);
......
......@@ -2,6 +2,8 @@ package ee.stat.dashboard.repository.custom;
import ee.stat.dashboard.model.classifier.ClassifierCode;
import ee.stat.dashboard.model.classifier.Element;
import ee.stat.dashboard.model.dashboard.DashboardStatus;
import ee.stat.dashboard.model.dashboard.DashboardUserType;
import ee.stat.dashboard.model.widget.back.enums.Language;
import ee.stat.dashboard.service.element.dto.RoleStrategy;
......@@ -48,16 +50,19 @@ public class ElementCustomRepositoryImpl implements ElementCustomRepository {
}
@Override
public List<Element> findAllByClfCodeAndRoleOrderByName(ClassifierCode code, RoleStrategy role, Language language) {
String roleExistsCondition = role.hasDashboard() ? "and rd.id is not null \n" : "and rd.id is null \n";
String order = language.isEt() ? "order by e.name_et asc \n" : "order by e.name_en asc \n";
public List<Element> findAllByClfCodeAndRoleOrderByName(ClassifierCode code, RoleStrategy role, Language language, DashboardStatus status, DashboardUserType userType) {
String roleExistsCondition = role.hasDashboard() ? " and rd.id is not null \n" : " and rd.id is null \n";
String order = language.isEt() ? " order by e.name_et asc \n" : " order by e.name_en asc \n";
String select = "SELECT DISTINCT e.*\n" +
"from Element e\n" +
" join Classifier c on c.id = e.classifier\n" +
" left join role_dashboard rd on e.id = rd.role_element\n" +
" left join dashboard d on d.id = rd.dashboard and d.status = :status and d.user_type = :userType \n" +
"where c.code = :code\n";
return entityManager.createNativeQuery(select + roleExistsCondition + order, Element.class)
.setParameter("code", code.name())
.setParameter("status", status.name())
.setParameter("userType", userType.name())
.getResultList();
}
......
......@@ -2,6 +2,8 @@ package ee.stat.dashboard.service.element;
import ee.stat.dashboard.model.classifier.ClassifierCode;
import ee.stat.dashboard.model.classifier.Element;
import ee.stat.dashboard.model.dashboard.DashboardStatus;
import ee.stat.dashboard.model.dashboard.DashboardUserType;
import ee.stat.dashboard.model.widget.back.enums.Language;
import ee.stat.dashboard.repository.ElementRepository;
import ee.stat.dashboard.service.element.dto.RoleStrategy;
......@@ -45,7 +47,7 @@ public class ElementServiceCache {
@Cacheable("ElementServiceCache_findAllByClfCodeAndRoleOrderByName")
public List<Element> findAllByClfCodeAndRoleOrderByName(ClassifierCode code, RoleStrategy role, Language language) {
return elementRepository.findAllByClfCodeAndRoleOrderByName(code, role, language);
return elementRepository.findAllByClfCodeAndRoleOrderByName(code, role, language, DashboardStatus.VISIBLE, DashboardUserType.ADMIN);
}
@Cacheable(value = "ElementServiceCache_findAllToByFrom")
......
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