SUPPORT-9033: only backend from SUPPORT-8639
This commit is contained in:
parent
be7e9b2ee0
commit
528f1f58e0
3 changed files with 47 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ public class TreeItemDto {
|
|||
public String label;
|
||||
public TreeItemDto[] children;
|
||||
public Object businessId;
|
||||
public String domainId;
|
||||
|
||||
public TreeItemDto(Object id, Object parentId, String label) {
|
||||
this.id = id;
|
||||
|
|
|
|||
|
|
@ -20,4 +20,9 @@ public class TreeItemRpcService extends Behavior {
|
|||
public List<TreeItemDto> loadTreeData() {
|
||||
return treeItemService.loadTreeData();
|
||||
}
|
||||
|
||||
@RpcCall
|
||||
public List<TreeItemDto> loadTreeDataByDomainId(String token, String[] roles) {
|
||||
return treeItemService.loadTreeDataByDomainId(token, roles);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package component.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -11,6 +12,9 @@ import java.util.Set;
|
|||
import component.model.TreeItemDto;
|
||||
import component.rpc.TreeItemRpcService;
|
||||
import database.dao.DefaultLoadDao;
|
||||
import ervu_business_metrics.security.model.jwt.UserSession;
|
||||
import ervu_business_metrics.security.service.ErvuJwtTokenService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import ru.cg.webbpm.modules.database.api.bean.TableRow;
|
||||
|
|
@ -28,6 +32,9 @@ import ru.cg.webbpm.modules.standard_annotations.validation.NotNull;
|
|||
*/
|
||||
@Service
|
||||
public class TreeItemService {
|
||||
@Autowired
|
||||
private ErvuJwtTokenService ervuJwtTokenService;
|
||||
|
||||
@NotNull
|
||||
public DefaultLoadDao loadDao;
|
||||
@GraphSource(value = TreeItemRpcService.class, scanMode = GraphSource.ScanMode.SELF)
|
||||
|
|
@ -42,6 +49,8 @@ public class TreeItemService {
|
|||
public EntityColumn labelColumn;
|
||||
@GraphSource(value = TreeItemRpcService.class, scanMode = GraphSource.ScanMode.SELF)
|
||||
public EntityColumn businessIdColumn;
|
||||
@GraphSource(value = TreeItemRpcService.class, scanMode = GraphSource.ScanMode.SELF)
|
||||
public EntityColumn domainIdColumn;
|
||||
@AdvancedProperty
|
||||
@GraphSource(value = TreeItemRpcService.class, scanMode = GraphSource.ScanMode.SELF)
|
||||
public EntityColumn sortColumn;
|
||||
|
|
@ -51,11 +60,40 @@ public class TreeItemService {
|
|||
|
||||
public List<TreeItemDto> loadTreeData() {
|
||||
List<TreeItemDto> loadedTreeItems = loadTreeItems();
|
||||
loadedTreeItems.forEach(item -> item.domainId = null);
|
||||
return loadedTreeItems.stream()
|
||||
.filter(item -> item.parentId == null)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<TreeItemDto> loadTreeDataByDomainId(String token, String[] roles) {
|
||||
UserSession session = ervuJwtTokenService.getUserSession(token);
|
||||
boolean hasMainRole = session.roles()
|
||||
.stream()
|
||||
.anyMatch(
|
||||
ervuRoleAuthority -> Arrays.asList(roles).contains(ervuRoleAuthority.getAuthority()));
|
||||
|
||||
String domainId = session.recruitmentId();
|
||||
if (hasMainRole || domainId == null || domainIdColumn == null) {
|
||||
return loadTreeData();
|
||||
}
|
||||
List<TreeItemDto> filteredTreeItems = loadTreeItems().stream()
|
||||
.filter(item -> item.domainId.equalsIgnoreCase(domainId))
|
||||
.toList();
|
||||
filteredTreeItems.forEach(this::setDomainIdToNull);
|
||||
return filteredTreeItems;
|
||||
}
|
||||
|
||||
private void setDomainIdToNull(TreeItemDto treeItem) {
|
||||
treeItem.domainId = null;
|
||||
TreeItemDto[] treeItemChildren = treeItem.children;
|
||||
if (treeItemChildren != null && treeItemChildren.length > 0) {
|
||||
for (TreeItemDto child : treeItemChildren) {
|
||||
setDomainIdToNull(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<TreeItemDto> loadTreeItems() {
|
||||
LoadOptions loadOptions = new LoadOptions();
|
||||
if (sortColumn != null && sortOrder != null) {
|
||||
|
|
@ -107,6 +145,9 @@ public class TreeItemService {
|
|||
if (businessIdColumn != null) {
|
||||
treeItemDto.businessId = tableRow.get(businessIdColumn);
|
||||
}
|
||||
if (domainIdColumn != null) {
|
||||
treeItemDto.domainId = String.valueOf(tableRow.get(domainIdColumn));
|
||||
}
|
||||
return treeItemDto;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue