SUPPORT-9634: ip sort
This commit is contained in:
parent
2fe8777911
commit
055d34471e
9 changed files with 231 additions and 38 deletions
|
|
@ -0,0 +1,40 @@
|
|||
package ru.micord.ervu.account_applications.component.service;
|
||||
|
||||
|
||||
import component.complex.FilterableByPKGridService;
|
||||
import model.Filter;
|
||||
import model.grid.GridRows;
|
||||
import model.grid.SortInfo;
|
||||
import ru.micord.ervu.account_applications.component.util.GridUtils;
|
||||
|
||||
import ru.cg.webbpm.modules.database.api.dao.option.SortOrder;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public class IpFilterableGridService extends FilterableByPKGridService {
|
||||
private static final String IP_FIELD = "ip_directory$ip_address";
|
||||
|
||||
@Override
|
||||
public GridRows loadData(Integer offset, Integer limit, Filter[] filters, SortInfo[] sortInfos) {
|
||||
GridRows gridRows = super.loadData(offset, limit, filters, null);
|
||||
SortOrder sortOrder = (sortInfos != null && sortInfos.length > 0)
|
||||
? sortInfos[0].getSortOrder()
|
||||
: SortOrder.ASC;
|
||||
|
||||
GridUtils.sortByIp(gridRows, sortOrder, IP_FIELD);
|
||||
return gridRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridRows loadDataWithRowCount(Integer offset, Integer limit, Filter[] filters,
|
||||
SortInfo[] sortInfos) {
|
||||
GridRows gridRows = super.loadDataWithRowCount(offset, limit, filters, null);
|
||||
SortOrder sortOrder = (sortInfos != null && sortInfos.length > 0)
|
||||
? sortInfos[0].getSortOrder()
|
||||
: SortOrder.ASC;
|
||||
|
||||
GridUtils.sortByIp(gridRows, sortOrder, IP_FIELD);
|
||||
return gridRows;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package ru.micord.ervu.account_applications.component.service;
|
||||
|
||||
|
||||
import model.Filter;
|
||||
import model.grid.GridRows;
|
||||
import model.grid.SortInfo;
|
||||
import ru.micord.ervu.account_applications.component.util.GridUtils;
|
||||
import service.GridV2ServiceImpl;
|
||||
|
||||
import ru.cg.webbpm.modules.database.api.dao.option.SortOrder;
|
||||
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public class IpGridV2Service extends GridV2ServiceImpl {
|
||||
private static final String IP_FIELD = "link_user_application_ip_address$ip_address";
|
||||
|
||||
@Override
|
||||
public GridRows loadData(Integer offset, Integer limit, Filter[] filters, SortInfo[] sortInfos) {
|
||||
GridRows gridRows = super.loadData(offset, limit, filters, null);
|
||||
SortOrder sortOrder = (sortInfos != null && sortInfos.length > 0)
|
||||
? sortInfos[0].getSortOrder()
|
||||
: SortOrder.ASC;
|
||||
|
||||
GridUtils.sortByIp(gridRows, sortOrder, IP_FIELD);
|
||||
return gridRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridRows loadDataWithRowCount(Integer offset, Integer limit, Filter[] filters,
|
||||
SortInfo[] sortInfos) {
|
||||
GridRows gridRows = super.loadDataWithRowCount(offset, limit, filters, null);
|
||||
SortOrder sortOrder = (sortInfos != null && sortInfos.length > 0)
|
||||
? sortInfos[0].getSortOrder()
|
||||
: SortOrder.ASC;
|
||||
|
||||
GridUtils.sortByIp(gridRows, sortOrder, IP_FIELD);
|
||||
return gridRows;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package ru.micord.ervu.account_applications.component.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import model.grid.GridRow;
|
||||
import model.grid.GridRows;
|
||||
import ru.micord.ervu.account_applications.util.IpAddressUtils;
|
||||
|
||||
import ru.cg.webbpm.modules.database.api.dao.option.SortOrder;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public final class GridUtils {
|
||||
|
||||
private GridUtils() {}
|
||||
|
||||
public static void sortByIp(GridRows gridRows, SortOrder sortOrder, String columnName) {
|
||||
if (gridRows == null || gridRows.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GridRow[] rows = gridRows.getRows();
|
||||
|
||||
Arrays.sort(rows, (row1, row2) -> {
|
||||
String ip1 = (String) row1.get(columnName);
|
||||
String ip2 = (String) row2.get(columnName);
|
||||
|
||||
int comparison = IpAddressUtils.compareIpAddresses(ip1, ip2);
|
||||
|
||||
return sortOrder == SortOrder.DESC ? -comparison : comparison;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package ru.micord.ervu.account_applications.service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
|
@ -30,6 +30,7 @@ import ru.micord.ervu.account_applications.component.model.dto.SearchRequest;
|
|||
import ru.micord.ervu.account_applications.component.model.dto.SearchResponse;
|
||||
import ru.micord.ervu.account_applications.security.context.SecurityContext;
|
||||
import ru.micord.ervu.account_applications.service.constant.PathConstant;
|
||||
import ru.micord.ervu.account_applications.util.IpAddressUtils;
|
||||
|
||||
import ru.cg.webbpm.modules.standard_annotations.editor.ObjectRef;
|
||||
|
||||
|
|
@ -196,13 +197,19 @@ public class AccountFetchService implements EntityFetchService<Account> {
|
|||
}
|
||||
|
||||
private GridRows convertIpAddressesToGridRows(List<?> ipList) {
|
||||
List<?> sortedList = new ArrayList<>(ipList);
|
||||
sortedList.sort((ip1, ip2) -> {
|
||||
String ip1Str = ip1 != null ? ip1.toString() : "";
|
||||
String ip2Str = ip2 != null ? ip2.toString() : "";
|
||||
return IpAddressUtils.compareIpAddresses(ip1Str, ip2Str);
|
||||
});
|
||||
|
||||
List<GridRow> rows = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (Object ip : ipList) {
|
||||
for (Object ip : sortedList) {
|
||||
GridRow row = new GridRow();
|
||||
row.put("row_uid", ip);
|
||||
row.put(
|
||||
editableGridColumnRef != null ? editableGridColumnRef.getObjectId() : FIELD_IP_ADDRESSES,
|
||||
FIELD_IP_ADDRESSES,
|
||||
ip
|
||||
);
|
||||
rows.add(row);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package ru.micord.ervu.account_applications.util;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public final class IpAddressUtils {
|
||||
|
||||
private IpAddressUtils() {}
|
||||
|
||||
public static int compareIpAddresses(String ip1, String ip2) {
|
||||
long ip1Long = ipToLong(ip1);
|
||||
long ip2Long = ipToLong(ip2);
|
||||
return Long.compare(ip1Long, ip2Long);
|
||||
}
|
||||
|
||||
private static long ipToLong(String ip) {
|
||||
if (ip == null || ip.isEmpty() || !ip.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
String[] parts = ip.split("\\.");
|
||||
long result = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result = result * 256 + Integer.parseInt(parts[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue