提交 5d68fb6f 编写于 作者: sq3536's avatar sq3536

model

上级 219aade2
......@@ -95,4 +95,22 @@ public class EntityObj extends DataObj<String,Object> {
}
@JsonIgnore
@JSONField(serialize = false)
private ModelObj modelObj;
@JsonIgnore
@JSONField(serialize = false)
public ModelObj getModelObj() {
return modelObj;
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setModelObj(ModelObj modelObj) {
this.modelObj = modelObj;
return this;
}
}
......@@ -30,25 +30,102 @@ public class ModelObj extends DataObj<String,Object> {
this.dataModel = dataModel;
}
@JsonIgnore
@JSONField(serialize = false)
private ModelObj parent;
@JsonIgnore
@JSONField(serialize = false)
public ModelObj getParent() {
return parent;
}
@JsonIgnore
@JSONField(serialize = false)
public void setParent(ModelObj parent) {
this.parent = parent;
}
public EntityObj getEntity(String name)
{
Property property=this.getDataModel().getObjectProperty(name);
Object obj=this.get(name);
if(obj!=null&&obj instanceof EntityObj)
return (EntityObj) obj;
else if(property==null)
Property property=this.getDataModel().getObjectProperty(name);
if(property!=null) {
return new EntityObj().setDataModel(this.getDataModel()).setProperty(property).setRowKey(this.getRowKey());
else
}
property=this.getDataModel().findObjectProperty(name,"UP");
if(property!=null){
int layerDiff=this.getDataModel().getLayerNo()-property.getLayerNo();
ModelObj parentObj=this;
for(int i=0;i<layerDiff;i++)
parentObj=parentObj.getParent();
return parentObj.getEntity(name);
}
return new EntityObj().setDataModel(this.getDataModel()).setDstSystemId(this.getDataModel().getFactPorperty().getSystem()).setMetaEntityName(name).setRowKey(this.getRowKey());
}
public List<ModelObj> getNested(String name)
public NestedArray getNested(String name)
{
Object list=this.get(name);
if(list!=null&&list instanceof List)
return (List<ModelObj>)list;
else
return new ArrayList<>();
if(list!=null&&list instanceof NestedArray)
return (NestedArray)list;
DataModel model=this.getDataModel().getNestedDataModel(name);
if(model!=null)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
model=this.getDataModel().findDataModel(name,"DOWN");
if(model!=null)
{
List<String> steps=new ArrayList<>();
DataModel tmpModel=model;
while (tmpModel.getParentDataModel()!=null&&!tmpModel.getParentDataModel().getDataModelName().equalsIgnoreCase(this.getDataModel().getDataModelName()))
{
tmpModel=model.getParentDataModel();
steps.add(0,tmpModel.getDataModelName());
}
if(steps.size()>1)
{
NestedArray subarry=this.getNested(steps.get(0));
if(subarry.size()>0)
{
for(int i=1;i<steps.size();i++)
{
subarry=subarry.getSubNested(steps.get(i));
if(subarry.size()==0)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
}
return subarry;
}
}
}
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
}
@Override
public Object get(Object key) {
if(key==null)
return null;
if(key.toString().indexOf(".")>0)
{
String[] epair=key.toString().split("[.]");
if(epair.length>=2)
{
String name=epair[0];
String column=epair[1];
return this.getEntity(name).get(column);
}
}
return super.get(key);
}
......
package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
public class NestedArray extends ArrayList<ModelObj> {
@JsonIgnore
@JSONField(serialize = false)
private DataModel dataModel;
@JsonIgnore
@JSONField(serialize = false)
public DataModel getDataModel() {
return dataModel;
}
@JsonIgnore
@JSONField(serialize = false)
public NestedArray setDataModel(DataModel dataModel) {
this.dataModel = dataModel;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private ModelObj parent;
@JsonIgnore
@JSONField(serialize = false)
public ModelObj getParent() {
return parent;
}
@JsonIgnore
@JSONField(serialize = false)
public NestedArray setParent(ModelObj parent) {
this.parent = parent;
return this;
}
public NestedArray getSubNested(String name)
{
NestedArray rt=new NestedArray();
for(ModelObj modelObj:this)
{
Object list=modelObj.get(name);
if(list!=null&&list instanceof NestedArray)
rt.addAll((NestedArray)list);
}
return rt;
}
}
......@@ -121,32 +121,36 @@ public class DataModel {
return null;
}
public Property findObjectProperty(String name)
public Property findObjectProperty(String name,String direction)
{
if(StringUtils.isEmpty(direction))
direction="ALL";
Property rt=this.getObjectProperty(name);
if(rt!=null)
return rt;
if(this.getNestedDataModels()!=null)
{
for(DataModel dm:this.getNestedDataModels())
{
rt=dm.findObjectProperty(name);
if(rt!=null)
if(direction.equalsIgnoreCase("ALL")||direction.equalsIgnoreCase("DOWN")) {
if (this.getNestedDataModels() != null) {
for (DataModel dm : this.getNestedDataModels()) {
rt = dm.findObjectProperty(name, "DOWN");
if (rt != null)
return rt;
}
}
DataModel parent=this.getParentDataModel();
while (parent!=null)
{
rt=parent.getObjectProperty(name);
if(rt!=null)
}
if(direction.equalsIgnoreCase("ALL")||direction.equalsIgnoreCase("UP")) {
DataModel parent = this.getParentDataModel();
while (parent != null) {
rt = parent.getObjectProperty(name);
if (rt != null)
return rt;
else
parent=parent.getParentDataModel();
parent = parent.getParentDataModel();
}
}
return null;
}
public DataModel getNestedDataModel(String name)
{
if(this.getNestedDataModels()!=null&&(!StringUtils.isEmpty(name)))
......@@ -161,36 +165,43 @@ public class DataModel {
return null;
}
public DataModel findDataModel(String name)
public DataModel findDataModel(String name,String direction)
{
if(StringUtils.isEmpty(direction))
direction="ALL";
if(name.equalsIgnoreCase(this.getDataModelName()))
return this;
DataModel rt=this.getNestedDataModel(name);
DataModel rt= null;
if(direction.equalsIgnoreCase("ALL")||direction.equalsIgnoreCase("DOWN")) {
rt=this.getNestedDataModel(name);
if(rt!=null)
return rt;
if(this.getNestedDataModels()!=null)
{
for(DataModel dm:this.getNestedDataModels())
{
rt=dm.getNestedDataModel(name);
rt=dm.findDataModel(name,"DOWN");
if(rt!=null)
return rt;
}
}
}
if(this.getObjectProperty(name)!=null)
return this;
DataModel parent=this.getParentDataModel();
while (parent!=null)
{
if(name.equalsIgnoreCase(parent.getDataModelName()))
rt=parent;
if(rt==null&&parent.getObjectProperty(name)!=null)
rt=parent;
if(rt!=null)
if(direction.equalsIgnoreCase("ALL")||direction.equalsIgnoreCase("UP")) {
DataModel parent = this.getParentDataModel();
while (parent != null) {
if (name.equalsIgnoreCase(parent.getDataModelName()))
rt = parent;
if (rt == null && parent.getObjectProperty(name) != null)
rt = parent;
if (rt != null)
return rt;
else
parent=parent.getParentDataModel();
parent = parent.getParentDataModel();
}
}
return null;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册