com.arextest.diff.utils.ReferenceConvert Maven / Gradle / Ivy
package com.arextest.diff.utils;
import com.arextest.diff.model.key.ListSortEntity;
import com.arextest.diff.model.key.ReferenceEntity;
import com.arextest.diff.model.key.ResponseListKeyEntity;
import com.arextest.diff.model.key.ResponseNodeReferenceEntity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ReferenceConvert {
public static List getAllReferenceEntities(
List responseNodeReferenceEntities) {
if (responseNodeReferenceEntities == null) {
return new ArrayList<>();
}
Set referenceEntitiesSet = new HashSet<>();
for (ResponseNodeReferenceEntity responseNodeReferenceEntity : responseNodeReferenceEntities) {
String fkNodePath = responseNodeReferenceEntity.getFkNode();
String pkNodePath = responseNodeReferenceEntity.getPkNode();
ReferenceEntity entity = new ReferenceEntity();
entity.setFkNodePath(Arrays.asList(fkNodePath.split("\\\\")));
List pkNode = Arrays.asList(pkNodePath.split("\\\\"));
entity.setPkNodePath(pkNode);
// this may be cause problem
entity.setPkNodeListPath(pkNode.subList(0, pkNode.size() - 1));
referenceEntitiesSet.add(entity);
}
List referenceEntities = new ArrayList<>();
for (ReferenceEntity referenceEntity : referenceEntitiesSet) {
referenceEntities.add(referenceEntity);
}
return referenceEntities;
}
public static List getKeyConfig(List keyEntities,
List references) {
if (keyEntities == null) {
return new ArrayList<>();
}
Map pkNodePath2ListPathMap = new HashMap<>();
if (references != null) {
for (ReferenceEntity referenceEntity : references) {
pkNodePath2ListPathMap.put(ListUti.convertToString2(referenceEntity.getPkNodeListPath()),
referenceEntity);
}
}
List keys = new ArrayList<>();
for (ResponseListKeyEntity keyEntity : keyEntities) {
if (StringUtil.isEmpty(keyEntity.getKeyNodes())) {
continue;
}
ListSortEntity listSortEntity = new ListSortEntity();
List> keyNodePaths = new ArrayList<>();
for (String keyNodePath : keyEntity.getKeyNodes().split(",")) {
keyNodePaths.add(Arrays.asList(keyNodePath.split("\\\\")));
}
listSortEntity.setListNodepath(Arrays.asList(keyEntity.getListNodePath().split("\\\\")));
listSortEntity.setKeys(keyNodePaths);
ReferenceEntity entity = pkNodePath2ListPathMap.get(
ListUti.convertToString2(listSortEntity.getListNodepath()));
if (entity != null) {
List pkNodeRelativePath = entity.getPkNodePath()
.subList(entity.getPkNodeListPath().size(), entity.getPkNodePath().size());
listSortEntity.setReferenceNodeRelativePath(pkNodeRelativePath);
// listKeyEntity.setReferenceEntity(entity);
}
keys.add(listSortEntity);
}
return keys;
}
}